Fix test for invalid blank input

This commit is contained in:
Max Brunsfeld 2016-06-23 09:24:26 -07:00
parent c6e9b32d3f
commit 09b019c530
2 changed files with 5 additions and 14 deletions

View file

@ -100,13 +100,15 @@ describe("Document", [&]() {
ts_document_set_input_string(doc, "");
ts_document_parse(doc);
TSNode new_root = ts_document_root_node(doc);
AssertThat(ts_node_end_char(new_root), Equals<size_t>(0));
assert_node_string_equals(
new_root,
"(ERROR (UNEXPECTED <EOF>))");
"(ERROR)");
ts_document_set_input_string(doc, "1");
ts_document_parse(doc);
new_root = ts_document_root_node(doc);
AssertThat(ts_node_end_char(new_root), Equals<size_t>(1));
assert_node_string_equals(
new_root,
"(number)");

View file

@ -384,16 +384,6 @@ void ts_tree_edit(TSTree *self, TSInputEdit edit) {
}
}
static size_t write_lookahead_to_string(char *string, size_t limit,
char lookahead) {
switch (lookahead) {
case '\0':
return snprintf(string, limit, "<EOF>");
default:
return snprintf(string, limit, "'%c'", lookahead);
}
}
static size_t ts_tree__write_to_string(const TSTree *self,
const TSLanguage *language, char *string,
size_t limit, bool is_root,
@ -409,9 +399,8 @@ static size_t ts_tree__write_to_string(const TSTree *self,
cursor += snprintf(*writer, limit, " ");
if (visible) {
if (self->symbol == ts_builtin_sym_error && self->child_count == 0) {
cursor += snprintf(*writer, limit, "(UNEXPECTED ");
cursor += write_lookahead_to_string(*writer, limit, self->lookahead_char);
if (self->symbol == ts_builtin_sym_error && self->child_count == 0 && self->size.chars > 0) {
cursor += snprintf(*writer, limit, "(UNEXPECTED '%c'", self->lookahead_char);
} else {
cursor += snprintf(*writer, limit, "(%s",
ts_language_symbol_name(language, self->symbol));