2014-10-14 22:50:24 -07:00
|
|
|
#include "runtime/debugger.h"
|
2014-10-13 01:02:12 -07:00
|
|
|
#include "runtime/helpers/spy_debugger.h"
|
2014-10-14 22:50:24 -07:00
|
|
|
#include "runtime/runtime_spec_helper.h"
|
2014-07-10 13:14:52 -07:00
|
|
|
|
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
|
|
|
|
2015-07-31 15:47:48 -07:00
|
|
|
AssertThat(ts_node_string(ts_document_root_node(doc), doc), Equals(
|
2015-08-22 10:48:34 -07:00
|
|
|
"(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
|
|
|
|
2015-07-31 15:47:48 -07:00
|
|
|
AssertThat(ts_document_root_node(doc).data, Equals<void *>(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());
|
|
|
|
|
|
2015-07-31 15:47:48 -07:00
|
|
|
AssertThat(ts_document_root_node(doc).data, Equals<void *>(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
|
|
|
|
2015-07-31 15:47:48 -07:00
|
|
|
AssertThat(ts_node_string(ts_document_root_node(doc), doc), Equals(
|
2015-08-22 10:48:34 -07:00
|
|
|
"(object (string) (array (number) (number)))"));
|
2014-08-31 12:10:31 -07:00
|
|
|
});
|
2014-08-29 13:22:03 -07:00
|
|
|
});
|
|
|
|
|
});
|
2014-10-13 01:02:12 -07:00
|
|
|
|
2014-10-17 17:52:54 -07:00
|
|
|
describe("set_debugger(TSDebugger)", [&]() {
|
2014-10-13 01:02:12 -07:00
|
|
|
SpyDebugger *debugger;
|
|
|
|
|
|
|
|
|
|
before_each([&]() {
|
|
|
|
|
debugger = new SpyDebugger();
|
2014-10-17 17:52:54 -07:00
|
|
|
ts_document_set_language(doc, ts_language_json());
|
|
|
|
|
ts_document_set_debugger(doc, debugger->debugger());
|
2014-10-13 01:02:12 -07:00
|
|
|
});
|
|
|
|
|
|
2014-10-17 17:52:54 -07:00
|
|
|
it("calls the debugger with a message for each lex action", [&]() {
|
|
|
|
|
ts_document_set_input_string(doc, "[1, 2]");
|
2014-10-13 01:02:12 -07:00
|
|
|
|
2014-10-17 17:52:54 -07:00
|
|
|
AssertThat(debugger->messages, Contains("lookahead char:'1'"));
|
|
|
|
|
AssertThat(debugger->messages, Contains("advance state:1"));
|
|
|
|
|
AssertThat(debugger->messages, Contains("accept_token sym:number"));
|
|
|
|
|
});
|
2014-10-13 01:02:12 -07:00
|
|
|
|
2014-10-17 17:52:54 -07:00
|
|
|
it("calls the debugger with a message for each parse action", [&]() {
|
|
|
|
|
ts_document_set_input_string(doc, "[1, 2]");
|
2014-10-13 01:02:12 -07:00
|
|
|
|
2015-05-27 10:53:02 -07:00
|
|
|
AssertThat(debugger->messages, Contains("new_parse"));
|
|
|
|
|
AssertThat(debugger->messages, Contains("lookahead char:'['"));
|
2015-09-02 16:36:29 -07:00
|
|
|
AssertThat(debugger->messages, Contains("reduce sym:array, count:4"));
|
2014-10-17 17:52:54 -07:00
|
|
|
AssertThat(debugger->messages, Contains("accept"));
|
|
|
|
|
});
|
2014-10-13 01:02:12 -07:00
|
|
|
|
2014-10-17 17:52:54 -07:00
|
|
|
it("allows the debugger to be retrieved later", [&]() {
|
|
|
|
|
AssertThat(ts_document_get_debugger(doc).data, Equals(debugger));
|
2014-10-13 01:02:12 -07:00
|
|
|
});
|
|
|
|
|
|
2014-10-17 17:52:54 -07:00
|
|
|
describe("disabling debugging", [&]() {
|
2014-10-13 01:02:12 -07:00
|
|
|
before_each([&]() {
|
2014-10-17 21:27:49 -07:00
|
|
|
ts_document_set_debugger(doc, ts_debugger_null());
|
2014-10-13 01:02:12 -07:00
|
|
|
});
|
|
|
|
|
|
2014-10-17 17:52:54 -07:00
|
|
|
it("does not call the debugger any more", [&]() {
|
2014-10-13 01:02:12 -07:00
|
|
|
ts_document_set_input_string(doc, "[1, 2]");
|
2014-10-17 17:52:54 -07:00
|
|
|
AssertThat(debugger->messages, IsEmpty());
|
2014-10-13 01:02:12 -07:00
|
|
|
});
|
|
|
|
|
|
2014-10-17 17:52:54 -07:00
|
|
|
it("releases the old debugger", [&]() {
|
|
|
|
|
AssertThat(debugger->release_call_count, Equals<size_t>(1));
|
2014-10-13 01:02:12 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-07-10 13:14:52 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
END_TEST
|