2014-07-10 13:14:52 -07:00
|
|
|
#include "runtime/runtime_spec_helper.h"
|
|
|
|
|
|
2014-07-31 13:04:46 -07:00
|
|
|
extern "C" const TSLanguage * ts_language_json();
|
2014-07-10 13:14:52 -07:00
|
|
|
|
|
|
|
|
START_TEST
|
|
|
|
|
|
2014-08-01 12:34:40 -07:00
|
|
|
describe("Document", [&]() {
|
|
|
|
|
TSDocument *doc;
|
2014-07-10 13:14:52 -07:00
|
|
|
|
2014-08-01 12:34:40 -07:00
|
|
|
before_each([&]() {
|
|
|
|
|
doc = ts_document_make();
|
|
|
|
|
});
|
2014-07-10 13:14:52 -07:00
|
|
|
|
2014-08-01 12:34:40 -07:00
|
|
|
after_each([&]() {
|
|
|
|
|
ts_document_free(doc);
|
|
|
|
|
});
|
2014-07-10 13:14:52 -07:00
|
|
|
|
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", [&]() {
|
2014-08-01 12:34:40 -07:00
|
|
|
before_each([&]() {
|
2014-08-29 13:22:03 -07:00
|
|
|
ts_document_set_language(doc, ts_language_json());
|
2014-08-01 12:34:40 -07:00
|
|
|
});
|
2014-07-10 13:14:52 -07:00
|
|
|
|
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-08-01 12:34:40 -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-01 12:34:40 -07:00
|
|
|
});
|
2014-08-29 13:22:03 -07:00
|
|
|
});
|
2014-07-10 13:14:52 -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-07-10 13:14:52 -07:00
|
|
|
|
2014-08-29 13:22:03 -07:00
|
|
|
AssertThat(ts_document_root_node(doc), Equals<TSNode *>(nullptr));
|
2014-08-01 12:34:40 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-07-10 13:14:52 -07:00
|
|
|
|
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
|
|
|
});
|
|
|
|
|
});
|
2014-07-10 13:14:52 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
END_TEST
|