From e5ea6165fd2a2f774c4c7d7c582fc9015ef7bf07 Mon Sep 17 00:00:00 2001 From: Pranjal Raihan Date: Tue, 4 Feb 2025 19:12:42 -0800 Subject: [PATCH] Improve parser test error messages Summary: This diff breaks up passing and failing tests into helpers: `parse_ast` and `parse_ast_should_fail` respectively. The big win is that some tests forgot to put `EXPECT_THAT(diagnostics, IsEmpty())` which shows the parse error if the test fails. This dif means that all tests should now do the right thing. Reviewed By: rmakheja Differential Revision: D69095813 fbshipit-source-id: 25f1d8de193ecaf802e82e9c39fad4db861b8b62 --- thrift/compiler/whisker/test/parser_test.cc | 364 ++++++++------------ 1 file changed, 150 insertions(+), 214 deletions(-) diff --git a/thrift/compiler/whisker/test/parser_test.cc b/thrift/compiler/whisker/test/parser_test.cc index fac41117a32..cdaf0e76164 100644 --- a/thrift/compiler/whisker/test/parser_test.cc +++ b/thrift/compiler/whisker/test/parser_test.cc @@ -45,12 +45,23 @@ class ParserTest : public testing::Test { return fmt::format("path/to/test-{}.whisker", id); } - std::optional parse_ast(const std::string& source) { + std::optional try_parse_ast(const std::string& source) { diagnostics.clear(); return parse( src_manager.add_virtual_file(path_to_file(file_id++), source), diags); } + [[nodiscard]] ast::root parse_ast(const std::string& source) { + auto ast = try_parse_ast(source); + EXPECT_THAT(diagnostics, testing::IsEmpty()); + return ast.value(); + } + + void parse_ast_should_fail(const std::string& source) { + auto ast = try_parse_ast(source); + ASSERT_FALSE(ast.has_value()); + } + std::string to_string(const ast::root& ast) { std::ostringstream out; print_ast(ast, src_manager, out); @@ -65,13 +76,13 @@ class ParserTest : public testing::Test { TEST_F(ParserTest, empty) { auto ast = parse_ast(""); - EXPECT_TRUE(ast->body_elements.empty()); + EXPECT_TRUE(ast.body_elements.empty()); } TEST_F(ParserTest, basic) { auto ast = parse_ast("Some text {{foo.bar}} more text"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text 'Some text '\n" "|- interpolation 'foo.bar'\n" @@ -79,8 +90,7 @@ TEST_F(ParserTest, basic) { } TEST_F(ParserTest, empty_template) { - auto ast = parse_ast("{{ }}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{ }}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -93,7 +103,7 @@ TEST_F(ParserTest, empty_template) { TEST_F(ParserTest, variable_is_single_id) { auto ast = parse_ast("{{ foo }}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- interpolation 'foo'\n"); } @@ -101,7 +111,7 @@ TEST_F(ParserTest, variable_is_single_id) { TEST_F(ParserTest, variable_is_multi_id) { auto ast = parse_ast("{{ foo. bar.baz }}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- interpolation 'foo.bar.baz'\n"); } @@ -109,23 +119,24 @@ TEST_F(ParserTest, variable_is_multi_id) { TEST_F(ParserTest, variable_is_dot) { auto ast = parse_ast("{{. }}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- interpolation 'this'\n"); } TEST_F(ParserTest, variable_starts_with_dot) { - auto ast = parse_ast("{{ .foo }}"); - EXPECT_FALSE(ast.has_value()); - EXPECT_EQ(diagnostics.size(), 1); - EXPECT_EQ( - diagnostics[0].message(), - "expected `}}` to close interpolation but found identifier"); + parse_ast_should_fail("{{ .foo }}"); + EXPECT_THAT( + diagnostics, + testing::ElementsAre(diagnostic( + diagnostic_level::error, + "expected `}}` to close interpolation but found identifier", + path_to_file(1), + 1))); } TEST_F(ParserTest, variable_has_extra_stuff_after) { - auto ast = parse_ast("{{foo.bar!}}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{foo.bar!}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -141,7 +152,7 @@ TEST_F(ParserTest, basic_section) { " Stuff is {{foo}} happening!\n" "{{/ news.has-update?}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- section-block \n" "| `- variable-lookup 'news.has-update?'\n" @@ -157,7 +168,7 @@ TEST_F(ParserTest, inverted_section) { " Stuff is {{foo}} happening!\n" "{{/news.has-update?}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- section-block \n" "| `- variable-lookup 'news.has-update?'\n" @@ -175,7 +186,7 @@ TEST_F(ParserTest, nested_sections) { " {{/update.is-important?}}\n" "{{/news.has-update?}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- section-block \n" "| `- variable-lookup 'news.has-update?'\n" @@ -188,14 +199,13 @@ TEST_F(ParserTest, nested_sections) { } TEST_F(ParserTest, mismatched_section_hierarchy) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#news.has-update?}}\n" " {{#update.is-important?}}\n" " Important stuff is {{foo}} happening!\n" " {{#inner}}{{/inner}}\n" " {{/news.has-update?}}\n" "{{/update.is-important?}}"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre( @@ -212,8 +222,7 @@ TEST_F(ParserTest, mismatched_section_hierarchy) { } TEST_F(ParserTest, section_open_by_itself) { - auto ast = parse_ast("{{#news.has-update?}}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#news.has-update?}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -226,8 +235,7 @@ TEST_F(ParserTest, section_open_by_itself) { TEST_F(ParserTest, section_with_bad_close) { // keyword to close { - auto ast = parse_ast("{{#news.has-update?}}{{/true}}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#news.has-update?}}{{/true}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -238,8 +246,7 @@ TEST_F(ParserTest, section_with_bad_close) { } // missing }} { - auto ast = parse_ast("{{#news.has-update?}}{{/ news.has-update?"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#news.has-update?}}{{/ news.has-update?"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -250,8 +257,7 @@ TEST_F(ParserTest, section_with_bad_close) { } // mismatch + missing close { - auto ast = parse_ast("{{#news.has-update?}}{{/ foo-bar?"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#news.has-update?}}{{/ foo-bar?"); EXPECT_THAT( diagnostics, testing::ElementsAre( @@ -269,8 +275,7 @@ TEST_F(ParserTest, section_with_bad_close) { } TEST_F(ParserTest, section_close_by_itself) { - auto ast = parse_ast("{{/news.has-update?}}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{/news.has-update?}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -286,7 +291,7 @@ TEST_F(ParserTest, basic_if) { " Stuff is {{foo}} happening!\n" "{{/if news.has-update?}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- if-block \n" "| `- expression 'news.has-update?'\n" @@ -304,7 +309,7 @@ TEST_F(ParserTest, basic_if_else) { " Nothing is happening!\n" "{{/if news.has-update?}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- if-block \n" "| `- expression 'news.has-update?'\n" @@ -318,7 +323,7 @@ TEST_F(ParserTest, basic_if_else) { } TEST_F(ParserTest, unless_block_repeated_else) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#if (not news.has-update?)}}\n" " Stuff is {{foo}} happening!\n" "{{#else}}\n" @@ -326,7 +331,6 @@ TEST_F(ParserTest, unless_block_repeated_else) { "{{#else}}\n" " Nothing is happening!\n" "{{/if (not news.has-update?)}}"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -337,8 +341,7 @@ TEST_F(ParserTest, unless_block_repeated_else) { } TEST_F(ParserTest, if_block_else_by_itself) { - auto ast = parse_ast("{{#else}}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#else}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -349,8 +352,7 @@ TEST_F(ParserTest, if_block_else_by_itself) { } TEST_F(ParserTest, if_block_unclosed_with_else) { - auto ast = parse_ast("{{#if news.has-update?}}{{#else}}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#if news.has-update?}}{{#else}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -370,7 +372,7 @@ TEST_F(ParserTest, if_block_nested) { " {{/if update.is-important?}}\n" "{{/if news.has-update?}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- if-block \n" "| `- expression 'news.has-update?'\n" @@ -386,14 +388,13 @@ TEST_F(ParserTest, if_block_nested) { } TEST_F(ParserTest, mismatched_if_hierarchy) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#if news.has-update?}}\n" " {{#update.is-important?}}\n" " Important stuff is {{foo}} happening!\n" " {{#inner}}{{/inner}}\n" " {{/if news.has-update?}}\n" "{{/update.is-important?}}"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -404,8 +405,7 @@ TEST_F(ParserTest, mismatched_if_hierarchy) { } TEST_F(ParserTest, if_by_itself) { - auto ast = parse_ast("{{#if}}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#if}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -416,8 +416,7 @@ TEST_F(ParserTest, if_by_itself) { } TEST_F(ParserTest, if_close_by_itself) { - auto ast = parse_ast("{{/if}}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{/if}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -428,13 +427,12 @@ TEST_F(ParserTest, if_close_by_itself) { } TEST_F(ParserTest, conditional_block_mismatched_open_and_close) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#if (not news.has-update?)}}\n" " Stuff is happening!\n" "{{#else}}\n" " Nothing is happening!\n" "{{/unless}}"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -445,13 +443,12 @@ TEST_F(ParserTest, conditional_block_mismatched_open_and_close) { } TEST_F(ParserTest, conditional_block_missing_close_lookup) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#if news.has-update?}}\n" " Stuff is happening!\n" "{{#else}}\n" " Nothing is happening!\n" "{{/if}}"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -462,13 +459,12 @@ TEST_F(ParserTest, conditional_block_missing_close_lookup) { } TEST_F(ParserTest, conditional_block_mismatched_lookup) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#if news.has-update?}}\n" " Stuff is happening!\n" "{{#else}}\n" " Nothing is happening!\n" "{{/if news.has_updates?}}"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -487,9 +483,8 @@ TEST_F(ParserTest, conditional_block_else_if) { "{{#else}}\n" " Nothing is happening!\n" "{{/if news.has-update?}}"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- if-block \n" "| `- expression 'news.has-update?'\n" @@ -504,7 +499,7 @@ TEST_F(ParserTest, conditional_block_else_if) { } TEST_F(ParserTest, conditional_block_else_if_after_else) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#if news.has-update?}}\n" " New stuff is happening!\n" "{{#else}}\n" @@ -512,7 +507,6 @@ TEST_F(ParserTest, conditional_block_else_if_after_else) { "{{#else if news.is-important?}}\n" " Important stuff is happening!\n" "{{/if news.has-update?}}"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -527,9 +521,8 @@ TEST_F(ParserTest, conditional_block_with_not) { "{{#if (not news.has-update?)}}\n" " Stuff is happening!\n" "{{/if (not news.has-update?)}}"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- if-block \n" "| `- expression '(not news.has-update?)'\n" @@ -542,9 +535,8 @@ TEST_F(ParserTest, conditional_block_with_and_or) { "{{#if (and (or no yes) yes)}}\n" "Yes!\n" "{{/if (and (or no yes) yes)}}"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- if-block \n" "| `- expression '(and (or no yes) yes)'\n" @@ -553,11 +545,10 @@ TEST_F(ParserTest, conditional_block_with_and_or) { } TEST_F(ParserTest, conditional_block_not_wrong_arity) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#if (not news.has_updates? news.has_updates?)}}\n" " Stuff is happening!\n" "{{/if (not news.has_updates? news.has_updates?)}}"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -573,7 +564,7 @@ TEST_F(ParserTest, basic_each) { " {{.}}\n" "{{/each}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- each-block \n" "| `- expression 'news.updates'\n" @@ -590,7 +581,7 @@ TEST_F(ParserTest, basic_each_else) { " Got nothing!\n" "{{/each}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- each-block \n" "| `- expression 'news.updates'\n" @@ -608,7 +599,7 @@ TEST_F(ParserTest, each_with_element_capture) { " {{update}}\n" "{{/each}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- each-block \n" "| `- expression 'news.updates'\n" @@ -624,7 +615,7 @@ TEST_F(ParserTest, each_with_element_and_index_captures) { " {{index}}. {{update}}\n" "{{/each}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- each-block \n" "| `- expression 'news.updates'\n" @@ -649,7 +640,7 @@ TEST_F(ParserTest, each_block_nested) { " No updates!\n" "{{/each}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- each-block \n" "| `- expression 'news.updates'\n" @@ -672,8 +663,7 @@ TEST_F(ParserTest, each_block_nested) { } TEST_F(ParserTest, each_block_unclosed_with_else) { - auto ast = parse_ast("{{#each news.updates}}{{#else}}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#each news.updates}}{{#else}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -684,8 +674,7 @@ TEST_F(ParserTest, each_block_unclosed_with_else) { } TEST_F(ParserTest, each_by_itself) { - auto ast = parse_ast("{{#each}}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#each}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -696,8 +685,7 @@ TEST_F(ParserTest, each_by_itself) { } TEST_F(ParserTest, each_close_by_itself) { - auto ast = parse_ast("{{/each}}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{/each}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -708,10 +696,9 @@ TEST_F(ParserTest, each_close_by_itself) { } TEST_F(ParserTest, each_missing_captures) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#each (foo 1 2 3) as}}\n" "{{/each}}\n"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -722,10 +709,9 @@ TEST_F(ParserTest, each_missing_captures) { } TEST_F(ParserTest, each_empty_captures) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#each (foo 1 2 3) as ||}}\n" "{{/each}}\n"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -736,10 +722,9 @@ TEST_F(ParserTest, each_empty_captures) { } TEST_F(ParserTest, each_too_many_captures) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#each (foo 1 2 3) as |c1 c2 c3|}}\n" "{{/each}}\n"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -750,10 +735,9 @@ TEST_F(ParserTest, each_too_many_captures) { } TEST_F(ParserTest, each_extra_tokens_after_captures) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#each (foo 1 2 3) as |update| true}}\n" "{{/each}}\n"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -764,10 +748,9 @@ TEST_F(ParserTest, each_extra_tokens_after_captures) { } TEST_F(ParserTest, each_missing_as) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#each (foo 1 2 3) |update|}}\n" "{{/each}}\n"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -778,10 +761,9 @@ TEST_F(ParserTest, each_missing_as) { } TEST_F(ParserTest, each_missing_expr) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#each as |update|}}\n" "{{/each}}\n"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -792,10 +774,9 @@ TEST_F(ParserTest, each_missing_expr) { } TEST_F(ParserTest, each_missing_expr_and_as) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#each |name index|}}\n" "{{/each}}\n"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -806,7 +787,7 @@ TEST_F(ParserTest, each_missing_expr_and_as) { } TEST_F(ParserTest, each_multiple_else) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#each news.updates}}\n" " {{.}}\n" "{{#else}}\n" @@ -814,7 +795,6 @@ TEST_F(ParserTest, each_multiple_else) { "{{#else}}\n" " Got nothing again!\n" "{{/each}}"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -825,8 +805,7 @@ TEST_F(ParserTest, each_multiple_else) { } TEST_F(ParserTest, each_missing_close) { - auto ast = parse_ast("{{#each news.updates}}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#each news.updates}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -837,10 +816,9 @@ TEST_F(ParserTest, each_missing_close) { } TEST_F(ParserTest, each_else_missing_close) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#each news.updates}}\n" "{{#else}}"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -858,7 +836,7 @@ TEST_F(ParserTest, literals) { "{{\"hello\\tworld\"}}\n" "{{-1234}}\n"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- interpolation 'null'\n" "|- newline '\\n'\n" @@ -875,7 +853,7 @@ TEST_F(ParserTest, literals) { TEST_F(ParserTest, function_call) { auto ast = parse_ast("{{ (uppercase (lowercase hello\tspace) world) }}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- interpolation '(uppercase (lowercase hello space) world)'\n"); } @@ -883,7 +861,7 @@ TEST_F(ParserTest, function_call) { TEST_F(ParserTest, function_call_named_args) { auto ast = parse_ast(R"({{ (str.concat hello world sep=",") }})"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- interpolation '(str.concat hello world sep=\",\")'\n"); } @@ -891,15 +869,14 @@ TEST_F(ParserTest, function_call_named_args) { TEST_F(ParserTest, function_call_named_args_only) { auto ast = parse_ast("{{ (str.concat sep = comma) }}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- interpolation '(str.concat sep=comma)'\n"); } TEST_F(ParserTest, function_call_named_args_duplicate) { - auto ast = - parse_ast("{{ (str.concat hello world sep=comma foo=bar sep=baz) }}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail( + "{{ (str.concat hello world sep=comma foo=bar sep=baz) }}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -910,9 +887,8 @@ TEST_F(ParserTest, function_call_named_args_duplicate) { } TEST_F(ParserTest, function_call_named_args_without_lookup) { - auto ast = parse_ast(R"({{ (sep=",") }})"); + parse_ast_should_fail(R"({{ (sep=",") }})"); // `sep` is parsed as the name - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -923,8 +899,7 @@ TEST_F(ParserTest, function_call_named_args_without_lookup) { } TEST_F(ParserTest, function_call_positional_args_after_named_args) { - auto ast = parse_ast(R"({{ (str.concat sep="," hello world) }})"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail(R"({{ (str.concat sep="," hello world) }})"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -935,8 +910,7 @@ TEST_F(ParserTest, function_call_positional_args_after_named_args) { } TEST_F(ParserTest, function_call_named_args_not_identifier) { - auto ast = parse_ast("{{ (str.concat hello world word.sep=comma) }}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{ (str.concat hello world word.sep=comma) }}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -948,8 +922,7 @@ TEST_F(ParserTest, function_call_named_args_not_identifier) { TEST_F(ParserTest, function_call_named_args_for_builtins) { { - auto ast = parse_ast("{{ (not foo ignore=1234) }}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{ (not foo ignore=1234) }}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -959,8 +932,7 @@ TEST_F(ParserTest, function_call_named_args_for_builtins) { 1))); } { - auto ast = parse_ast("{{ (and foo bar ignore=1234) }}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{ (and foo bar ignore=1234) }}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -970,8 +942,7 @@ TEST_F(ParserTest, function_call_named_args_for_builtins) { 1))); } { - auto ast = parse_ast("{{ (or foo bar ignore=1234) }}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{ (or foo bar ignore=1234) }}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -987,9 +958,8 @@ TEST_F(ParserTest, partial_block_basic) { "{{#let partial foo |arg1 arg2|}}\n" "This is a partial block!\n" "{{/let partial}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- partial-block 'foo'\n" "| `- argument 'arg1'\n" @@ -1003,9 +973,8 @@ TEST_F(ParserTest, partial_block_with_captures) { "{{#let partial foo |arg1 arg2| captures |cap1 cap2|}}\n" "This is a partial block!\n" "{{/let partial}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- partial-block 'foo'\n" "| `- argument 'arg1'\n" @@ -1021,9 +990,8 @@ TEST_F(ParserTest, partial_block_only_captures) { "{{#let partial foo captures |cap1 cap2|}}\n" "This is a partial block!\n" "{{/let partial}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- partial-block 'foo'\n" "| `- capture 'cap1'\n" @@ -1034,9 +1002,8 @@ TEST_F(ParserTest, partial_block_only_captures) { TEST_F(ParserTest, partial_block_after_comment) { auto ast = parse_ast("{{!}}{{#let partial foo |arg|}}{{/let partial}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- comment ''\n" "|- partial-block 'foo'\n" @@ -1054,9 +1021,8 @@ TEST_F(ParserTest, partial_block_consume_whitespace) { " inside partial\n" "{{/let partial}}\n" "hello\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- newline '\\n'\n" "|- comment ''\n" @@ -1071,16 +1037,14 @@ TEST_F(ParserTest, partial_block_consume_whitespace) { TEST_F(ParserTest, partial_block_no_arguments) { auto ast = parse_ast("{{#let partial foo}}{{/let partial}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- partial-block 'foo'\n"); } TEST_F(ParserTest, partial_block_empty_arguments) { - auto ast = parse_ast("{{#let partial foo ||}}{{/let partial}}\n"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#let partial foo ||}}{{/let partial}}\n"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1091,8 +1055,7 @@ TEST_F(ParserTest, partial_block_empty_arguments) { } TEST_F(ParserTest, partial_block_duplicate_arguments) { - auto ast = parse_ast("{{#let partial foo |arg arg|}}{{/let partial}}\n"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#let partial foo |arg arg|}}{{/let partial}}\n"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1103,9 +1066,8 @@ TEST_F(ParserTest, partial_block_duplicate_arguments) { } TEST_F(ParserTest, partial_block_empty_captures) { - auto ast = - parse_ast("{{#let partial foo |arg| captures ||}}{{/let partial}}\n"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail( + "{{#let partial foo |arg| captures ||}}{{/let partial}}\n"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1116,9 +1078,8 @@ TEST_F(ParserTest, partial_block_empty_captures) { } TEST_F(ParserTest, partial_block_duplicate_captures) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#let partial foo |arg| captures |cap cap|}}{{/let partial}}\n"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1129,9 +1090,8 @@ TEST_F(ParserTest, partial_block_duplicate_captures) { } TEST_F(ParserTest, partial_block_duplicate_argument_with_capture) { - auto ast = - parse_ast("{{#let partial foo |arg| captures |arg|}}{{/let partial}}\n"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail( + "{{#let partial foo |arg| captures |arg|}}{{/let partial}}\n"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1142,8 +1102,7 @@ TEST_F(ParserTest, partial_block_duplicate_argument_with_capture) { } TEST_F(ParserTest, partial_block_missing_name) { - auto ast = parse_ast("{{#let partial |arg1|}}{{/let partial}}\n"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#let partial |arg1|}}{{/let partial}}\n"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1154,8 +1113,7 @@ TEST_F(ParserTest, partial_block_missing_name) { } TEST_F(ParserTest, partial_block_extra_tokens) { - auto ast = parse_ast("{{#let partial foo |arg1| true}}{{/let partial}}\n"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#let partial foo |arg1| true}}{{/let partial}}\n"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1166,8 +1124,7 @@ TEST_F(ParserTest, partial_block_extra_tokens) { } TEST_F(ParserTest, partial_block_without_close) { - auto ast = parse_ast("{{#let partial foo |arg1|}}\n"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#let partial foo |arg1|}}\n"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1178,8 +1135,7 @@ TEST_F(ParserTest, partial_block_without_close) { } TEST_F(ParserTest, partial_block_with_bad_close) { - auto ast = parse_ast("{{#let partial foo |arg1|}}{{/let}}\n"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#let partial foo |arg1|}}{{/let}}\n"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1195,9 +1151,8 @@ TEST_F(ParserTest, partial_block_nested) { " {{#let partial bar |arg3 arg4|}}\n" " {{/let partial}}\n" "{{/let partial}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- partial-block 'foo'\n" "| `- argument 'arg1'\n" @@ -1218,9 +1173,8 @@ TEST_F(ParserTest, partial_block_inside_body) { "Some body text\n" "{{#let partial bar |arg1 arg2|}}{{/let partial}}\n" "{{#let partial baz |arg1 arg2|}}{{/let partial}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- comment ' header '\n" "|- partial-block 'foo'\n" @@ -1244,9 +1198,8 @@ TEST_F(ParserTest, partial_block_inside_body) { TEST_F(ParserTest, partial_statement_basic) { auto ast = parse_ast("{{#partial foo}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- partial-statement 'foo'\n" "| `- standalone-indentation ''\n"); @@ -1254,9 +1207,8 @@ TEST_F(ParserTest, partial_statement_basic) { TEST_F(ParserTest, partial_statement_with_args) { auto ast = parse_ast("{{#partial foo bar=1234}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- partial-statement 'foo'\n" "| `- standalone-indentation ''\n" @@ -1266,9 +1218,8 @@ TEST_F(ParserTest, partial_statement_with_args) { TEST_F(ParserTest, partial_statement_expression) { auto ast = parse_ast("{{#partial (fetch-partial \"foo\" bar=1234) arg1=true}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- partial-statement '(fetch-partial \"foo\" bar=1234)'\n" "| `- standalone-indentation ''\n" @@ -1276,8 +1227,7 @@ TEST_F(ParserTest, partial_statement_expression) { } TEST_F(ParserTest, partial_statement_empty) { - auto ast = parse_ast("{{#partial}}\n"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#partial}}\n"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1288,9 +1238,8 @@ TEST_F(ParserTest, partial_statement_empty) { } TEST_F(ParserTest, partial_statement_missing_name) { - auto ast = - parse_ast("{{#partial arg1=(some-expression 1 2 3 4) arg2=true}}\n"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail( + "{{#partial arg1=(some-expression 1 2 3 4) arg2=true}}\n"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1301,8 +1250,7 @@ TEST_F(ParserTest, partial_statement_missing_name) { } TEST_F(ParserTest, partial_statement_argument_without_name) { - auto ast = parse_ast("{{#partial foo (some-expression 1 2 3 4)}}\n"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{#partial foo (some-expression 1 2 3 4)}}\n"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1313,7 +1261,7 @@ TEST_F(ParserTest, partial_statement_argument_without_name) { } TEST_F(ParserTest, partial_statement_missing_close) { - auto ast = parse_ast("{{#partial foo arg1=true"); + parse_ast_should_fail("{{#partial foo arg1=true"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1325,9 +1273,8 @@ TEST_F(ParserTest, partial_statement_missing_close) { TEST_F(ParserTest, partial_statement_standalone) { auto ast = parse_ast(" \t {{#partial foo arg1=true}} \t \n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text ' \\t '\n" "|- partial-statement 'foo'\n" @@ -1338,9 +1285,8 @@ TEST_F(ParserTest, partial_statement_standalone) { TEST_F(ParserTest, partial_statement_not_standalone) { { auto ast = parse_ast(" \t {{#partial foo arg1=true}} \t {{> foo}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text ' \\t '\n" "|- partial-statement 'foo'\n" @@ -1353,9 +1299,8 @@ TEST_F(ParserTest, partial_statement_not_standalone) { { auto ast = parse_ast( "{{#if true}} \t {{#partial foo arg1=true}} \t {{/if true}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-2.whisker]\n" "|- if-block \n" "| `- expression 'true'\n" @@ -1370,7 +1315,7 @@ TEST_F(ParserTest, partial_statement_not_standalone) { TEST_F(ParserTest, basic_macro) { auto ast = parse_ast("{{> path / to / file }}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- macro 'path/to/file'\n" "| `- standalone-indentation ''\n"); @@ -1379,7 +1324,7 @@ TEST_F(ParserTest, basic_macro) { TEST_F(ParserTest, macro_single_id) { auto ast = parse_ast("{{> foo }}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- macro 'foo'\n" "| `- standalone-indentation ''\n"); @@ -1391,7 +1336,7 @@ TEST_F(ParserTest, macro_in_section) { " {{> print/news}}\n" "{{/news.has-update?}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- section-block \n" "| `- variable-lookup 'news.has-update?'\n" @@ -1403,7 +1348,7 @@ TEST_F(ParserTest, macro_in_section) { TEST_F(ParserTest, macro_preserves_whitespace_indentation) { auto ast = parse_ast(" \t {{> print/news}}\n"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text ' \\t '\n" "|- macro 'print/news'\n" @@ -1411,8 +1356,7 @@ TEST_F(ParserTest, macro_preserves_whitespace_indentation) { } TEST_F(ParserTest, macro_no_id) { - auto ast = parse_ast("{{> }}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{> }}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1423,8 +1367,7 @@ TEST_F(ParserTest, macro_no_id) { } TEST_F(ParserTest, macro_extra_stuff) { - auto ast = parse_ast("{{> foo ! }}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{> foo ! }}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1437,15 +1380,14 @@ TEST_F(ParserTest, macro_extra_stuff) { TEST_F(ParserTest, macro_dotted_path) { auto ast = parse_ast("{{> path/to.file }}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- macro 'path/to.file'\n" "| `- standalone-indentation ''\n"); } TEST_F(ParserTest, macro_empty_path_part) { - auto ast = parse_ast("{{> path//to.file }}"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{> path//to.file }}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1456,8 +1398,7 @@ TEST_F(ParserTest, macro_empty_path_part) { } TEST_F(ParserTest, unclosed_macro) { - auto ast = parse_ast("{{> path/to/file"); - EXPECT_FALSE(ast.has_value()); + parse_ast_should_fail("{{> path/to/file"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1470,7 +1411,7 @@ TEST_F(ParserTest, unclosed_macro) { TEST_F(ParserTest, let_statement) { auto ast = parse_ast("{{#let foo = (not true_value)}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- let-statement \n" "| `- identifier 'foo'\n" @@ -1480,7 +1421,7 @@ TEST_F(ParserTest, let_statement) { TEST_F(ParserTest, let_statement_with_implicit_context) { auto ast = parse_ast("{{#let foo = (a.b.c this)}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- let-statement \n" "| `- identifier 'foo'\n" @@ -1488,7 +1429,7 @@ TEST_F(ParserTest, let_statement_with_implicit_context) { } TEST_F(ParserTest, let_statement_dotted_name) { - auto ast = parse_ast("{{#let foo.bar = (not true_value)}}"); + parse_ast_should_fail("{{#let foo.bar = (not true_value)}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1499,7 +1440,7 @@ TEST_F(ParserTest, let_statement_dotted_name) { } TEST_F(ParserTest, let_statement_missing_id) { - auto ast = parse_ast("{{#let (not true_value)}}"); + parse_ast_should_fail("{{#let (not true_value)}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1510,7 +1451,7 @@ TEST_F(ParserTest, let_statement_missing_id) { } TEST_F(ParserTest, let_statement_missing_eq) { - auto ast = parse_ast("{{#let foo (not true_value)}}"); + parse_ast_should_fail("{{#let foo (not true_value)}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1521,7 +1462,7 @@ TEST_F(ParserTest, let_statement_missing_eq) { } TEST_F(ParserTest, let_statement_missing_expression) { - auto ast = parse_ast("{{#let foo =}}"); + parse_ast_should_fail("{{#let foo =}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1532,7 +1473,7 @@ TEST_F(ParserTest, let_statement_missing_expression) { } TEST_F(ParserTest, let_statement_missing_eq_and_expression) { - auto ast = parse_ast("{{#let foo}}"); + parse_ast_should_fail("{{#let foo}}"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1543,7 +1484,7 @@ TEST_F(ParserTest, let_statement_missing_eq_and_expression) { } TEST_F(ParserTest, let_statement_missing_close) { - auto ast = parse_ast("{{#let foo = (not true_value)"); + parse_ast_should_fail("{{#let foo = (not true_value)"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1554,7 +1495,7 @@ TEST_F(ParserTest, let_statement_missing_close) { } TEST_F(ParserTest, let_statement_keyword) { - auto ast = parse_ast("{{#let let = (not true_value)"); + parse_ast_should_fail("{{#let let = (not true_value)"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1566,15 +1507,14 @@ TEST_F(ParserTest, let_statement_keyword) { TEST_F(ParserTest, pragma_ignore_newlines) { auto ast = parse_ast("{{#pragma ignore-newlines}}\n"); - EXPECT_THAT(diagnostics, testing::IsEmpty()); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- pragma-statement 'ignore-newlines' \n"); } TEST_F(ParserTest, pragma_unrecognized) { - auto ast = parse_ast("{{#pragma unrecognized}}\n"); + parse_ast_should_fail("{{#pragma unrecognized}}\n"); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1590,7 +1530,7 @@ TEST_F(ParserTest, with_block) { "{{bar}}\n" "{{/with}}\n"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- with-block \n" "| `- expression 'foo.bar'\n" @@ -1599,11 +1539,10 @@ TEST_F(ParserTest, with_block) { } TEST_F(ParserTest, with_block_no_expression) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#with}}\n" "{{bar}}\n" "{{/with}}\n"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1614,11 +1553,10 @@ TEST_F(ParserTest, with_block_no_expression) { } TEST_F(ParserTest, with_block_multiple_expression) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#with foo.bar bar.baz}}\n" "{{bar}}\n" "{{/with}}\n"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1629,10 +1567,9 @@ TEST_F(ParserTest, with_block_multiple_expression) { } TEST_F(ParserTest, with_block_missing_close) { - auto ast = parse_ast( + parse_ast_should_fail( "{{#with foo.bar}}\n" "{{bar}}\n"); - EXPECT_FALSE(ast.has_value()); EXPECT_THAT( diagnostics, testing::ElementsAre(diagnostic( @@ -1644,9 +1581,8 @@ TEST_F(ParserTest, with_block_missing_close) { TEST_F(ParserTest, comment) { auto ast = parse_ast("Hello{{! #$^& random text }}world"); - EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text 'Hello'\n" "|- comment ' #$^& random text '\n" @@ -1656,7 +1592,7 @@ TEST_F(ParserTest, comment) { TEST_F(ParserTest, comment_empty) { auto ast = parse_ast("{{!}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- comment ''\n"); } @@ -1666,7 +1602,7 @@ TEST_F(ParserTest, comment_escaped) { "Hello{{!-- \n" "next line }} still comment --}}world"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text 'Hello'\n" "|- comment ' \\nnext line }} still comment '\n" @@ -1676,7 +1612,7 @@ TEST_F(ParserTest, comment_escaped) { TEST_F(ParserTest, comment_escaped_empty) { auto ast = parse_ast("{{!----}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- comment ''\n"); } @@ -1689,7 +1625,7 @@ TEST_F(ParserTest, strip_standalone_lines) { "{{/boolean}}\n" "| A Line\n"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text '| This Is'\n" "|- newline '\\n'\n" @@ -1709,7 +1645,7 @@ TEST_F(ParserTest, strip_standalone_lines_indented) { " {{/boolean}}\n" "| A Line\n"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text '| This Is'\n" "|- newline '\\n'\n" @@ -1728,7 +1664,7 @@ TEST_F(ParserTest, strip_standalone_lines_indented_at_eof) { "|\n" " {{/boolean}} "); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text '| This Is'\n" "|- newline '\\n'\n" @@ -1746,7 +1682,7 @@ TEST_F( "|\n" " {{/boolean}}"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text '| This Is'\n" "|- newline '\\n'\n" @@ -1765,7 +1701,7 @@ TEST_F(ParserTest, strip_standalone_lines_multiple) { " {{/boolean}}\n" "| A Line\n"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text '| This Is'\n" "|- newline '\\n'\n" @@ -1788,7 +1724,7 @@ TEST_F(ParserTest, strip_standalone_lines_multiline) { " {{/boolean.condition}}\n" "| A Line\n"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text '| This Is'\n" "|- newline '\\n'\n" @@ -1809,7 +1745,7 @@ TEST_F(ParserTest, strip_standalone_lines_multiline_comment) { " {{/boolean.condition}}\n" "| A Line\n"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text '| This Is'\n" "|- newline '\\n'\n" @@ -1831,7 +1767,7 @@ TEST_F(ParserTest, strip_standalone_lines_multiline_ineligible) { " {{/boolean.condition}}\n" "| A Line\n"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text '| This Is'\n" "|- newline '\\n'\n" @@ -1859,7 +1795,7 @@ TEST_F( " {{/boolean.condition}}\n" "| A Line\n"); EXPECT_EQ( - to_string(*ast), + to_string(ast), "root [path/to/test-1.whisker]\n" "|- text '| This Is'\n" "|- newline '\\n'\n"