tree-sitter/spec/runtime/document_spec.cc

66 lines
1.7 KiB
C++
Raw Normal View History

#include "runtime/runtime_spec_helper.h"
extern "C" const TSLanguage * ts_language_json();
START_TEST
describe("Document", [&]() {
TSDocument *doc;
before_each([&]() {
doc = ts_document_make();
});
after_each([&]() {
ts_document_free(doc);
});
2014-09-10 18:49:53 -07:00
describe("set_input(TSInput)", [&]() {
2014-08-29 13:22:03 -07:00
describe("when the language is set", [&]() {
before_each([&]() {
2014-08-29 13:22:03 -07:00
ts_document_set_language(doc, ts_language_json());
});
2014-08-29 13:22:03 -07:00
it("parses the document", [&]() {
2014-09-10 18:49:53 -07:00
ts_document_set_input_string(doc, "{ \"key\": [1, 2] }");
2014-09-10 18:49:53 -07:00
AssertThat(ts_node_string(ts_document_root_node(doc)), Equals(
"(DOCUMENT (object (string) (array (number) (number))))"));
});
2014-08-29 13:22:03 -07:00
});
2014-08-29 13:22:03 -07:00
describe("when the language is not set", [&]() {
it("does not try to parse the document", [&]() {
2014-09-10 18:49:53 -07:00
ts_document_set_input_string(doc, "{ \"key\": [1, 2] }");
2014-08-29 13:22:03 -07:00
AssertThat(ts_document_root_node(doc), Equals<TSNode *>(nullptr));
});
});
});
2014-09-10 18:49:53 -07:00
describe("set_language(TSLanguage)", [&]() {
describe("when the input is not set", [&]() {
it("does not try to parse the document", [&]() {
2014-08-29 13:22:03 -07:00
ts_document_set_language(doc, ts_language_json());
2014-09-10 18:49:53 -07:00
AssertThat(ts_document_root_node(doc), Equals<TSNode *>(nullptr));
2014-08-31 12:10:31 -07:00
});
});
2014-09-10 18:49:53 -07:00
describe("when the input is set", [&]() {
2014-08-31 12:10:31 -07:00
before_each([&]() {
2014-09-10 18:49:53 -07:00
ts_document_set_input_string(doc, "{ \"key\": [1, 2] }");
2014-08-31 12:10:31 -07:00
});
2014-09-10 18:49:53 -07:00
it("parses the document", [&]() {
ts_document_set_language(doc, ts_language_json());
2014-08-31 12:10:31 -07:00
2014-09-10 18:49:53 -07:00
AssertThat(ts_node_string(ts_document_root_node(doc)), Equals(
"(DOCUMENT (object (string) (array (number) (number))))"));
2014-08-31 12:10:31 -07:00
});
2014-08-29 13:22:03 -07:00
});
});
});
END_TEST