Update runtime code naming
Also, add macros so that code generator doesn't need to know about any runtime variables names or types
This commit is contained in:
parent
1b56832cb7
commit
6ed6aa05cc
11 changed files with 579 additions and 575 deletions
|
|
@ -6,51 +6,51 @@ enum { cat, dog, pig };
|
|||
static const char *names[] = { "cat", "dog", "pig" };
|
||||
|
||||
describe("trees", []() {
|
||||
TSTree *tree1, *parent1;
|
||||
ts_tree *tree1, *parent1;
|
||||
|
||||
before_each([&]() {
|
||||
tree1 = TSTreeMake(cat, 0, NULL);
|
||||
parent1 = TSTreeMake(dog, 1, &tree1);
|
||||
tree1 = ts_tree_make(cat, 0, NULL);
|
||||
parent1 = ts_tree_make(dog, 1, &tree1);
|
||||
});
|
||||
|
||||
after_each([&]() {
|
||||
TSTreeRelease(tree1);
|
||||
TSTreeRelease(parent1);
|
||||
ts_tree_release(tree1);
|
||||
ts_tree_release(parent1);
|
||||
});
|
||||
|
||||
describe("equality", [&]() {
|
||||
it("returns true for identical trees", [&]() {
|
||||
TSTree *tree2 = TSTreeMake(cat, 0, NULL);
|
||||
AssertThat(TSTreeEquals(tree1, tree2), Equals(1));
|
||||
ts_tree *tree2 = ts_tree_make(cat, 0, NULL);
|
||||
AssertThat(ts_tree_equals(tree1, tree2), Equals(1));
|
||||
|
||||
TSTree *parent2 = TSTreeMake(dog, 1, &tree2);
|
||||
AssertThat(TSTreeEquals(parent1, parent2), Equals(1));
|
||||
ts_tree *parent2 = ts_tree_make(dog, 1, &tree2);
|
||||
AssertThat(ts_tree_equals(parent1, parent2), Equals(1));
|
||||
|
||||
TSTreeRelease(tree2);
|
||||
TSTreeRelease(parent2);
|
||||
ts_tree_release(tree2);
|
||||
ts_tree_release(parent2);
|
||||
});
|
||||
|
||||
it("returns false for different trees", [&]() {
|
||||
TSTree *different_tree = TSTreeMake(pig, 0, NULL);
|
||||
AssertThat(TSTreeEquals(tree1, different_tree), Equals(0));
|
||||
ts_tree *different_tree = ts_tree_make(pig, 0, NULL);
|
||||
AssertThat(ts_tree_equals(tree1, different_tree), Equals(0));
|
||||
|
||||
TSTree *different_parent = TSTreeMake(dog, 1, &different_tree);
|
||||
AssertThat(TSTreeEquals(parent1, different_parent), Equals(0));
|
||||
ts_tree *different_parent = ts_tree_make(dog, 1, &different_tree);
|
||||
AssertThat(ts_tree_equals(parent1, different_parent), Equals(0));
|
||||
|
||||
TSTree *parent_with_same_type = TSTreeMake(cat, 1, &different_parent);
|
||||
AssertThat(TSTreeEquals(parent_with_same_type, tree1), Equals(0));
|
||||
AssertThat(TSTreeEquals(tree1, parent_with_same_type), Equals(0));
|
||||
ts_tree *parent_with_same_type = ts_tree_make(cat, 1, &different_parent);
|
||||
AssertThat(ts_tree_equals(parent_with_same_type, tree1), Equals(0));
|
||||
AssertThat(ts_tree_equals(tree1, parent_with_same_type), Equals(0));
|
||||
|
||||
TSTreeRelease(different_tree);
|
||||
TSTreeRelease(different_parent);
|
||||
TSTreeRelease(parent_with_same_type);
|
||||
ts_tree_release(different_tree);
|
||||
ts_tree_release(different_parent);
|
||||
ts_tree_release(parent_with_same_type);
|
||||
});
|
||||
});
|
||||
|
||||
describe("serialization", [&]() {
|
||||
it("returns a readable string", [&]() {
|
||||
AssertThat(string(TSTreeToString(tree1, names)), Equals("(cat)"));
|
||||
AssertThat(string(TSTreeToString(parent1, names)), Equals("(dog (cat))"));
|
||||
AssertThat(string(ts_tree_string(tree1, names)), Equals("(cat)"));
|
||||
AssertThat(string(ts_tree_string(parent1, names)), Equals("(dog (cat))"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue