2014-06-23 18:50:03 -07:00
|
|
|
#include "runtime/runtime_spec_helper.h"
|
2015-09-20 13:38:46 -07:00
|
|
|
#include <functional>
|
2014-06-23 18:50:03 -07:00
|
|
|
#include "runtime/helpers/read_test_entries.h"
|
2015-07-16 17:32:19 -07:00
|
|
|
#include "runtime/helpers/spy_input.h"
|
2014-10-22 18:44:52 -07:00
|
|
|
#include "runtime/helpers/log_debugger.h"
|
2014-03-20 18:15:38 -07:00
|
|
|
|
2014-07-31 13:04:46 -07:00
|
|
|
extern "C" const TSLanguage *ts_language_javascript();
|
|
|
|
|
extern "C" const TSLanguage *ts_language_json();
|
|
|
|
|
extern "C" const TSLanguage *ts_language_arithmetic();
|
|
|
|
|
extern "C" const TSLanguage *ts_language_golang();
|
2015-06-28 16:22:31 -05:00
|
|
|
extern "C" const TSLanguage *ts_language_c();
|
2014-03-20 18:15:38 -07:00
|
|
|
|
|
|
|
|
START_TEST
|
|
|
|
|
|
2015-09-20 13:38:46 -07:00
|
|
|
map<string, const TSLanguage *> languages({
|
|
|
|
|
{"json", ts_language_json()},
|
|
|
|
|
{"arithmetic", ts_language_arithmetic()},
|
|
|
|
|
{"javascript", ts_language_javascript()},
|
|
|
|
|
{"golang", ts_language_golang()},
|
|
|
|
|
{"c", ts_language_c()},
|
|
|
|
|
});
|
|
|
|
|
|
2014-03-20 18:15:38 -07:00
|
|
|
describe("Languages", [&]() {
|
2014-08-06 13:00:35 -07:00
|
|
|
TSDocument *doc;
|
|
|
|
|
|
|
|
|
|
before_each([&]() {
|
|
|
|
|
doc = ts_document_make();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
after_each([&]() {
|
|
|
|
|
ts_document_free(doc);
|
|
|
|
|
});
|
|
|
|
|
|
2015-09-18 23:36:47 -07:00
|
|
|
for (const auto &pair : languages) {
|
2015-09-20 13:38:46 -07:00
|
|
|
describe(("The " + pair.first + " parser").c_str(), [&]() {
|
2014-08-06 13:00:35 -07:00
|
|
|
before_each([&]() {
|
2015-09-20 13:38:46 -07:00
|
|
|
ts_document_set_language(doc, pair.second);
|
2015-10-01 17:10:39 -07:00
|
|
|
// ts_document_set_debugger(doc, log_debugger_make(false));
|
2014-08-06 13:00:35 -07:00
|
|
|
});
|
|
|
|
|
|
2015-09-20 13:38:46 -07:00
|
|
|
for (auto &entry : test_entries_for_language(pair.first)) {
|
|
|
|
|
SpyInput *input;
|
|
|
|
|
|
|
|
|
|
auto expect_the_correct_tree = [&](string tree_string) {
|
|
|
|
|
const char *node_string = ts_node_string(ts_document_root_node(doc), doc);
|
|
|
|
|
AssertThat(node_string, Equals(tree_string));
|
|
|
|
|
free((void *)node_string);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto it_handles_edit_sequence = [&](string name, std::function<void()> edit_sequence){
|
2015-09-22 21:19:19 -07:00
|
|
|
it(("parses " + entry.description + ": " + name).c_str(), [&]() {
|
2015-09-20 13:38:46 -07:00
|
|
|
input = new SpyInput(entry.input, 3);
|
|
|
|
|
ts_document_set_input(doc, input->input());
|
|
|
|
|
edit_sequence();
|
|
|
|
|
expect_the_correct_tree(entry.tree_string);
|
|
|
|
|
delete input;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
it_handles_edit_sequence("initial parse", [&]() {
|
2015-09-18 23:20:06 -07:00
|
|
|
ts_document_parse(doc);
|
2014-10-22 18:44:52 -07:00
|
|
|
});
|
|
|
|
|
|
2015-09-22 21:19:19 -07:00
|
|
|
it_handles_edit_sequence("repairing an inserted error", [&]() {
|
|
|
|
|
ts_document_edit(doc, input->replace(entry.input.size() / 2, 0, "%^&*"));
|
|
|
|
|
ts_document_parse(doc);
|
|
|
|
|
|
|
|
|
|
ts_document_edit(doc, input->undo());
|
|
|
|
|
ts_document_parse(doc);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it_handles_edit_sequence("creating and repairing an inserted error", [&]() {
|
2015-09-18 23:20:06 -07:00
|
|
|
ts_document_parse(doc);
|
2014-10-22 18:44:52 -07:00
|
|
|
|
2015-09-20 13:38:46 -07:00
|
|
|
ts_document_edit(doc, input->replace(entry.input.size() / 2, 0, "%^&*"));
|
2015-09-18 23:20:06 -07:00
|
|
|
ts_document_parse(doc);
|
2014-10-22 18:44:52 -07:00
|
|
|
|
2015-09-20 13:38:46 -07:00
|
|
|
ts_document_edit(doc, input->undo());
|
2015-09-18 23:20:06 -07:00
|
|
|
ts_document_parse(doc);
|
2014-03-24 09:14:29 -07:00
|
|
|
});
|
2015-02-21 01:28:33 -08:00
|
|
|
|
2015-09-22 21:19:19 -07:00
|
|
|
it_handles_edit_sequence("repairing an errant deletion", [&]() {
|
2015-09-18 23:20:06 -07:00
|
|
|
ts_document_parse(doc);
|
2015-02-21 01:28:33 -08:00
|
|
|
|
2015-09-20 13:38:46 -07:00
|
|
|
ts_document_edit(doc, input->replace(entry.input.size() / 2, 5, ""));
|
2015-09-18 23:20:06 -07:00
|
|
|
ts_document_parse(doc);
|
2015-02-21 01:28:33 -08:00
|
|
|
|
2015-09-20 13:38:46 -07:00
|
|
|
ts_document_edit(doc, input->undo());
|
2015-09-18 23:20:06 -07:00
|
|
|
ts_document_parse(doc);
|
2015-02-21 01:28:33 -08:00
|
|
|
});
|
2015-09-22 21:19:19 -07:00
|
|
|
|
|
|
|
|
it_handles_edit_sequence("creating and repairing an errant deletion", [&]() {
|
|
|
|
|
ts_document_edit(doc, input->replace(entry.input.size() / 2, 5, ""));
|
|
|
|
|
ts_document_parse(doc);
|
|
|
|
|
|
|
|
|
|
ts_document_edit(doc, input->undo());
|
|
|
|
|
ts_document_parse(doc);
|
|
|
|
|
});
|
2014-08-06 13:00:35 -07:00
|
|
|
}
|
|
|
|
|
});
|
2015-09-18 23:36:47 -07:00
|
|
|
}
|
2014-03-20 18:15:38 -07:00
|
|
|
});
|
|
|
|
|
|
2014-06-23 18:50:03 -07:00
|
|
|
END_TEST
|