From 991dadcbedf67ea06d58a75dc4be7c47f7314267 Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Mon, 5 Dec 2022 08:30:53 -0800 Subject: [PATCH] Move parse tree tests to files. (#2437) I think it'd be helpful to examine what the parse tree looks like in failure cases. Note, I'm not sure that the behavior of the recovery situations is correct; the test had been asserting that the parse tree should indicate it's error free. However, this means that the only signal the the driver that the input is invalid is that the diagnostic emitter was used. I think it may be important to have it return a non-zero error to prevent compile, or we can turn these into warnings but then "requiring a space" is wrong. Either way, that's a concern I have with the pre-existing recovery behavior: I'm just trying to highlight it as I make this change, because now the test is really that nodes aren't tagged with has_error. --- toolchain/parser/parse_tree_test.cpp | 129 ------------------ .../parser/testdata/basics/package.carbon | 35 ----- .../fail_infix_uneven_space_after.carbon | 22 +++ ...r.carbon => fail_precedence_and_or.carbon} | 2 +- ...d.carbon => fail_precedence_or_and.carbon} | 2 +- .../fail_precedence_star_minus.carbon | 22 +++ .../fail_precedence_star_star.carbon | 22 +++ .../operators/fail_star_star_no_space.carbon | 25 ++++ .../parser/testdata/operators/infix.carbon | 20 +++ .../testdata/operators/infix_no_space.carbon | 20 +++ .../operators/infix_with_paren_after.carbon | 22 +++ .../operators/infix_with_paren_before.carbon | 22 +++ .../parser/testdata/operators/postfix.carbon | 19 +++ ...fix_unary.carbon => postfix_repeat.carbon} | 0 .../operators/postfix_space_after_op.carbon | 19 +++ .../parser/testdata/operators/prefix.carbon | 19 +++ .../testdata/operators/prefix_no_space.carbon | 20 +++ ...efix_unary.carbon => prefix_repeat.carbon} | 0 .../recover_infix_uneven_space_before.carbon | 21 +++ .../operators/recover_postfix_space.carbon | 20 +++ .../recover_postfix_space_before_comma.carbon | 25 ++++ .../recover_postfix_space_in_call.carbon | 23 ++++ .../recover_postfix_space_surrounding.carbon | 21 +++ .../operators/recover_prefix_space.carbon | 21 +++ ...ver_prefix_uneven_space_with_assign.carbon | 20 +++ toolchain/parser/testdata/package/api.carbon | 15 ++ .../testdata/package/api_library.carbon | 17 +++ .../testdata/package/fail_extra_string.carbon | 17 +++ .../package/fail_library_is_identifier.carbon | 15 ++ .../package/fail_library_skips_name.carbon | 14 ++ .../package/fail_name_is_keyword.carbon | 14 ++ .../testdata/package/fail_no_name.carbon | 14 ++ .../testdata/package/fail_no_semi.carbon | 16 +++ .../testdata/package/fail_no_type.carbon | 15 ++ .../package/fail_omit_library_keyword.carbon | 15 ++ toolchain/parser/testdata/package/impl.carbon | 15 ++ .../testdata/package/impl_library.carbon | 17 +++ .../testdata/struct/fail_comma_only.carbon | 23 ++++ .../struct/fail_comma_repeat_in_type.carbon | 28 ++++ .../struct/fail_comma_repeat_in_value.carbon | 28 ++++ .../testdata/struct/fail_dot_only.carbon | 24 ++++ .../struct/fail_dot_string_colon.carbon | 30 ++++ .../struct/fail_dot_string_equals.carbon | 30 ++++ .../struct/fail_extra_token_in_type.carbon | 29 ++++ .../struct/fail_extra_token_in_value.carbon | 29 ++++ .../struct/fail_identifier_colon.carbon | 22 +++ .../struct/fail_identifier_equals.carbon | 22 +++ .../struct/fail_identifier_only.carbon | 22 +++ .../testdata/struct/fail_missing_type.carbon | 24 ++++ .../testdata/struct/fail_missing_value.carbon | 24 ++++ .../struct/fail_mix_type_and_value.carbon | 29 ++++ .../struct/fail_mix_value_and_type.carbon | 27 ++++ .../struct/fail_no_colon_or_equals.carbon | 24 ++++ .../struct/fail_type_no_designator.carbon | 22 +++ .../parser/testdata/struct/no_entries.carbon | 20 +++ .../testdata/struct/one_entry_no_comma.carbon | 28 ++++ .../struct/one_entry_with_comma.carbon | 30 ++++ .../two_entries.carbon} | 31 ----- .../tuples.carbon => tuple/nested.carbon} | 17 --- .../parser/testdata/tuple/two_entries.carbon | 26 ++++ 60 files changed, 1130 insertions(+), 214 deletions(-) delete mode 100644 toolchain/parser/testdata/basics/package.carbon create mode 100644 toolchain/parser/testdata/operators/fail_infix_uneven_space_after.carbon rename toolchain/parser/testdata/operators/{fail_missing_precedence_and_or.carbon => fail_precedence_and_or.carbon} (91%) rename toolchain/parser/testdata/operators/{fail_missing_precedence_or_and.carbon => fail_precedence_or_and.carbon} (91%) create mode 100644 toolchain/parser/testdata/operators/fail_precedence_star_minus.carbon create mode 100644 toolchain/parser/testdata/operators/fail_precedence_star_star.carbon create mode 100644 toolchain/parser/testdata/operators/fail_star_star_no_space.carbon create mode 100644 toolchain/parser/testdata/operators/infix.carbon create mode 100644 toolchain/parser/testdata/operators/infix_no_space.carbon create mode 100644 toolchain/parser/testdata/operators/infix_with_paren_after.carbon create mode 100644 toolchain/parser/testdata/operators/infix_with_paren_before.carbon create mode 100644 toolchain/parser/testdata/operators/postfix.carbon rename toolchain/parser/testdata/operators/{postfix_unary.carbon => postfix_repeat.carbon} (100%) create mode 100644 toolchain/parser/testdata/operators/postfix_space_after_op.carbon create mode 100644 toolchain/parser/testdata/operators/prefix.carbon create mode 100644 toolchain/parser/testdata/operators/prefix_no_space.carbon rename toolchain/parser/testdata/operators/{prefix_unary.carbon => prefix_repeat.carbon} (100%) create mode 100644 toolchain/parser/testdata/operators/recover_infix_uneven_space_before.carbon create mode 100644 toolchain/parser/testdata/operators/recover_postfix_space.carbon create mode 100644 toolchain/parser/testdata/operators/recover_postfix_space_before_comma.carbon create mode 100644 toolchain/parser/testdata/operators/recover_postfix_space_in_call.carbon create mode 100644 toolchain/parser/testdata/operators/recover_postfix_space_surrounding.carbon create mode 100644 toolchain/parser/testdata/operators/recover_prefix_space.carbon create mode 100644 toolchain/parser/testdata/operators/recover_prefix_uneven_space_with_assign.carbon create mode 100644 toolchain/parser/testdata/package/api.carbon create mode 100644 toolchain/parser/testdata/package/api_library.carbon create mode 100644 toolchain/parser/testdata/package/fail_extra_string.carbon create mode 100644 toolchain/parser/testdata/package/fail_library_is_identifier.carbon create mode 100644 toolchain/parser/testdata/package/fail_library_skips_name.carbon create mode 100644 toolchain/parser/testdata/package/fail_name_is_keyword.carbon create mode 100644 toolchain/parser/testdata/package/fail_no_name.carbon create mode 100644 toolchain/parser/testdata/package/fail_no_semi.carbon create mode 100644 toolchain/parser/testdata/package/fail_no_type.carbon create mode 100644 toolchain/parser/testdata/package/fail_omit_library_keyword.carbon create mode 100644 toolchain/parser/testdata/package/impl.carbon create mode 100644 toolchain/parser/testdata/package/impl_library.carbon create mode 100644 toolchain/parser/testdata/struct/fail_comma_only.carbon create mode 100644 toolchain/parser/testdata/struct/fail_comma_repeat_in_type.carbon create mode 100644 toolchain/parser/testdata/struct/fail_comma_repeat_in_value.carbon create mode 100644 toolchain/parser/testdata/struct/fail_dot_only.carbon create mode 100644 toolchain/parser/testdata/struct/fail_dot_string_colon.carbon create mode 100644 toolchain/parser/testdata/struct/fail_dot_string_equals.carbon create mode 100644 toolchain/parser/testdata/struct/fail_extra_token_in_type.carbon create mode 100644 toolchain/parser/testdata/struct/fail_extra_token_in_value.carbon create mode 100644 toolchain/parser/testdata/struct/fail_identifier_colon.carbon create mode 100644 toolchain/parser/testdata/struct/fail_identifier_equals.carbon create mode 100644 toolchain/parser/testdata/struct/fail_identifier_only.carbon create mode 100644 toolchain/parser/testdata/struct/fail_missing_type.carbon create mode 100644 toolchain/parser/testdata/struct/fail_missing_value.carbon create mode 100644 toolchain/parser/testdata/struct/fail_mix_type_and_value.carbon create mode 100644 toolchain/parser/testdata/struct/fail_mix_value_and_type.carbon create mode 100644 toolchain/parser/testdata/struct/fail_no_colon_or_equals.carbon create mode 100644 toolchain/parser/testdata/struct/fail_type_no_designator.carbon create mode 100644 toolchain/parser/testdata/struct/no_entries.carbon create mode 100644 toolchain/parser/testdata/struct/one_entry_no_comma.carbon create mode 100644 toolchain/parser/testdata/struct/one_entry_with_comma.carbon rename toolchain/parser/testdata/{basics/structs.carbon => struct/two_entries.carbon} (51%) rename toolchain/parser/testdata/{basics/tuples.carbon => tuple/nested.carbon} (55%) create mode 100644 toolchain/parser/testdata/tuple/two_entries.carbon diff --git a/toolchain/parser/parse_tree_test.cpp b/toolchain/parser/parse_tree_test.cpp index 5a82d5830e45..9ea023660755 100644 --- a/toolchain/parser/parse_tree_test.cpp +++ b/toolchain/parser/parse_tree_test.cpp @@ -52,102 +52,6 @@ TEST_F(ParseTreeTest, IsValid) { EXPECT_TRUE((*tree.postorder().begin()).is_valid()); } -TEST_F(ParseTreeTest, OperatorWhitespaceErrors) { - // Test dispositions: Recovered means we issued an error but recovered a - // proper parse tree; Failed means we didn't fully recover from the error. - enum Kind { Valid, Recovered, Failed }; - - struct Testcase { - const char* input; - Kind kind; - } testcases[] = { - {"var v: Type = i8*;", Valid}, - {"var v: Type = i8 *;", Recovered}, - {"var v: Type = i8* ;", Valid}, - {"var v: Type = i8 * ;", Recovered}, - {"var n: i8 = n * n;", Valid}, - {"var n: i8 = n*n;", Valid}, - {"var n: i8 = (n)*3;", Valid}, - {"var n: i8 = 3*(n);", Valid}, - {"var n: i8 = n *n;", Recovered}, - // TODO: We could figure out that this first Failed example is infix - // with one-token lookahead. - {"var n: i8 = n* n;", Failed}, - {"var n: i8 = n* -n;", Failed}, - {"var n: i8 = n* *p;", Failed}, - // TODO: We try to form (n*)*p and reject due to missing parentheses - // before we notice the missing whitespace around the second `*`. - // It'd be better to (somehow) form n*(*p) and reject due to the missing - // whitespace around the first `*`. - {"var n: i8 = n**p;", Failed}, - {"var n: i8 = -n;", Valid}, - {"var n: i8 = - n;", Recovered}, - {"var n: i8 =-n;", Valid}, - {"var n: i8 =- n;", Recovered}, - {"var n: i8 = F(i8 *);", Recovered}, - {"var n: i8 = F(i8 *, 0);", Recovered}, - }; - - for (auto [input, kind] : testcases) { - TokenizedBuffer tokens = GetTokenizedBuffer(input); - ErrorTrackingDiagnosticConsumer error_tracker(consumer); - ParseTree tree = - ParseTree::Parse(tokens, error_tracker, /*vlog_stream=*/nullptr); - EXPECT_THAT(tree.has_errors(), Eq(kind == Failed)) << input; - EXPECT_THAT(error_tracker.seen_error(), Eq(kind != Valid)) << input; - } -} - -TEST_F(ParseTreeTest, StructErrors) { - struct Testcase { - llvm::StringLiteral input; - ::testing::Matcher diag_matcher; - }; - Testcase testcases[] = { - {"var x: {i32} = {};", - IsDiagnosticMessage("Expected `.field: type` or `.field = value`.")}, - {"var x: {a} = {};", - IsDiagnosticMessage("Expected `.field: type` or `.field = value`.")}, - {"var x: {a:} = {};", - IsDiagnosticMessage("Expected `.field: type` or `.field = value`.")}, - {"var x: {a=} = {};", - IsDiagnosticMessage("Expected `.field: type` or `.field = value`.")}, - {"var x: {.} = {};", - IsDiagnosticMessage("Expected identifier after `.`.")}, - {"var x: {.\"hello\" = 0, .y = 4} = {};", - IsDiagnosticMessage("Expected identifier after `.`.")}, - {"var x: {.\"hello\": i32, .y: i32} = {};", - IsDiagnosticMessage("Expected identifier after `.`.")}, - {"var x: {.a} = {};", - IsDiagnosticMessage("Expected `.field: type` or `.field = value`.")}, - {"var x: {.a:} = {};", IsDiagnosticMessage("Expected expression.")}, - {"var x: {.a=} = {};", IsDiagnosticMessage("Expected expression.")}, - {"var x: {.a: i32, .b = 0} = {};", - IsDiagnosticMessage("Expected `.field: type`.")}, - {"var x: {.a = 0, b: i32} = {};", - IsDiagnosticMessage("Expected `.field = value`.")}, - {"var x: {,} = {};", - IsDiagnosticMessage("Expected `.field: type` or `.field = value`.")}, - {"var x: {.a: i32,,} = {};", - IsDiagnosticMessage("Expected `.field: type`.")}, - {"var x: {.a = 0,,} = {};", - IsDiagnosticMessage("Expected `.field = value`.")}, - {"var x: {.a: i32 banana} = {.a = 0};", - IsDiagnosticMessage("Expected `,` or `}`.")}, - {"var x: {.a: i32} = {.a = 0 banana};", - IsDiagnosticMessage("Expected `,` or `}`.")}, - }; - - for (const Testcase& testcase : testcases) { - TokenizedBuffer tokens = GetTokenizedBuffer(testcase.input); - Testing::MockDiagnosticConsumer consumer; - EXPECT_CALL(consumer, HandleDiagnostic(testcase.diag_matcher)); - ParseTree tree = - ParseTree::Parse(tokens, consumer, /*vlog_stream=*/nullptr); - EXPECT_TRUE(tree.has_errors()); - } -} - TEST_F(ParseTreeTest, PrintPostorderAsYAML) { TokenizedBuffer tokens = GetTokenizedBuffer("fn F();"); ParseTree tree = ParseTree::Parse(tokens, consumer, /*vlog_stream=*/nullptr); @@ -223,38 +127,5 @@ TEST_F(ParseTreeTest, HighRecursion) { EXPECT_FALSE(tree.has_errors()); } -TEST_F(ParseTreeTest, PackageErrors) { - struct TestCase { - llvm::StringLiteral input; - ::testing::Matcher diag_matcher; - }; - - TestCase testcases[] = { - {"package;", IsDiagnosticMessage("Expected identifier after `package`.")}, - {"package fn;", - IsDiagnosticMessage("Expected identifier after `package`.")}, - {"package library \"Shapes\" api;", - IsDiagnosticMessage("Expected identifier after `package`.")}, - {"package Geometry library Shapes api;", - IsDiagnosticMessage( - "Expected a string literal to specify the library name.")}, - {"package Geometry \"Shapes\" api;", - IsDiagnosticMessage("Missing `library` keyword.")}, - {"package Geometry api", - IsDiagnosticMessage("Expected `;` to end package directive.")}, - {"package Geometry;", IsDiagnosticMessage("Expected a `api` or `impl`.")}, - {R"(package Foo library "bar" "baz";)", - IsDiagnosticMessage("Expected a `api` or `impl`.")}}; - - for (const TestCase& testcase : testcases) { - TokenizedBuffer tokens = GetTokenizedBuffer(testcase.input); - Testing::MockDiagnosticConsumer consumer; - EXPECT_CALL(consumer, HandleDiagnostic(testcase.diag_matcher)); - ParseTree tree = - ParseTree::Parse(tokens, consumer, /*vlog_stream=*/nullptr); - EXPECT_TRUE(tree.has_errors()); - } -} - } // namespace } // namespace Carbon::Testing diff --git a/toolchain/parser/testdata/basics/package.carbon b/toolchain/parser/testdata/basics/package.carbon deleted file mode 100644 index 7a0d52c80028..000000000000 --- a/toolchain/parser/testdata/basics/package.carbon +++ /dev/null @@ -1,35 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{carbon-run-parser} -// CHECK:STDOUT: [ -// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, -// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Geometry'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', subtree_size: 4}, -// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, -// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Geometry'}, -// CHECK:STDOUT: {kind: 'PackageImpl', text: 'impl'}, -// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', subtree_size: 4}, -// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, -// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Geometry'}, -// CHECK:STDOUT: {kind: 'Literal', text: '"Shapes"'}, -// CHECK:STDOUT: {kind: 'PackageLibrary', text: 'library', subtree_size: 2}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', subtree_size: 6}, -// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, -// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Geometry'}, -// CHECK:STDOUT: {kind: 'Literal', text: '"Shapes"'}, -// CHECK:STDOUT: {kind: 'PackageLibrary', text: 'library', subtree_size: 2}, -// CHECK:STDOUT: {kind: 'PackageImpl', text: 'impl'}, -// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', subtree_size: 6}, -// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, -// CHECK:STDOUT: ] - -// NOTE: Move to its own directory when more tests are added. -package Geometry api; -package Geometry impl; -package Geometry library "Shapes" api; -package Geometry library "Shapes" impl; diff --git a/toolchain/parser/testdata/operators/fail_infix_uneven_space_after.carbon b/toolchain/parser/testdata/operators/fail_infix_uneven_space_after.carbon new file mode 100644 index 000000000000..c146b0878ea4 --- /dev/null +++ b/toolchain/parser/testdata/operators/fail_infix_uneven_space_after.carbon @@ -0,0 +1,22 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'PostfixOperator', text: '*', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', has_error: yes, subtree_size: 8}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// TODO: We could figure out that this first Failed example is infix +// with one-token lookahead. +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/fail_infix_uneven_space_after.carbon:[[@LINE+1]]:16: Expected `;` after expression. +var n: i8 = n* n; diff --git a/toolchain/parser/testdata/operators/fail_missing_precedence_and_or.carbon b/toolchain/parser/testdata/operators/fail_precedence_and_or.carbon similarity index 91% rename from toolchain/parser/testdata/operators/fail_missing_precedence_and_or.carbon rename to toolchain/parser/testdata/operators/fail_precedence_and_or.carbon index 569ddb7d06ec..4bd3dc66054d 100644 --- a/toolchain/parser/testdata/operators/fail_missing_precedence_and_or.carbon +++ b/toolchain/parser/testdata/operators/fail_precedence_and_or.carbon @@ -21,6 +21,6 @@ // CHECK:STDOUT: ] fn F() { - // CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/fail_missing_precedence_and_or.carbon:[[@LINE+1]]:11: Parentheses are required to disambiguate operator precedence. + // CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/fail_precedence_and_or.carbon:[[@LINE+1]]:11: Parentheses are required to disambiguate operator precedence. a and b or c; } diff --git a/toolchain/parser/testdata/operators/fail_missing_precedence_or_and.carbon b/toolchain/parser/testdata/operators/fail_precedence_or_and.carbon similarity index 91% rename from toolchain/parser/testdata/operators/fail_missing_precedence_or_and.carbon rename to toolchain/parser/testdata/operators/fail_precedence_or_and.carbon index 7a4d85a3b052..494e24896304 100644 --- a/toolchain/parser/testdata/operators/fail_missing_precedence_or_and.carbon +++ b/toolchain/parser/testdata/operators/fail_precedence_or_and.carbon @@ -21,6 +21,6 @@ // CHECK:STDOUT: ] fn F() { - // CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/fail_missing_precedence_or_and.carbon:[[@LINE+1]]:10: Parentheses are required to disambiguate operator precedence. + // CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/fail_precedence_or_and.carbon:[[@LINE+1]]:10: Parentheses are required to disambiguate operator precedence. a or b and c; } diff --git a/toolchain/parser/testdata/operators/fail_precedence_star_minus.carbon b/toolchain/parser/testdata/operators/fail_precedence_star_minus.carbon new file mode 100644 index 000000000000..0a96cf92909d --- /dev/null +++ b/toolchain/parser/testdata/operators/fail_precedence_star_minus.carbon @@ -0,0 +1,22 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'PostfixOperator', text: '*', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'InfixOperator', text: '-', has_error: yes, subtree_size: 4}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 10}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/fail_precedence_star_minus.carbon:[[@LINE+1]]:16: Parentheses are required to disambiguate operator precedence. +var n: i8 = n* -n; diff --git a/toolchain/parser/testdata/operators/fail_precedence_star_star.carbon b/toolchain/parser/testdata/operators/fail_precedence_star_star.carbon new file mode 100644 index 000000000000..d7dabe615391 --- /dev/null +++ b/toolchain/parser/testdata/operators/fail_precedence_star_star.carbon @@ -0,0 +1,22 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'PostfixOperator', text: '*', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'p'}, +// CHECK:STDOUT: {kind: 'InfixOperator', text: '*', has_error: yes, subtree_size: 4}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 10}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/fail_precedence_star_star.carbon:[[@LINE+1]]:16: Parentheses are required to disambiguate operator precedence. +var n: i8 = n* *p; diff --git a/toolchain/parser/testdata/operators/fail_star_star_no_space.carbon b/toolchain/parser/testdata/operators/fail_star_star_no_space.carbon new file mode 100644 index 000000000000..5a651428972d --- /dev/null +++ b/toolchain/parser/testdata/operators/fail_star_star_no_space.carbon @@ -0,0 +1,25 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'PostfixOperator', text: '*', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'PostfixOperator', text: '*', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', has_error: yes, subtree_size: 9}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// TODO: We try to form (n*)*p and reject due to missing parentheses +// before we notice the missing whitespace around the second `*`. +// It'd be better to (somehow) form n*(*p) and reject due to the missing +// whitespace around the first `*`. +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/fail_star_star_no_space.carbon:[[@LINE+1]]:16: Expected `;` after expression. +var n: i8 = n**p; diff --git a/toolchain/parser/testdata/operators/infix.carbon b/toolchain/parser/testdata/operators/infix.carbon new file mode 100644 index 000000000000..d4c5f6cf1395 --- /dev/null +++ b/toolchain/parser/testdata/operators/infix.carbon @@ -0,0 +1,20 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'InfixOperator', text: '*', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 9}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +var n: i8 = n * n; diff --git a/toolchain/parser/testdata/operators/infix_no_space.carbon b/toolchain/parser/testdata/operators/infix_no_space.carbon new file mode 100644 index 000000000000..6f7ba1758dd3 --- /dev/null +++ b/toolchain/parser/testdata/operators/infix_no_space.carbon @@ -0,0 +1,20 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'InfixOperator', text: '*', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 9}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +var n: i8 = n*n; diff --git a/toolchain/parser/testdata/operators/infix_with_paren_after.carbon b/toolchain/parser/testdata/operators/infix_with_paren_after.carbon new file mode 100644 index 000000000000..3bc38635e724 --- /dev/null +++ b/toolchain/parser/testdata/operators/infix_with_paren_after.carbon @@ -0,0 +1,22 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'Literal', text: '3'}, +// CHECK:STDOUT: {kind: 'ParenExpressionOrTupleLiteralStart', text: '('}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'ParenExpression', text: ')', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'InfixOperator', text: '*', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 11}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +var n: i8 = 3*(n); diff --git a/toolchain/parser/testdata/operators/infix_with_paren_before.carbon b/toolchain/parser/testdata/operators/infix_with_paren_before.carbon new file mode 100644 index 000000000000..36b4e783636f --- /dev/null +++ b/toolchain/parser/testdata/operators/infix_with_paren_before.carbon @@ -0,0 +1,22 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'ParenExpressionOrTupleLiteralStart', text: '('}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'ParenExpression', text: ')', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'Literal', text: '3'}, +// CHECK:STDOUT: {kind: 'InfixOperator', text: '*', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 11}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +var n: i8 = (n)*3; diff --git a/toolchain/parser/testdata/operators/postfix.carbon b/toolchain/parser/testdata/operators/postfix.carbon new file mode 100644 index 000000000000..b0b9d0756bfd --- /dev/null +++ b/toolchain/parser/testdata/operators/postfix.carbon @@ -0,0 +1,19 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'v'}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'Type'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PostfixOperator', text: '*', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +var v: Type = i8*; diff --git a/toolchain/parser/testdata/operators/postfix_unary.carbon b/toolchain/parser/testdata/operators/postfix_repeat.carbon similarity index 100% rename from toolchain/parser/testdata/operators/postfix_unary.carbon rename to toolchain/parser/testdata/operators/postfix_repeat.carbon diff --git a/toolchain/parser/testdata/operators/postfix_space_after_op.carbon b/toolchain/parser/testdata/operators/postfix_space_after_op.carbon new file mode 100644 index 000000000000..aedd45ed112c --- /dev/null +++ b/toolchain/parser/testdata/operators/postfix_space_after_op.carbon @@ -0,0 +1,19 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'v'}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'Type'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PostfixOperator', text: '*', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +var v: Type = i8* ; diff --git a/toolchain/parser/testdata/operators/prefix.carbon b/toolchain/parser/testdata/operators/prefix.carbon new file mode 100644 index 000000000000..202502074012 --- /dev/null +++ b/toolchain/parser/testdata/operators/prefix.carbon @@ -0,0 +1,19 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'PrefixOperator', text: '-', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +var n: i8 = -n; diff --git a/toolchain/parser/testdata/operators/prefix_no_space.carbon b/toolchain/parser/testdata/operators/prefix_no_space.carbon new file mode 100644 index 000000000000..a4d09df41efe --- /dev/null +++ b/toolchain/parser/testdata/operators/prefix_no_space.carbon @@ -0,0 +1,20 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'PrefixOperator', text: '-', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +var n: i8 =-n; +// Valid diff --git a/toolchain/parser/testdata/operators/prefix_unary.carbon b/toolchain/parser/testdata/operators/prefix_repeat.carbon similarity index 100% rename from toolchain/parser/testdata/operators/prefix_unary.carbon rename to toolchain/parser/testdata/operators/prefix_repeat.carbon diff --git a/toolchain/parser/testdata/operators/recover_infix_uneven_space_before.carbon b/toolchain/parser/testdata/operators/recover_infix_uneven_space_before.carbon new file mode 100644 index 000000000000..4efdccc9df59 --- /dev/null +++ b/toolchain/parser/testdata/operators/recover_infix_uneven_space_before.carbon @@ -0,0 +1,21 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'InfixOperator', text: '*', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 9}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/recover_infix_uneven_space_before.carbon:[[@LINE+1]]:15: Whitespace missing after binary operator. +var n: i8 = n *n; diff --git a/toolchain/parser/testdata/operators/recover_postfix_space.carbon b/toolchain/parser/testdata/operators/recover_postfix_space.carbon new file mode 100644 index 000000000000..ba0c2c9f8d52 --- /dev/null +++ b/toolchain/parser/testdata/operators/recover_postfix_space.carbon @@ -0,0 +1,20 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'v'}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'Type'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PostfixOperator', text: '*', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/recover_postfix_space.carbon:[[@LINE+1]]:18: Whitespace is not allowed before this unary operator. +var v: Type = i8 *; diff --git a/toolchain/parser/testdata/operators/recover_postfix_space_before_comma.carbon b/toolchain/parser/testdata/operators/recover_postfix_space_before_comma.carbon new file mode 100644 index 000000000000..4a6c2438b860 --- /dev/null +++ b/toolchain/parser/testdata/operators/recover_postfix_space_before_comma.carbon @@ -0,0 +1,25 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'F'}, +// CHECK:STDOUT: {kind: 'CallExpressionStart', text: '(', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PostfixOperator', text: '*', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'CallExpressionComma', text: ','}, +// CHECK:STDOUT: {kind: 'Literal', text: '0'}, +// CHECK:STDOUT: {kind: 'CallExpression', text: ')', subtree_size: 7}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 13}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/recover_postfix_space_before_comma.carbon:[[@LINE+1]]:18: Whitespace is not allowed before this unary operator. +var n: i8 = F(i8 *, 0); diff --git a/toolchain/parser/testdata/operators/recover_postfix_space_in_call.carbon b/toolchain/parser/testdata/operators/recover_postfix_space_in_call.carbon new file mode 100644 index 000000000000..76e703d42139 --- /dev/null +++ b/toolchain/parser/testdata/operators/recover_postfix_space_in_call.carbon @@ -0,0 +1,23 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'F'}, +// CHECK:STDOUT: {kind: 'CallExpressionStart', text: '(', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PostfixOperator', text: '*', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'CallExpression', text: ')', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 11}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/recover_postfix_space_in_call.carbon:[[@LINE+1]]:18: Whitespace is not allowed before this unary operator. +var n: i8 = F(i8 *); diff --git a/toolchain/parser/testdata/operators/recover_postfix_space_surrounding.carbon b/toolchain/parser/testdata/operators/recover_postfix_space_surrounding.carbon new file mode 100644 index 000000000000..a55a535675fc --- /dev/null +++ b/toolchain/parser/testdata/operators/recover_postfix_space_surrounding.carbon @@ -0,0 +1,21 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'v'}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'Type'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PostfixOperator', text: '*', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/recover_postfix_space_surrounding.carbon:[[@LINE+2]]:18: Whitespace is not allowed before this unary operator. +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/recover_postfix_space_surrounding.carbon:[[@LINE+1]]:18: Whitespace is required after this unary operator. +var v: Type = i8 * ; diff --git a/toolchain/parser/testdata/operators/recover_prefix_space.carbon b/toolchain/parser/testdata/operators/recover_prefix_space.carbon new file mode 100644 index 000000000000..3d49f34055a0 --- /dev/null +++ b/toolchain/parser/testdata/operators/recover_prefix_space.carbon @@ -0,0 +1,21 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'PrefixOperator', text: '-', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/recover_prefix_space.carbon:[[@LINE+2]]:13: Whitespace is not allowed after this unary operator. +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/recover_prefix_space.carbon:[[@LINE+1]]:13: Whitespace is required before this unary operator. +var n: i8 = - n; diff --git a/toolchain/parser/testdata/operators/recover_prefix_uneven_space_with_assign.carbon b/toolchain/parser/testdata/operators/recover_prefix_uneven_space_with_assign.carbon new file mode 100644 index 000000000000..f634575625a6 --- /dev/null +++ b/toolchain/parser/testdata/operators/recover_prefix_uneven_space_with_assign.carbon @@ -0,0 +1,20 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'n'}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i8'}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'NameReference', text: 'n'}, +// CHECK:STDOUT: {kind: 'PrefixOperator', text: '-', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/operators/recover_prefix_uneven_space_with_assign.carbon:[[@LINE+1]]:12: Whitespace is not allowed after this unary operator. +var n: i8 =- n; diff --git a/toolchain/parser/testdata/package/api.carbon b/toolchain/parser/testdata/package/api.carbon new file mode 100644 index 000000000000..8869573a912a --- /dev/null +++ b/toolchain/parser/testdata/package/api.carbon @@ -0,0 +1,15 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Geometry'}, +// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, +// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +package Geometry api; diff --git a/toolchain/parser/testdata/package/api_library.carbon b/toolchain/parser/testdata/package/api_library.carbon new file mode 100644 index 000000000000..12e10caf4e81 --- /dev/null +++ b/toolchain/parser/testdata/package/api_library.carbon @@ -0,0 +1,17 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Geometry'}, +// CHECK:STDOUT: {kind: 'Literal', text: '"Shapes"'}, +// CHECK:STDOUT: {kind: 'PackageLibrary', text: 'library', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, +// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +package Geometry library "Shapes" api; diff --git a/toolchain/parser/testdata/package/fail_extra_string.carbon b/toolchain/parser/testdata/package/fail_extra_string.carbon new file mode 100644 index 000000000000..604aabd518a1 --- /dev/null +++ b/toolchain/parser/testdata/package/fail_extra_string.carbon @@ -0,0 +1,17 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Foo'}, +// CHECK:STDOUT: {kind: 'Literal', text: '"bar"'}, +// CHECK:STDOUT: {kind: 'PackageLibrary', text: 'library', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', has_error: yes, subtree_size: 5}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/package/fail_extra_string.carbon:[[@LINE+1]]:27: Expected a `api` or `impl`. +package Foo library "bar" "baz"; diff --git a/toolchain/parser/testdata/package/fail_library_is_identifier.carbon b/toolchain/parser/testdata/package/fail_library_is_identifier.carbon new file mode 100644 index 000000000000..b6f7ec4a683d --- /dev/null +++ b/toolchain/parser/testdata/package/fail_library_is_identifier.carbon @@ -0,0 +1,15 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Geometry'}, +// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', has_error: yes, subtree_size: 3}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/package/fail_library_is_identifier.carbon:[[@LINE+1]]:26: Expected a string literal to specify the library name. +package Geometry library Shapes api; diff --git a/toolchain/parser/testdata/package/fail_library_skips_name.carbon b/toolchain/parser/testdata/package/fail_library_skips_name.carbon new file mode 100644 index 000000000000..e2d78291d914 --- /dev/null +++ b/toolchain/parser/testdata/package/fail_library_skips_name.carbon @@ -0,0 +1,14 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', has_error: yes, subtree_size: 2}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/package/fail_library_skips_name.carbon:[[@LINE+1]]:9: Expected identifier after `package`. +package library "Shapes" api; diff --git a/toolchain/parser/testdata/package/fail_name_is_keyword.carbon b/toolchain/parser/testdata/package/fail_name_is_keyword.carbon new file mode 100644 index 000000000000..39a678e2ccb7 --- /dev/null +++ b/toolchain/parser/testdata/package/fail_name_is_keyword.carbon @@ -0,0 +1,14 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', has_error: yes, subtree_size: 2}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/package/fail_name_is_keyword.carbon:[[@LINE+1]]:9: Expected identifier after `package`. +package fn; diff --git a/toolchain/parser/testdata/package/fail_no_name.carbon b/toolchain/parser/testdata/package/fail_no_name.carbon new file mode 100644 index 000000000000..8a54c4f293b0 --- /dev/null +++ b/toolchain/parser/testdata/package/fail_no_name.carbon @@ -0,0 +1,14 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', has_error: yes, subtree_size: 2}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/package/fail_no_name.carbon:[[@LINE+1]]:8: Expected identifier after `package`. +package; diff --git a/toolchain/parser/testdata/package/fail_no_semi.carbon b/toolchain/parser/testdata/package/fail_no_semi.carbon new file mode 100644 index 000000000000..ceaa48908297 --- /dev/null +++ b/toolchain/parser/testdata/package/fail_no_semi.carbon @@ -0,0 +1,16 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Geometry'}, +// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, +// CHECK:STDOUT: {kind: 'PackageDirective', text: 'package', has_error: yes, subtree_size: 4}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/package/fail_no_semi.carbon:[[@LINE+1]]:21: Expected `;` to end package directive. +package Geometry api diff --git a/toolchain/parser/testdata/package/fail_no_type.carbon b/toolchain/parser/testdata/package/fail_no_type.carbon new file mode 100644 index 000000000000..42c89f1c8c27 --- /dev/null +++ b/toolchain/parser/testdata/package/fail_no_type.carbon @@ -0,0 +1,15 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Geometry'}, +// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', has_error: yes, subtree_size: 3}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/package/fail_no_type.carbon:[[@LINE+1]]:17: Expected a `api` or `impl`. +package Geometry; diff --git a/toolchain/parser/testdata/package/fail_omit_library_keyword.carbon b/toolchain/parser/testdata/package/fail_omit_library_keyword.carbon new file mode 100644 index 000000000000..760d1b908706 --- /dev/null +++ b/toolchain/parser/testdata/package/fail_omit_library_keyword.carbon @@ -0,0 +1,15 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Geometry'}, +// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', has_error: yes, subtree_size: 3}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/package/fail_omit_library_keyword.carbon:[[@LINE+1]]:18: Missing `library` keyword. +package Geometry "Shapes" api; diff --git a/toolchain/parser/testdata/package/impl.carbon b/toolchain/parser/testdata/package/impl.carbon new file mode 100644 index 000000000000..6786ec31a737 --- /dev/null +++ b/toolchain/parser/testdata/package/impl.carbon @@ -0,0 +1,15 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Geometry'}, +// CHECK:STDOUT: {kind: 'PackageImpl', text: 'impl'}, +// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +package Geometry impl; diff --git a/toolchain/parser/testdata/package/impl_library.carbon b/toolchain/parser/testdata/package/impl_library.carbon new file mode 100644 index 000000000000..5efaf45bed27 --- /dev/null +++ b/toolchain/parser/testdata/package/impl_library.carbon @@ -0,0 +1,17 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'Geometry'}, +// CHECK:STDOUT: {kind: 'Literal', text: '"Shapes"'}, +// CHECK:STDOUT: {kind: 'PackageLibrary', text: 'library', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'PackageImpl', text: 'impl'}, +// CHECK:STDOUT: {kind: 'PackageDirective', text: ';', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +package Geometry library "Shapes" impl; diff --git a/toolchain/parser/testdata/struct/fail_comma_only.carbon b/toolchain/parser/testdata/struct/fail_comma_only.carbon new file mode 100644 index 000000000000..4bb95e4b158d --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_comma_only.carbon @@ -0,0 +1,23 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: ',', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructComma', text: ','}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 11}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_comma_only.carbon:[[@LINE+1]]:9: Expected `.field: type` or `.field = value`. +var x: {,} = {}; diff --git a/toolchain/parser/testdata/struct/fail_comma_repeat_in_type.carbon b/toolchain/parser/testdata/struct/fail_comma_repeat_in_type.carbon new file mode 100644 index 000000000000..845c8e8cab78 --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_comma_repeat_in_type.carbon @@ -0,0 +1,28 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'a'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, +// CHECK:STDOUT: {kind: 'StructFieldType', text: ':', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructComma', text: ','}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: ',', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructComma', text: ','}, +// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 9}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 11}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 16}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_comma_repeat_in_type.carbon:[[@LINE+1]]:17: Expected `.field: type`. +var x: {.a: i32,,} = {}; diff --git a/toolchain/parser/testdata/struct/fail_comma_repeat_in_value.carbon b/toolchain/parser/testdata/struct/fail_comma_repeat_in_value.carbon new file mode 100644 index 000000000000..0623902a62f3 --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_comma_repeat_in_value.carbon @@ -0,0 +1,28 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'a'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: '0'}, +// CHECK:STDOUT: {kind: 'StructFieldValue', text: '=', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructComma', text: ','}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: ',', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructComma', text: ','}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 9}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 11}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 16}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_comma_repeat_in_value.carbon:[[@LINE+1]]:16: Expected `.field = value`. +var x: {.a = 0,,} = {}; diff --git a/toolchain/parser/testdata/struct/fail_dot_only.carbon b/toolchain/parser/testdata/struct/fail_dot_only.carbon new file mode 100644 index 000000000000..4921fdeb9071 --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_dot_only.carbon @@ -0,0 +1,24 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: '}', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '.', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 7}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 12}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_dot_only.carbon:[[@LINE+1]]:10: Expected identifier after `.`. +var x: {.} = {}; diff --git a/toolchain/parser/testdata/struct/fail_dot_string_colon.carbon b/toolchain/parser/testdata/struct/fail_dot_string_colon.carbon new file mode 100644 index 000000000000..948e0f8d26e5 --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_dot_string_colon.carbon @@ -0,0 +1,30 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: '"hello"', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: ':', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructComma', text: ','}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'y'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, +// CHECK:STDOUT: {kind: 'StructFieldType', text: ':', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 11}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 13}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 18}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_dot_string_colon.carbon:[[@LINE+1]]:10: Expected identifier after `.`. +var x: {."hello": i32, .y: i32} = {}; diff --git a/toolchain/parser/testdata/struct/fail_dot_string_equals.carbon b/toolchain/parser/testdata/struct/fail_dot_string_equals.carbon new file mode 100644 index 000000000000..acaf4a4da71f --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_dot_string_equals.carbon @@ -0,0 +1,30 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: '"hello"', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: '0'}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '=', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructComma', text: ','}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'y'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: '4'}, +// CHECK:STDOUT: {kind: 'StructFieldValue', text: '=', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 11}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 13}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 18}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_dot_string_equals.carbon:[[@LINE+1]]:10: Expected identifier after `.`. +var x: {."hello" = 0, .y = 4} = {}; diff --git a/toolchain/parser/testdata/struct/fail_extra_token_in_type.carbon b/toolchain/parser/testdata/struct/fail_extra_token_in_type.carbon new file mode 100644 index 000000000000..94e568f7459e --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_extra_token_in_type.carbon @@ -0,0 +1,29 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'a'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, +// CHECK:STDOUT: {kind: 'StructFieldType', text: ':', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', has_error: yes, subtree_size: 6}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'a'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: '0'}, +// CHECK:STDOUT: {kind: 'StructFieldValue', text: '=', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 7}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 17}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_extra_token_in_type.carbon:[[@LINE+1]]:17: Expected `,` or `}`. +var x: {.a: i32 banana} = {.a = 0}; diff --git a/toolchain/parser/testdata/struct/fail_extra_token_in_value.carbon b/toolchain/parser/testdata/struct/fail_extra_token_in_value.carbon new file mode 100644 index 000000000000..4b41ad353fdd --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_extra_token_in_value.carbon @@ -0,0 +1,29 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'a'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, +// CHECK:STDOUT: {kind: 'StructFieldType', text: ':', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'a'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: '0'}, +// CHECK:STDOUT: {kind: 'StructFieldValue', text: '=', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', has_error: yes, subtree_size: 6}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 7}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 17}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_extra_token_in_value.carbon:[[@LINE+1]]:28: Expected `,` or `}`. +var x: {.a: i32} = {.a = 0 banana}; diff --git a/toolchain/parser/testdata/struct/fail_identifier_colon.carbon b/toolchain/parser/testdata/struct/fail_identifier_colon.carbon new file mode 100644 index 000000000000..5ed7ff2e4928 --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_identifier_colon.carbon @@ -0,0 +1,22 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: 'a', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 10}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_identifier_colon.carbon:[[@LINE+1]]:9: Expected `.field: type` or `.field = value`. +var x: {a:} = {}; diff --git a/toolchain/parser/testdata/struct/fail_identifier_equals.carbon b/toolchain/parser/testdata/struct/fail_identifier_equals.carbon new file mode 100644 index 000000000000..5c116f5c83a4 --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_identifier_equals.carbon @@ -0,0 +1,22 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: 'a', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 10}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_identifier_equals.carbon:[[@LINE+1]]:9: Expected `.field: type` or `.field = value`. +var x: {a=} = {}; diff --git a/toolchain/parser/testdata/struct/fail_identifier_only.carbon b/toolchain/parser/testdata/struct/fail_identifier_only.carbon new file mode 100644 index 000000000000..eb7d6412e8f4 --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_identifier_only.carbon @@ -0,0 +1,22 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: 'a', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 10}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_identifier_only.carbon:[[@LINE+1]]:9: Expected `.field: type` or `.field = value`. +var x: {a} = {}; diff --git a/toolchain/parser/testdata/struct/fail_missing_type.carbon b/toolchain/parser/testdata/struct/fail_missing_type.carbon new file mode 100644 index 000000000000..3670e56c4389 --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_missing_type.carbon @@ -0,0 +1,24 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'a'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: ':', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 7}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 12}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_missing_type.carbon:[[@LINE+1]]:12: Expected expression. +var x: {.a:} = {}; diff --git a/toolchain/parser/testdata/struct/fail_missing_value.carbon b/toolchain/parser/testdata/struct/fail_missing_value.carbon new file mode 100644 index 000000000000..3576fc72ff2f --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_missing_value.carbon @@ -0,0 +1,24 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'a'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '=', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 7}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 12}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_missing_value.carbon:[[@LINE+1]]:12: Expected expression. +var x: {.a=} = {}; diff --git a/toolchain/parser/testdata/struct/fail_mix_type_and_value.carbon b/toolchain/parser/testdata/struct/fail_mix_type_and_value.carbon new file mode 100644 index 000000000000..9425d5ce7179 --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_mix_type_and_value.carbon @@ -0,0 +1,29 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'a'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, +// CHECK:STDOUT: {kind: 'StructFieldType', text: ':', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructComma', text: ','}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'b'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '.', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 10}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 12}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 17}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_mix_type_and_value.carbon:[[@LINE+1]]:21: Expected `.field: type`. +var x: {.a: i32, .b = 0} = {}; diff --git a/toolchain/parser/testdata/struct/fail_mix_value_and_type.carbon b/toolchain/parser/testdata/struct/fail_mix_value_and_type.carbon new file mode 100644 index 000000000000..5482f957c0cd --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_mix_value_and_type.carbon @@ -0,0 +1,27 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'a'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: '0'}, +// CHECK:STDOUT: {kind: 'StructFieldValue', text: '=', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructComma', text: ','}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: 'b', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 10}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 15}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_mix_value_and_type.carbon:[[@LINE+1]]:17: Expected `.field = value`. +var x: {.a = 0, b: i32} = {}; diff --git a/toolchain/parser/testdata/struct/fail_no_colon_or_equals.carbon b/toolchain/parser/testdata/struct/fail_no_colon_or_equals.carbon new file mode 100644 index 000000000000..b4de62031710 --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_no_colon_or_equals.carbon @@ -0,0 +1,24 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'a'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '.', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 7}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 12}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_no_colon_or_equals.carbon:[[@LINE+1]]:11: Expected `.field: type` or `.field = value`. +var x: {.a} = {}; diff --git a/toolchain/parser/testdata/struct/fail_type_no_designator.carbon b/toolchain/parser/testdata/struct/fail_type_no_designator.carbon new file mode 100644 index 000000000000..0ab5a76cc5e4 --- /dev/null +++ b/toolchain/parser/testdata/struct/fail_type_no_designator.carbon @@ -0,0 +1,22 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{not} %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: 'i32', has_error: yes}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 10}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +// CHECK:STDERR: {{.*}}/toolchain/parser/testdata/struct/fail_type_no_designator.carbon:[[@LINE+1]]:9: Expected `.field: type` or `.field = value`. +var x: {i32} = {}; diff --git a/toolchain/parser/testdata/struct/no_entries.carbon b/toolchain/parser/testdata/struct/no_entries.carbon new file mode 100644 index 000000000000..8c06a18459ff --- /dev/null +++ b/toolchain/parser/testdata/struct/no_entries.carbon @@ -0,0 +1,20 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'y'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 9}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +var y: {} = {}; diff --git a/toolchain/parser/testdata/struct/one_entry_no_comma.carbon b/toolchain/parser/testdata/struct/one_entry_no_comma.carbon new file mode 100644 index 000000000000..fde9f2ae4a38 --- /dev/null +++ b/toolchain/parser/testdata/struct/one_entry_no_comma.carbon @@ -0,0 +1,28 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'z'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'n'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, +// CHECK:STDOUT: {kind: 'StructFieldType', text: ':', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'n'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: '4'}, +// CHECK:STDOUT: {kind: 'StructFieldValue', text: '=', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 7}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 17}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +var z: {.n: i32} = {.n = 4}; diff --git a/toolchain/parser/testdata/struct/one_entry_with_comma.carbon b/toolchain/parser/testdata/struct/one_entry_with_comma.carbon new file mode 100644 index 000000000000..5055feff7774 --- /dev/null +++ b/toolchain/parser/testdata/struct/one_entry_with_comma.carbon @@ -0,0 +1,30 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'z'}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'n'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, +// CHECK:STDOUT: {kind: 'StructFieldType', text: ':', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructComma', text: ','}, +// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 7}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 9}, +// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, +// CHECK:STDOUT: {kind: 'DesignatedName', text: 'n'}, +// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'Literal', text: '4'}, +// CHECK:STDOUT: {kind: 'StructFieldValue', text: '=', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'StructComma', text: ','}, +// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 7}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 8}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 19}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +var z: {.n: i32,} = {.n = 4,}; diff --git a/toolchain/parser/testdata/basics/structs.carbon b/toolchain/parser/testdata/struct/two_entries.carbon similarity index 51% rename from toolchain/parser/testdata/basics/structs.carbon rename to toolchain/parser/testdata/struct/two_entries.carbon index b4a9b96fe07c..4a09e28764e4 100644 --- a/toolchain/parser/testdata/basics/structs.carbon +++ b/toolchain/parser/testdata/struct/two_entries.carbon @@ -32,38 +32,7 @@ // CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 11}, // CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 12}, // CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 27}, -// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, -// CHECK:STDOUT: {kind: 'DeclaredName', text: 'y'}, -// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, -// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, -// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 4}, -// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, -// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2}, -// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 3}, -// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 9}, -// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, -// CHECK:STDOUT: {kind: 'DeclaredName', text: 'z'}, -// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, -// CHECK:STDOUT: {kind: 'DesignatedName', text: 'n'}, -// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, -// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, -// CHECK:STDOUT: {kind: 'StructFieldType', text: ':', subtree_size: 4}, -// CHECK:STDOUT: {kind: 'StructComma', text: ','}, -// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 7}, -// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 9}, -// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'}, -// CHECK:STDOUT: {kind: 'DesignatedName', text: 'n'}, -// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2}, -// CHECK:STDOUT: {kind: 'Literal', text: '4'}, -// CHECK:STDOUT: {kind: 'StructFieldValue', text: '=', subtree_size: 4}, -// CHECK:STDOUT: {kind: 'StructComma', text: ','}, -// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 7}, -// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 8}, -// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 19}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] -// NOTE: Move to its own directory when more tests are added. var x: {.a: i32, .b: i32} = {.a = 1, .b = 2}; -var y: {} = {}; -var z: {.n: i32,} = {.n = 4,}; diff --git a/toolchain/parser/testdata/basics/tuples.carbon b/toolchain/parser/testdata/tuple/nested.carbon similarity index 55% rename from toolchain/parser/testdata/basics/tuples.carbon rename to toolchain/parser/testdata/tuple/nested.carbon index 7baeb52a263d..5f55602164d5 100644 --- a/toolchain/parser/testdata/basics/tuples.carbon +++ b/toolchain/parser/testdata/tuple/nested.carbon @@ -6,21 +6,6 @@ // RUN: %{carbon-run-parser} // CHECK:STDOUT: [ // CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, -// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, -// CHECK:STDOUT: {kind: 'ParenExpressionOrTupleLiteralStart', text: '('}, -// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, -// CHECK:STDOUT: {kind: 'TupleLiteralComma', text: ','}, -// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, -// CHECK:STDOUT: {kind: 'TupleLiteral', text: ')', subtree_size: 5}, -// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 7}, -// CHECK:STDOUT: {kind: 'ParenExpressionOrTupleLiteralStart', text: '('}, -// CHECK:STDOUT: {kind: 'Literal', text: '1'}, -// CHECK:STDOUT: {kind: 'TupleLiteralComma', text: ','}, -// CHECK:STDOUT: {kind: 'Literal', text: '2'}, -// CHECK:STDOUT: {kind: 'TupleLiteral', text: ')', subtree_size: 5}, -// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 6}, -// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 15}, -// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, // CHECK:STDOUT: {kind: 'DeclaredName', text: 'y'}, // CHECK:STDOUT: {kind: 'ParenExpressionOrTupleLiteralStart', text: '('}, // CHECK:STDOUT: {kind: 'ParenExpressionOrTupleLiteralStart', text: '('}, @@ -37,6 +22,4 @@ // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] -// NOTE: Move to its own directory when more tests are added. -var x: (i32, i32) = (1, 2); var y: ((), (), ()); diff --git a/toolchain/parser/testdata/tuple/two_entries.carbon b/toolchain/parser/testdata/tuple/two_entries.carbon new file mode 100644 index 000000000000..e4b018caca82 --- /dev/null +++ b/toolchain/parser/testdata/tuple/two_entries.carbon @@ -0,0 +1,26 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// RUN: %{carbon-run-parser} +// CHECK:STDOUT: [ +// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'}, +// CHECK:STDOUT: {kind: 'DeclaredName', text: 'x'}, +// CHECK:STDOUT: {kind: 'ParenExpressionOrTupleLiteralStart', text: '('}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, +// CHECK:STDOUT: {kind: 'TupleLiteralComma', text: ','}, +// CHECK:STDOUT: {kind: 'Literal', text: 'i32'}, +// CHECK:STDOUT: {kind: 'TupleLiteral', text: ')', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 7}, +// CHECK:STDOUT: {kind: 'ParenExpressionOrTupleLiteralStart', text: '('}, +// CHECK:STDOUT: {kind: 'Literal', text: '1'}, +// CHECK:STDOUT: {kind: 'TupleLiteralComma', text: ','}, +// CHECK:STDOUT: {kind: 'Literal', text: '2'}, +// CHECK:STDOUT: {kind: 'TupleLiteral', text: ')', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'VariableInitializer', text: '=', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'VariableDeclaration', text: ';', subtree_size: 15}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] + +var x: (i32, i32) = (1, 2);