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
|
|
@ -1,46 +1,46 @@
|
|||
#include "spec_helper.h"
|
||||
|
||||
extern TSParseConfig ts_parse_config_arithmetic;
|
||||
extern ts_parse_config ts_parse_config_arithmetic;
|
||||
|
||||
START_TEST
|
||||
|
||||
describe("arithmetic", []() {
|
||||
TSDocument *document;
|
||||
ts_document *document;
|
||||
|
||||
before_each([&]() {
|
||||
document = TSDocumentMake();
|
||||
TSDocumentSetUp(document, ts_parse_config_arithmetic);
|
||||
document = ts_document_make();
|
||||
ts_document_set_parser(document, ts_parse_config_arithmetic);
|
||||
});
|
||||
|
||||
it("parses variables", [&]() {
|
||||
TSDocumentSetText(document, "x");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals(
|
||||
ts_document_set_text(document, "x");
|
||||
AssertThat(string(ts_document_string(document)), Equals(
|
||||
"(expression (term (factor (variable))))"));
|
||||
});
|
||||
|
||||
it("parses numbers", [&]() {
|
||||
TSDocumentSetText(document, "5");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals(
|
||||
ts_document_set_text(document, "5");
|
||||
AssertThat(string(ts_document_string(document)), Equals(
|
||||
"(expression (term (factor (number))))"));
|
||||
});
|
||||
|
||||
it("parses products of variables", [&]() {
|
||||
TSDocumentSetText(document, "x + y");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals(
|
||||
ts_document_set_text(document, "x + y");
|
||||
AssertThat(string(ts_document_string(document)), Equals(
|
||||
"(expression (term (factor (variable))) (plus) (term (factor (variable))))"));
|
||||
|
||||
TSDocumentSetText(document, "x * y");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals(
|
||||
ts_document_set_text(document, "x * y");
|
||||
AssertThat(string(ts_document_string(document)), Equals(
|
||||
"(expression (term (factor (variable)) (times) (factor (variable))))"));
|
||||
});
|
||||
|
||||
it("parses complex trees", [&]() {
|
||||
TSDocumentSetText(document, "x * y + z * a");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals(
|
||||
ts_document_set_text(document, "x * y + z * a");
|
||||
AssertThat(string(ts_document_string(document)), Equals(
|
||||
"(expression (term (factor (variable)) (times) (factor (variable))) (plus) (term (factor (variable)) (times) (factor (variable))))"));
|
||||
|
||||
TSDocumentSetText(document, "x * (y + z)");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals(
|
||||
ts_document_set_text(document, "x * (y + z)");
|
||||
AssertThat(string(ts_document_string(document)), Equals(
|
||||
"(expression (term (factor (variable)) (times) (factor (expression (term (factor (variable))) (plus) (term (factor (variable)))))))"));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,48 +1,48 @@
|
|||
#include "spec_helper.h"
|
||||
|
||||
extern TSParseConfig ts_parse_config_json;
|
||||
extern ts_parse_config ts_parse_config_json;
|
||||
|
||||
START_TEST
|
||||
|
||||
describe("json", []() {
|
||||
TSDocument *document;
|
||||
ts_document *document;
|
||||
|
||||
before_each([&]() {
|
||||
document = TSDocumentMake();
|
||||
TSDocumentSetUp(document, ts_parse_config_json);
|
||||
document = ts_document_make();
|
||||
ts_document_set_parser(document, ts_parse_config_json);
|
||||
});
|
||||
|
||||
it("parses strings", [&]() {
|
||||
TSDocumentSetText(document, "\"\"");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals("(value (string))"));
|
||||
ts_document_set_text(document, "\"\"");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (string))"));
|
||||
|
||||
TSDocumentSetText(document, "\"simple-string\"");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals("(value (string))"));
|
||||
ts_document_set_text(document, "\"simple-string\"");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (string))"));
|
||||
|
||||
TSDocumentSetText(document, "\"this is a \\\"string\\\" within a string\"");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals("(value (string))"));
|
||||
ts_document_set_text(document, "\"this is a \\\"string\\\" within a string\"");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (string))"));
|
||||
});
|
||||
|
||||
it("parses objects", [&]() {
|
||||
TSDocumentSetText(document, "{}");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals("(value (object))"));
|
||||
ts_document_set_text(document, "{}");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (object))"));
|
||||
|
||||
TSDocumentSetText(document, "{ \"key1\": 1 }");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals("(value (object (string) (value (number))))"));
|
||||
ts_document_set_text(document, "{ \"key1\": 1 }");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (object (string) (value (number))))"));
|
||||
|
||||
TSDocumentSetText(document, "{\"key1\": 1, \"key2\": 2 }");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals("(value (object (string) (value (number)) (string) (value (number))))"));
|
||||
ts_document_set_text(document, "{\"key1\": 1, \"key2\": 2 }");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (object (string) (value (number)) (string) (value (number))))"));
|
||||
});
|
||||
|
||||
it("parses arrays", [&]() {
|
||||
TSDocumentSetText(document, "[]");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals("(value (array))"));
|
||||
ts_document_set_text(document, "[]");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (array))"));
|
||||
|
||||
TSDocumentSetText(document, "[5]");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals("(value (array (value (number))))"));
|
||||
ts_document_set_text(document, "[5]");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (array (value (number))))"));
|
||||
|
||||
TSDocumentSetText(document, "[1, 2, 3]");
|
||||
AssertThat(string(TSDocumentToString(document)), Equals("(value (array (value (number)) (value (number)) (value (number))))"));
|
||||
ts_document_set_text(document, "[1, 2, 3]");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (array (value (number)) (value (number)) (value (number))))"));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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