Add some edit sequences to corpus tests

This commit is contained in:
Max Brunsfeld 2015-09-22 21:19:19 -07:00
parent d032114d7a
commit 90862dd18f
3 changed files with 27 additions and 9 deletions

View file

@ -1,20 +1,22 @@
#include "tree_sitter/runtime.h"
#include <stdio.h>
static void log_debug(void *data, TSDebugType type, const char *msg) {
static void log_debug(void *payload, TSDebugType type, const char *msg) {
bool include_lexing = (bool)payload;
switch (type) {
case TSDebugTypeParse:
fprintf(stderr, "* %s\n", msg);
break;
case TSDebugTypeLex:
fprintf(stderr, " %s\n", msg);
if (include_lexing)
fprintf(stderr, " %s\n", msg);
break;
}
}
TSDebugger log_debugger_make() {
TSDebugger log_debugger_make(bool include_lexing) {
TSDebugger result;
result.payload = NULL;
result.payload = (void *)include_lexing;
result.debug_fn = log_debug;
return result;
}

View file

@ -3,6 +3,6 @@
#include "tree_sitter/runtime.h"
TSDebugger log_debugger_make();
TSDebugger log_debugger_make(bool include_lexing);
#endif // HELPERS_LOG_DEBUGGER_H_

View file

@ -35,7 +35,7 @@ describe("Languages", [&]() {
describe(("The " + pair.first + " parser").c_str(), [&]() {
before_each([&]() {
ts_document_set_language(doc, pair.second);
// ts_document_set_debugger(doc, log_debugger_make());
// ts_document_set_debugger(doc, log_debugger_make(true));
});
for (auto &entry : test_entries_for_language(pair.first)) {
@ -48,7 +48,7 @@ describe("Languages", [&]() {
};
auto it_handles_edit_sequence = [&](string name, std::function<void()> edit_sequence){
it(("handles " + entry.description + ": " + name).c_str(), [&]() {
it(("parses " + entry.description + ": " + name).c_str(), [&]() {
input = new SpyInput(entry.input, 3);
ts_document_set_input(doc, input->input());
edit_sequence();
@ -61,7 +61,15 @@ describe("Languages", [&]() {
ts_document_parse(doc);
});
it_handles_edit_sequence("one insertion, undo", [&]() {
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", [&]() {
ts_document_parse(doc);
ts_document_edit(doc, input->replace(entry.input.size() / 2, 0, "%^&*"));
@ -71,7 +79,7 @@ describe("Languages", [&]() {
ts_document_parse(doc);
});
it_handles_edit_sequence("one deletion, undo", [&]() {
it_handles_edit_sequence("repairing an errant deletion", [&]() {
ts_document_parse(doc);
ts_document_edit(doc, input->replace(entry.input.size() / 2, 5, ""));
@ -80,6 +88,14 @@ describe("Languages", [&]() {
ts_document_edit(doc, input->undo());
ts_document_parse(doc);
});
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);
});
}
});
}