File tests/tooling/Matcher.cpp changed (mode: 100644) (index 48efeef..01f02bb) |
23 |
23 |
|
|
24 |
24 |
#include "tests.hpp" |
#include "tests.hpp" |
25 |
25 |
|
|
|
26 |
|
TEST_CASE("Comment matcher works", "[tooling][matcher][.srcml]") |
|
27 |
|
{ |
|
28 |
|
Matcher matcher(MType::Comment, nullptr); |
|
29 |
|
|
|
30 |
|
int nMatches = 0; |
|
31 |
|
|
|
32 |
|
auto matchHandler = [&](Node */*node*/) { |
|
33 |
|
++nMatches; |
|
34 |
|
}; |
|
35 |
|
|
|
36 |
|
SECTION("In Make") { |
|
37 |
|
Tree tree = parseMake("# this is # a comment"); |
|
38 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
39 |
|
CHECK(nMatches == 1); |
|
40 |
|
} |
|
41 |
|
SECTION("In C") { |
|
42 |
|
Tree tree = parseC("/* a */ /* b // b */ // c", true); |
|
43 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
44 |
|
CHECK(nMatches == 3); |
|
45 |
|
} |
|
46 |
|
SECTION("In C++") { |
|
47 |
|
Tree tree = parseCxx("/* a */ /* b // b */ // c"); |
|
48 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
49 |
|
CHECK(nMatches == 3); |
|
50 |
|
} |
|
51 |
|
} |
|
52 |
|
|
|
53 |
|
TEST_CASE("Directive matcher works", "[tooling][matcher][.srcml]") |
|
54 |
|
{ |
|
55 |
|
Matcher matcher(MType::Directive, nullptr); |
|
56 |
|
|
|
57 |
|
int nMatches = 0; |
|
58 |
|
|
|
59 |
|
auto matchHandler = [&](Node */*node*/) { |
|
60 |
|
++nMatches; |
|
61 |
|
}; |
|
62 |
|
|
|
63 |
|
SECTION("In Make") { |
|
64 |
|
Tree tree = parseMake("-include config.mk"); |
|
65 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
66 |
|
CHECK(nMatches == 1); |
|
67 |
|
} |
|
68 |
|
SECTION("In C") { |
|
69 |
|
Tree tree = parseC("#include <stdio.h>\n#define a \\b", true); |
|
70 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
71 |
|
CHECK(nMatches == 2); |
|
72 |
|
} |
|
73 |
|
SECTION("In C++") { |
|
74 |
|
Tree tree = parseCxx("#include <iostream>\n#define a \\b"); |
|
75 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
76 |
|
CHECK(nMatches == 2); |
|
77 |
|
} |
|
78 |
|
} |
|
79 |
|
|
26 |
80 |
TEST_CASE("Statement matcher works", "[tooling][matcher][.srcml]") |
TEST_CASE("Statement matcher works", "[tooling][matcher][.srcml]") |
27 |
81 |
{ |
{ |
28 |
82 |
Matcher matcher(MType::Statement, nullptr); |
Matcher matcher(MType::Statement, nullptr); |