xaizek / zograscope (License: AGPLv3 only) (since 2018-12-07)
Mainly a syntax-aware diff that also provides a number of additional tools.
Commit 13bfb75a5bcedcacdd5582664f84074ca64d87c9

Add a couple more tests of the Matcher
Author: xaizek
Author date (UTC): 2019-07-01 16:17
Committer name: xaizek
Committer date (UTC): 2019-07-01 16:17
Parent(s): b3515bf0e31da5a28fcdf56313e0b1ff19ae88d3
Signing key: 99DC5E4DB05F6BE2
Tree: 6892faa215d5e60747f1a14447efbd3ba6d6b485
File Lines added Lines deleted
tests/tooling/Matcher.cpp 54 0
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);
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/zograscope

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/zograscope

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master