From d3137c6ac6d26038702e51fd761e81e99fe614e4 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 14 Oct 2014 23:12:26 -0700 Subject: [PATCH] Organize parser spec --- spec/runtime/parser_spec.cc | 94 ++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/spec/runtime/parser_spec.cc b/spec/runtime/parser_spec.cc index 1a50a659..6c6d35a1 100644 --- a/spec/runtime/parser_spec.cc +++ b/spec/runtime/parser_spec.cc @@ -220,7 +220,7 @@ describe("Parser", [&]() { }); describe("inserting text", [&]() { - describe("new tokens near the end of the input", [&]() { + describe("creating new tokens near the end of the input", [&]() { before_each([&]() { set_text("x ^ (100 + abc)"); @@ -244,30 +244,7 @@ describe("Parser", [&]() { }); }); - describe("introducing an error", [&]() { - it("gives the error the right size", [&]() { - ts_document_set_language(doc, ts_language_javascript()); - - set_text("var x = y;"); - - AssertThat(ts_node_string(root), Equals( - "(DOCUMENT (var_declaration " - "(identifier) (identifier)))")); - - insert_text(strlen("var x = y"), " *"); - - AssertThat(ts_node_string(root), Equals( - "(DOCUMENT (var_declaration (ERROR ';')))")); - - insert_text(strlen("var x = y *"), " z"); - - AssertThat(ts_node_string(root), Equals( - "(DOCUMENT (var_declaration " - "(identifier) (math_op (identifier) (identifier))))")); - }); - }); - - describe("new tokens near the beginning of the input", [&]() { + describe("creating new tokens near the beginning of the input", [&]() { before_each([&]() { chunk_size = 2; @@ -295,6 +272,29 @@ describe("Parser", [&]() { }); }); + describe("introducing an error", [&]() { + it("gives the error the right size", [&]() { + ts_document_set_language(doc, ts_language_javascript()); + + set_text("var x = y;"); + + AssertThat(ts_node_string(root), Equals( + "(DOCUMENT (var_declaration " + "(identifier) (identifier)))")); + + insert_text(strlen("var x = y"), " *"); + + AssertThat(ts_node_string(root), Equals( + "(DOCUMENT (var_declaration (ERROR ';')))")); + + insert_text(strlen("var x = y *"), " z"); + + AssertThat(ts_node_string(root), Equals( + "(DOCUMENT (var_declaration " + "(identifier) (math_op (identifier) (identifier))))")); + }); + }); + describe("into the middle of an existing token", [&]() { before_each([&]() { set_text("abc * 123"); @@ -354,6 +354,28 @@ describe("Parser", [&]() { "(DOCUMENT (sum (variable) (variable)))")); }); }); + + describe("into a node containing a ubiquitous token", [&]() { + before_each([&]() { + set_text("123 *\n" + "# a-comment\n" + "abc"); + + AssertThat(ts_node_string(root), Equals( + "(DOCUMENT (product (number) (comment) (variable)))")); + + insert_text( + strlen("123 *\n" + "# a-comment\n" + "abc"), + "XYZ"); + }); + + it("updates the parse tree", [&]() { + AssertThat(ts_node_string(root), Equals( + "(DOCUMENT (product (number) (comment) (variable)))")); + }); + }); }); describe("deleting text", [&]() { @@ -391,28 +413,6 @@ describe("Parser", [&]() { "(identifier) (property_access (identifier) (identifier)))))")); }); }); - - describe("editing text inside a node containing a ubiquitous token", [&]() { - before_each([&]() { - set_text("123 *\n" - "# a-comment\n" - "abc"); - - AssertThat(ts_node_string(root), Equals( - "(DOCUMENT (product (number) (comment) (variable)))")); - - insert_text( - strlen("123 *\n" - "# a-comment\n" - "abc"), - "XYZ"); - }); - - it("updates the parse tree", [&]() { - AssertThat(ts_node_string(root), Equals( - "(DOCUMENT (product (number) (comment) (variable)))")); - }); - }); }); describe("lexing", [&]() {