tree-sitter/spec/runtime/arithmetic_spec.cpp
Max Brunsfeld 6ed6aa05cc Update runtime code naming
Also, add macros so that code generator doesn't
need to know about any runtime variables names
or types
2014-02-20 13:30:43 -08:00

48 lines
No EOL
1.7 KiB
C++

#include "spec_helper.h"
extern ts_parse_config ts_parse_config_arithmetic;
START_TEST
describe("arithmetic", []() {
ts_document *document;
before_each([&]() {
document = ts_document_make();
ts_document_set_parser(document, ts_parse_config_arithmetic);
});
it("parses variables", [&]() {
ts_document_set_text(document, "x");
AssertThat(string(ts_document_string(document)), Equals(
"(expression (term (factor (variable))))"));
});
it("parses numbers", [&]() {
ts_document_set_text(document, "5");
AssertThat(string(ts_document_string(document)), Equals(
"(expression (term (factor (number))))"));
});
it("parses products of variables", [&]() {
ts_document_set_text(document, "x + y");
AssertThat(string(ts_document_string(document)), Equals(
"(expression (term (factor (variable))) (plus) (term (factor (variable))))"));
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", [&]() {
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))))"));
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)))))))"));
});
});
END_TEST