tree-sitter/spec/runtime/arithmetic_spec.cpp

48 lines
1.7 KiB
C++
Raw Normal View History

#include "spec_helper.h"
2014-01-08 18:35:16 -08:00
extern TSParseConfig ts_parse_config_arithmetic;
2013-12-17 13:14:41 -08:00
START_TEST
2013-12-17 13:14:41 -08:00
describe("arithmetic", []() {
2014-01-09 13:31:30 -08:00
TSDocument *document;
before_each([&]() {
document = TSDocumentMake();
2014-01-08 18:35:16 -08:00
TSDocumentSetUp(document, ts_parse_config_arithmetic);
2014-01-09 13:31:30 -08:00
});
it("parses variables", [&]() {
TSDocumentSetText(document, "x");
AssertThat(string(TSDocumentToString(document)), Equals(
"(expression (term (factor (variable))))"));
2014-01-09 13:31:30 -08:00
});
it("parses numbers", [&]() {
TSDocumentSetText(document, "5");
AssertThat(string(TSDocumentToString(document)), Equals(
"(expression (term (factor (number))))"));
});
2014-01-09 13:31:30 -08:00
it("parses products of variables", [&]() {
2014-02-19 12:48:38 -08:00
TSDocumentSetText(document, "x + y");
2014-01-23 13:00:08 -08:00
AssertThat(string(TSDocumentToString(document)), Equals(
"(expression (term (factor (variable))) (plus) (term (factor (variable))))"));
2014-02-19 12:48:38 -08:00
TSDocumentSetText(document, "x * y");
AssertThat(string(TSDocumentToString(document)), Equals(
2014-01-23 13:00:08 -08:00
"(expression (term (factor (variable)) (times) (factor (variable))))"));
});
it("parses complex trees", [&]() {
2014-02-19 12:48:38 -08:00
TSDocumentSetText(document, "x * y + z * a");
AssertThat(string(TSDocumentToString(document)), Equals(
2014-01-23 13:00:08 -08:00
"(expression (term (factor (variable)) (times) (factor (variable))) (plus) (term (factor (variable)) (times) (factor (variable))))"));
2014-02-19 12:48:38 -08:00
TSDocumentSetText(document, "x * (y + z)");
AssertThat(string(TSDocumentToString(document)), Equals(
"(expression (term (factor (variable)) (times) (factor (expression (term (factor (variable))) (plus) (term (factor (variable)))))))"));
});
});
END_TEST