2014-07-10 13:14:52 -07:00
|
|
|
#include "runtime/runtime_spec_helper.h"
|
|
|
|
|
#include "runtime/helpers/spy_reader.h"
|
2014-07-17 23:29:11 -07:00
|
|
|
#include "runtime/tree.h"
|
2014-07-10 13:14:52 -07:00
|
|
|
|
2014-07-30 23:40:02 -07:00
|
|
|
extern "C" const TSLanguage * ts_language_json;
|
2014-07-10 13:14:52 -07:00
|
|
|
|
|
|
|
|
START_TEST
|
|
|
|
|
|
|
|
|
|
describe("incremental parsing", [&]() {
|
|
|
|
|
TSDocument *doc;
|
|
|
|
|
|
|
|
|
|
before_each([&]() {
|
|
|
|
|
doc = ts_document_make();
|
2014-07-30 23:40:02 -07:00
|
|
|
ts_document_set_language(doc, ts_language_json);
|
2014-07-10 13:14:52 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
after_each([&]() {
|
|
|
|
|
ts_document_free(doc);
|
|
|
|
|
});
|
|
|
|
|
|
2014-07-17 23:29:11 -07:00
|
|
|
describe("incremental parsing", [&]() {
|
|
|
|
|
SpyReader *reader;
|
2014-07-10 13:14:52 -07:00
|
|
|
|
|
|
|
|
before_each([&]() {
|
2014-07-17 23:29:11 -07:00
|
|
|
reader = new SpyReader("{ \"key\": [1, 2] }", 5);
|
|
|
|
|
ts_document_set_input(doc, reader->input);
|
|
|
|
|
});
|
2014-07-10 13:14:52 -07:00
|
|
|
|
2014-07-17 23:29:11 -07:00
|
|
|
after_each([&]() {
|
|
|
|
|
delete reader;
|
2014-07-10 13:14:52 -07:00
|
|
|
});
|
|
|
|
|
|
2014-07-17 23:29:11 -07:00
|
|
|
it("parses the input", [&]() {
|
2014-07-10 13:14:52 -07:00
|
|
|
AssertThat(string(ts_document_string(doc)), Equals(
|
2014-07-17 23:29:11 -07:00
|
|
|
"(object (string) (array (number) (number)))"));
|
2014-07-10 13:14:52 -07:00
|
|
|
});
|
|
|
|
|
|
2014-07-17 23:29:11 -07:00
|
|
|
it("reads the entire input", [&]() {
|
|
|
|
|
AssertThat(reader->strings_read, Equals(vector<string>({
|
|
|
|
|
"{ \"key\": [1, 2] }"
|
|
|
|
|
})));
|
2014-07-10 13:14:52 -07:00
|
|
|
});
|
|
|
|
|
|
2014-07-17 23:29:11 -07:00
|
|
|
describe("modifying the end of the input", [&]() {
|
|
|
|
|
before_each([&]() {
|
|
|
|
|
size_t position(string("{ \"key\": [1, 2]").length());
|
|
|
|
|
string inserted_text(", \"key2\": 4");
|
2014-07-10 13:14:52 -07:00
|
|
|
|
2014-07-17 23:29:11 -07:00
|
|
|
reader->content.insert(position, inserted_text);
|
|
|
|
|
ts_document_edit(doc, { position, 0, inserted_text.length() });
|
|
|
|
|
});
|
2014-07-10 13:14:52 -07:00
|
|
|
|
2014-07-17 23:29:11 -07:00
|
|
|
it("updates the parse tree", [&]() {
|
|
|
|
|
AssertThat(string(ts_document_string(doc)), Equals(
|
|
|
|
|
"(object (string) (array (number) (number)) (string) (number))"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("re-reads only the changed portion of the input", [&]() {
|
|
|
|
|
AssertThat(reader->strings_read.size(), Equals<size_t>(2));
|
|
|
|
|
AssertThat(reader->strings_read[1], Equals(", \"key2\": 4 }"));
|
|
|
|
|
});
|
2014-07-10 13:14:52 -07:00
|
|
|
});
|
|
|
|
|
|
2014-07-17 23:29:11 -07:00
|
|
|
describe("modifying the beginning of the input", [&]() {
|
|
|
|
|
before_each([&]() {
|
|
|
|
|
size_t position(string("{ ").length());
|
|
|
|
|
string inserted_text("\"key2\": 4, ");
|
|
|
|
|
|
|
|
|
|
reader->content.insert(position, inserted_text);
|
|
|
|
|
ts_document_edit(doc, { position, 0, inserted_text.length() });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("updates the parse tree", [&]() {
|
|
|
|
|
AssertThat(string(ts_document_string(doc)), Equals(
|
|
|
|
|
"(object (string) (number) (string) (array (number) (number)))"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it_skip("re-reads only the changed portion of the input", [&]() {
|
|
|
|
|
AssertThat(reader->strings_read.size(), Equals<size_t>(2));
|
|
|
|
|
AssertThat(reader->strings_read[1], Equals("\"key2\": 4, "));
|
|
|
|
|
});
|
2014-07-10 13:14:52 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
END_TEST
|