From 09b019c530e6effa0cecc01e6fb211e88e7aaeac Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 23 Jun 2016 09:24:26 -0700 Subject: [PATCH] Fix test for invalid blank input --- spec/runtime/document_spec.cc | 4 +++- src/runtime/tree.c | 15 ++------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/spec/runtime/document_spec.cc b/spec/runtime/document_spec.cc index bf4e7b72..584eeb87 100644 --- a/spec/runtime/document_spec.cc +++ b/spec/runtime/document_spec.cc @@ -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(0)); assert_node_string_equals( new_root, - "(ERROR (UNEXPECTED ))"); + "(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(1)); assert_node_string_equals( new_root, "(number)"); diff --git a/src/runtime/tree.c b/src/runtime/tree.c index 41b446a9..95f3bb8c 100644 --- a/src/runtime/tree.c +++ b/src/runtime/tree.c @@ -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, ""); - 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));