Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright Contributors to the OpenVDB Project | ||
2 | // SPDX-License-Identifier: MPL-2.0 | ||
3 | |||
4 | #include <openvdb_ax/ast/AST.h> | ||
5 | #include <openvdb_ax/ast/Scanners.h> | ||
6 | #include <openvdb_ax/ast/PrintTree.h> | ||
7 | #include <openvdb_ax/Exceptions.h> | ||
8 | |||
9 | #include "../util.h" | ||
10 | |||
11 | #include <cppunit/extensions/HelperMacros.h> | ||
12 | |||
13 | #include <string> | ||
14 | |||
15 | using namespace openvdb::ax::ast; | ||
16 | using namespace openvdb::ax::ast::tokens; | ||
17 | |||
18 | namespace { | ||
19 | |||
20 | static const unittest_util::CodeTests tests = | ||
21 | { | ||
22 | { "a_;", Node::Ptr(new Local("a_")) }, | ||
23 | { "_a;", Node::Ptr(new Local("_a")) }, | ||
24 | { "_;", Node::Ptr(new Local("_")) }, | ||
25 | { "aa;", Node::Ptr(new Local("aa")) }, | ||
26 | { "A;", Node::Ptr(new Local("A")) }, | ||
27 | { "_A;", Node::Ptr(new Local("_A")) }, | ||
28 | { "a1;", Node::Ptr(new Local("a1")) }, | ||
29 | { "_1;", Node::Ptr(new Local("_1")) }, | ||
30 | { "abc;", Node::Ptr(new Local("abc")) }, | ||
31 | { "D1f;", Node::Ptr(new Local("D1f")) }, | ||
32 | { "var;", Node::Ptr(new Local("var")) } | ||
33 | }; | ||
34 | |||
35 | } | ||
36 | |||
37 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | class TestLocalNode : public CppUnit::TestCase |
38 | { | ||
39 | public: | ||
40 | |||
41 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
4 | CPPUNIT_TEST_SUITE(TestLocalNode); |
42 |
5/10✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
|
6 | CPPUNIT_TEST(testSyntax); |
43 |
5/10✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
|
6 | CPPUNIT_TEST(testASTNode); |
44 |
4/8✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
|
4 | CPPUNIT_TEST_SUITE_END(); |
45 | |||
46 |
20/40✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 11 times.
✓ Branch 8 taken 1 times.
✓ Branch 10 taken 11 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 11 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 11 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 11 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 11 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 11 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 11 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 11 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 11 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 11 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 11 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 11 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 11 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 11 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✓ Branch 51 taken 11 times.
✓ Branch 53 taken 11 times.
✗ Branch 54 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
|
36 | void testSyntax() { TEST_SYNTAX_PASSES(tests); } |
47 | void testASTNode(); | ||
48 | }; | ||
49 | |||
50 | CPPUNIT_TEST_SUITE_REGISTRATION(TestLocalNode); | ||
51 | |||
52 | 1 | void TestLocalNode::testASTNode() | |
53 | { | ||
54 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
|
12 | for (const auto& test : tests) { |
55 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | const std::string& code = test.first; |
56 | const Node* expected = test.second.get(); | ||
57 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | const Tree::ConstPtr tree = parse(code.c_str()); |
58 |
11/22✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 11 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 11 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 11 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 11 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 11 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 11 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 11 times.
✗ Branch 29 not taken.
✓ Branch 41 taken 11 times.
✗ Branch 42 not taken.
|
33 | CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast<bool>(tree)); |
59 | |||
60 | // get the first statement | ||
61 | const Node* result = tree->child(0)->child(0); | ||
62 |
6/12✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 11 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 11 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 11 times.
✗ Branch 17 not taken.
|
11 | CPPUNIT_ASSERT(result); |
63 |
12/24✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 11 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 11 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 11 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 11 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 11 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 11 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 11 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 11 times.
✗ Branch 32 not taken.
✓ Branch 45 taken 11 times.
✗ Branch 46 not taken.
|
33 | CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), |
64 | Node::LocalNode == result->nodetype()); | ||
65 | |||
66 | std::vector<const Node*> resultList, expectedList; | ||
67 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | linearize(*result, resultList); |
68 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | linearize(*expected, expectedList); |
69 | |||
70 |
2/4✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
|
11 | if (!unittest_util::compareLinearTrees(expectedList, resultList)) { |
71 | ✗ | std::ostringstream os; | |
72 | ✗ | os << "\nExpected:\n"; | |
73 | ✗ | openvdb::ax::ast::print(*expected, true, os); | |
74 | ✗ | os << "Result:\n"; | |
75 | ✗ | openvdb::ax::ast::print(*result, true, os); | |
76 | ✗ | CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Local code", code) + os.str()); | |
77 | } | ||
78 | } | ||
79 | 1 | } | |
80 | |||
81 | |||
82 |