File tests/tests.cpp changed (mode: 100644) (index 899fafd..77967d4) |
... |
... |
parseLua(const std::string &str) |
134 |
134 |
return parse("test-input.lua", str, true); |
return parse("test-input.lua", str, true); |
135 |
135 |
} |
} |
136 |
136 |
|
|
|
137 |
|
Tree |
|
138 |
|
parseBash(const std::string &str) |
|
139 |
|
{ |
|
140 |
|
return parse("test-input.sh", str, true); |
|
141 |
|
} |
|
142 |
|
|
137 |
143 |
// Parses source into a tree. |
// Parses source into a tree. |
138 |
144 |
static Tree |
static Tree |
139 |
145 |
parse(const std::string &fileName, const std::string &str, bool coarse) |
parse(const std::string &fileName, const std::string &str, bool coarse) |
File tests/tests.hpp changed (mode: 100644) (index 0853d55..2b1cdfb) |
... |
... |
Tree parseCxx(const std::string &str); |
142 |
142 |
// Parses Lua source into a tree. |
// Parses Lua source into a tree. |
143 |
143 |
Tree parseLua(const std::string &str); |
Tree parseLua(const std::string &str); |
144 |
144 |
|
|
|
145 |
|
// Parses Lua source into a tree. |
|
146 |
|
Tree parseBash(const std::string &str); |
|
147 |
|
|
145 |
148 |
// Finds the first node of specified type which has a matching value of its |
// Finds the first node of specified type which has a matching value of its |
146 |
149 |
// label (or any label if `label` is an empty string). |
// label (or any label if `label` is an empty string). |
147 |
150 |
const Node * findNode(const Tree &tree, Type type, |
const Node * findNode(const Tree &tree, Type type, |
File tests/tooling/Matcher.cpp changed (mode: 100644) (index 2b8e66d..47fc5d7) |
... |
... |
TEST_CASE("Declaration matcher works", "[tooling][matcher][.srcml]") |
220 |
220 |
CHECK(nMatches == 4); |
CHECK(nMatches == 4); |
221 |
221 |
} |
} |
222 |
222 |
} |
} |
|
223 |
|
|
|
224 |
|
TEST_CASE("Function matcher works", "[tooling][matcher][.srcml]") |
|
225 |
|
{ |
|
226 |
|
Matcher matcher(MType::Function, nullptr); |
|
227 |
|
|
|
228 |
|
int nMatches = 0; |
|
229 |
|
|
|
230 |
|
auto matchHandler = [&](Node */*node*/) { |
|
231 |
|
++nMatches; |
|
232 |
|
}; |
|
233 |
|
|
|
234 |
|
SECTION("In C") { |
|
235 |
|
Tree tree = parseC("void f() {} void g() {}", true); |
|
236 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
237 |
|
CHECK(nMatches == 2); |
|
238 |
|
} |
|
239 |
|
SECTION("In C++") { |
|
240 |
|
Tree tree = parseCxx("void f() {} void g() {}"); |
|
241 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
242 |
|
CHECK(nMatches == 2); |
|
243 |
|
} |
|
244 |
|
SECTION("In Lua") { |
|
245 |
|
Tree tree = parseLua("function f() end local " |
|
246 |
|
"function g() end " |
|
247 |
|
"a = function() end"); |
|
248 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
249 |
|
CHECK(nMatches == 3); |
|
250 |
|
} |
|
251 |
|
SECTION("In Bash") { |
|
252 |
|
Tree tree = parseBash("function f() {\n}\n" |
|
253 |
|
"g() {\n}"); |
|
254 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
255 |
|
CHECK(nMatches == 2); |
|
256 |
|
} |
|
257 |
|
} |