Separate spec helpers files for compiler and runtime specs
This commit is contained in:
parent
b167ee84fa
commit
142671c177
24 changed files with 99 additions and 71 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "compiler_spec_helper.h"
|
||||
#include "prepared_grammar.h"
|
||||
#include "build_tables/build_tables.h"
|
||||
#include <functional>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "compiler_spec_helper.h"
|
||||
#include "prepared_grammar.h"
|
||||
#include "build_tables/first_set.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "compiler_spec_helper.h"
|
||||
#include "prepared_grammar.h"
|
||||
#include "build_tables/follow_sets.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "compiler_spec_helper.h"
|
||||
#include "prepared_grammar.h"
|
||||
#include "build_tables/item_set_closure.h"
|
||||
#include "build_tables/item_set_transitions.h"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "compiler_spec_helper.h"
|
||||
#include "build_tables/rule_can_be_blank.h"
|
||||
|
||||
using namespace rules;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "compiler_spec_helper.h"
|
||||
#include "build_tables/rule_transitions.h"
|
||||
|
||||
using namespace rules;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,19 @@
|
|||
#include "spec_helper.h"
|
||||
#include "compiler_spec_helper.h"
|
||||
#include "../../examples/grammars/json.hpp"
|
||||
#include "../../examples/grammars/arithmetic.hpp"
|
||||
#include <fstream>
|
||||
|
||||
static string src_dir() {
|
||||
const char * dir = getenv("TREESITTER_DIR");
|
||||
if (!dir) dir = getenv("PWD");
|
||||
return dir;
|
||||
}
|
||||
|
||||
START_TEST
|
||||
|
||||
describe("compiling the example grammars", []() {
|
||||
string example_parser_dir = src_dir() + "/examples/parsers/";
|
||||
|
||||
|
||||
it("compiles the arithmetic grammar", [&]() {
|
||||
Grammar grammar = test_grammars::arithmetic();
|
||||
ofstream(example_parser_dir + "arithmetic.c") << compile(grammar, "arithmetic");
|
||||
|
|
@ -19,4 +25,4 @@ describe("compiling the example grammars", []() {
|
|||
});
|
||||
});
|
||||
|
||||
END_TEST
|
||||
END_TEST
|
||||
|
|
|
|||
18
spec/compiler/compiler_spec_helper.h
Normal file
18
spec/compiler/compiler_spec_helper.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef __tree_sitter_compiler_spec_helper_h__
|
||||
#define __tree_sitter_compiler_spec_helper_h__
|
||||
|
||||
#include "bandit/bandit.h"
|
||||
#include "helpers/stream_methods.h"
|
||||
#include "helpers/equals_pointer.h"
|
||||
#include "helpers/character_set_helpers.h"
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "rules/character_set.h"
|
||||
|
||||
using namespace tree_sitter;
|
||||
using namespace std;
|
||||
using namespace bandit;
|
||||
|
||||
#define START_TEST go_bandit([]() {
|
||||
#define END_TEST });
|
||||
|
||||
#endif
|
||||
12
spec/compiler/compiler_specs.cpp
Normal file
12
spec/compiler/compiler_specs.cpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include "compiler_spec_helper.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *args[] = {
|
||||
"",
|
||||
"--no-color",
|
||||
"--only="
|
||||
""
|
||||
};
|
||||
return bandit::run(4, const_cast<char **>(args));
|
||||
}
|
||||
|
|
@ -1,18 +1,15 @@
|
|||
#include "spec_helper.h"
|
||||
#include "rules/character_set.h"
|
||||
|
||||
string src_dir() {
|
||||
const char * dir = getenv("TREESITTER_DIR");
|
||||
if (!dir) dir = getenv("PWD");
|
||||
return dir;
|
||||
}
|
||||
#include "character_set_helpers.h"
|
||||
#include <memory>
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::make_shared;
|
||||
using std::set;
|
||||
|
||||
namespace rules {
|
||||
rule_ptr character(const set<CharacterRange> &ranges) {
|
||||
return make_shared<CharacterSet>(ranges);
|
||||
}
|
||||
|
||||
|
||||
rule_ptr character(const set<CharacterRange> &ranges, bool sign) {
|
||||
if (sign)
|
||||
return character(ranges);
|
||||
|
|
@ -20,4 +17,4 @@ namespace tree_sitter {
|
|||
return CharacterSet(ranges).complement().copy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
spec/compiler/helpers/character_set_helpers.h
Normal file
14
spec/compiler/helpers/character_set_helpers.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef __tree_sitter__character_set_helpers__
|
||||
#define __tree_sitter__character_set_helpers__
|
||||
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "rules/character_set.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
rule_ptr character(const std::set<CharacterRange> &ranges);
|
||||
rule_ptr character(const std::set<CharacterRange> &ranges, bool sign);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "compiler_spec_helper.h"
|
||||
#include "prepared_grammar.h"
|
||||
#include "prepare_grammar/prepare_grammar.h"
|
||||
#include "rules/symbol.h"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "compiler_spec_helper.h"
|
||||
#include "rules/character_set.h"
|
||||
|
||||
using namespace rules;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "compiler_spec_helper.h"
|
||||
#include "rules/pattern.h"
|
||||
#include "rules/character_set.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "compiler_spec_helper.h"
|
||||
#include "rules/rule.h"
|
||||
|
||||
using namespace rules;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "runtime_spec_helper.h"
|
||||
|
||||
extern ts_parse_config ts_parse_config_arithmetic;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "runtime_spec_helper.h"
|
||||
|
||||
extern ts_parse_config ts_parse_config_json;
|
||||
|
||||
|
|
|
|||
13
spec/runtime/runtime_spec_helper.h
Normal file
13
spec/runtime/runtime_spec_helper.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef __tree_sitter_runtime_spec_helper_h__
|
||||
#define __tree_sitter_runtime_spec_helper_h__
|
||||
|
||||
#include "bandit/bandit.h"
|
||||
#include "tree_sitter/runtime.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace bandit;
|
||||
|
||||
#define START_TEST go_bandit([]() {
|
||||
#define END_TEST });
|
||||
|
||||
#endif
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include "spec_helper.h"
|
||||
#include "runtime_spec_helper.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
|
@ -9,4 +9,4 @@ int main(int argc, char *argv[])
|
|||
""
|
||||
};
|
||||
return bandit::run(4, const_cast<char **>(args));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#include "spec_helper.h"
|
||||
#include "runtime_spec_helper.h"
|
||||
|
||||
static ts_tree ** tree_array(vector<ts_tree *> trees) {
|
||||
ts_tree ** result = (ts_tree **)calloc(trees.size(), sizeof(ts_tree *));
|
||||
for (int i = 0; i < trees.size(); i++)
|
||||
for (size_t i = 0; i < trees.size(); i++)
|
||||
result[i] = trees[i];
|
||||
return result;
|
||||
}
|
||||
|
|
@ -14,12 +14,12 @@ static const char *names[] = { "cat", "dog", "pig" };
|
|||
|
||||
describe("trees", []() {
|
||||
ts_tree *tree1, *parent1;
|
||||
|
||||
|
||||
before_each([&]() {
|
||||
tree1 = ts_tree_make_leaf(cat, 0, 0);
|
||||
parent1 = ts_tree_make_node(dog, 1, tree_array({ tree1 }), 0, 0);
|
||||
});
|
||||
|
||||
|
||||
after_each([&]() {
|
||||
ts_tree_release(tree1);
|
||||
ts_tree_release(parent1);
|
||||
|
|
@ -29,20 +29,20 @@ describe("trees", []() {
|
|||
it("returns true for identical trees", [&]() {
|
||||
ts_tree *tree2 = ts_tree_make_leaf(cat, 0, 0);
|
||||
AssertThat(ts_tree_equals(tree1, tree2), Equals(1));
|
||||
|
||||
|
||||
ts_tree *parent2 = ts_tree_make_node(dog, 1, tree_array({ tree2 }), 0, 0);
|
||||
AssertThat(ts_tree_equals(parent1, parent2), Equals(1));
|
||||
|
||||
|
||||
ts_tree_release(tree2);
|
||||
ts_tree_release(parent2);
|
||||
});
|
||||
|
||||
|
||||
it("returns false for trees with different symbols", [&]() {
|
||||
ts_tree *tree2 = ts_tree_make_leaf(pig, 0, 0);
|
||||
AssertThat(ts_tree_equals(tree1, tree2), Equals(0));
|
||||
ts_tree_release(tree2);
|
||||
});
|
||||
|
||||
|
||||
it("returns false for trees with different children", [&]() {
|
||||
ts_tree *tree2 = ts_tree_make_leaf(pig, 0, 0);
|
||||
ts_tree *parent2 = ts_tree_make_node(dog, 1, tree_array({ tree2 }), 0, 0);
|
||||
|
|
@ -52,7 +52,7 @@ describe("trees", []() {
|
|||
ts_tree_release(parent2);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("serialization", [&]() {
|
||||
it("returns a readable string", [&]() {
|
||||
AssertThat(string(ts_tree_string(tree1, names)), Equals("(cat)"));
|
||||
|
|
@ -61,4 +61,4 @@ describe("trees", []() {
|
|||
});
|
||||
});
|
||||
|
||||
END_TEST
|
||||
END_TEST
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
#ifndef __tree_sitter_spec_helper_h__
|
||||
#define __tree_sitter_spec_helper_h__
|
||||
|
||||
#include "bandit/bandit.h"
|
||||
#include "helpers/stream_methods.h"
|
||||
#include "helpers/equals_pointer.h"
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "tree_sitter/runtime.h"
|
||||
#include "rules/character_range.h"
|
||||
|
||||
using namespace tree_sitter;
|
||||
using namespace std;
|
||||
using namespace bandit;
|
||||
|
||||
#define START_TEST go_bandit([]() {
|
||||
#define END_TEST });
|
||||
|
||||
string src_dir();
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
rule_ptr character(const std::set<CharacterRange> &matches);
|
||||
rule_ptr character(const std::set<CharacterRange> &matches, bool);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -46,10 +46,9 @@
|
|||
'include_dirs': [
|
||||
'externals/bandit',
|
||||
'src/compiler',
|
||||
'spec',
|
||||
'spec/compiler',
|
||||
],
|
||||
'sources': [
|
||||
'<!@(ls spec/*.h spec/*.cpp)',
|
||||
'<!@(find spec/compiler -name "*.h" -or -name "*.cpp")',
|
||||
'<!@(find examples/grammars -name "*.hpp")',
|
||||
],
|
||||
|
|
@ -62,13 +61,9 @@
|
|||
'include_dirs': [
|
||||
'externals/bandit',
|
||||
'src/runtime',
|
||||
'spec',
|
||||
|
||||
# TODO - make separate spec helpers for runtime and compiler specs
|
||||
'src/compiler',
|
||||
'spec/runtime',
|
||||
],
|
||||
'sources': [
|
||||
'<!@(ls spec/*.h spec/*.cpp)',
|
||||
'<!@(find spec/runtime -name "*.h" -or -name "*.cpp")',
|
||||
'<!@(find examples/parsers -name "*.c")',
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue