Przeglądaj źródła

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.
Jon Ross-Perkins 3 lat temu
rodzic
commit
991dadcbed
60 zmienionych plików z 1130 dodań i 214 usunięć
  1. 0 129
      toolchain/parser/parse_tree_test.cpp
  2. 0 35
      toolchain/parser/testdata/basics/package.carbon
  3. 22 0
      toolchain/parser/testdata/operators/fail_infix_uneven_space_after.carbon
  4. 1 1
      toolchain/parser/testdata/operators/fail_precedence_and_or.carbon
  5. 1 1
      toolchain/parser/testdata/operators/fail_precedence_or_and.carbon
  6. 22 0
      toolchain/parser/testdata/operators/fail_precedence_star_minus.carbon
  7. 22 0
      toolchain/parser/testdata/operators/fail_precedence_star_star.carbon
  8. 25 0
      toolchain/parser/testdata/operators/fail_star_star_no_space.carbon
  9. 20 0
      toolchain/parser/testdata/operators/infix.carbon
  10. 20 0
      toolchain/parser/testdata/operators/infix_no_space.carbon
  11. 22 0
      toolchain/parser/testdata/operators/infix_with_paren_after.carbon
  12. 22 0
      toolchain/parser/testdata/operators/infix_with_paren_before.carbon
  13. 19 0
      toolchain/parser/testdata/operators/postfix.carbon
  14. 0 0
      toolchain/parser/testdata/operators/postfix_repeat.carbon
  15. 19 0
      toolchain/parser/testdata/operators/postfix_space_after_op.carbon
  16. 19 0
      toolchain/parser/testdata/operators/prefix.carbon
  17. 20 0
      toolchain/parser/testdata/operators/prefix_no_space.carbon
  18. 0 0
      toolchain/parser/testdata/operators/prefix_repeat.carbon
  19. 21 0
      toolchain/parser/testdata/operators/recover_infix_uneven_space_before.carbon
  20. 20 0
      toolchain/parser/testdata/operators/recover_postfix_space.carbon
  21. 25 0
      toolchain/parser/testdata/operators/recover_postfix_space_before_comma.carbon
  22. 23 0
      toolchain/parser/testdata/operators/recover_postfix_space_in_call.carbon
  23. 21 0
      toolchain/parser/testdata/operators/recover_postfix_space_surrounding.carbon
  24. 21 0
      toolchain/parser/testdata/operators/recover_prefix_space.carbon
  25. 20 0
      toolchain/parser/testdata/operators/recover_prefix_uneven_space_with_assign.carbon
  26. 15 0
      toolchain/parser/testdata/package/api.carbon
  27. 17 0
      toolchain/parser/testdata/package/api_library.carbon
  28. 17 0
      toolchain/parser/testdata/package/fail_extra_string.carbon
  29. 15 0
      toolchain/parser/testdata/package/fail_library_is_identifier.carbon
  30. 14 0
      toolchain/parser/testdata/package/fail_library_skips_name.carbon
  31. 14 0
      toolchain/parser/testdata/package/fail_name_is_keyword.carbon
  32. 14 0
      toolchain/parser/testdata/package/fail_no_name.carbon
  33. 16 0
      toolchain/parser/testdata/package/fail_no_semi.carbon
  34. 15 0
      toolchain/parser/testdata/package/fail_no_type.carbon
  35. 15 0
      toolchain/parser/testdata/package/fail_omit_library_keyword.carbon
  36. 15 0
      toolchain/parser/testdata/package/impl.carbon
  37. 17 0
      toolchain/parser/testdata/package/impl_library.carbon
  38. 23 0
      toolchain/parser/testdata/struct/fail_comma_only.carbon
  39. 28 0
      toolchain/parser/testdata/struct/fail_comma_repeat_in_type.carbon
  40. 28 0
      toolchain/parser/testdata/struct/fail_comma_repeat_in_value.carbon
  41. 24 0
      toolchain/parser/testdata/struct/fail_dot_only.carbon
  42. 30 0
      toolchain/parser/testdata/struct/fail_dot_string_colon.carbon
  43. 30 0
      toolchain/parser/testdata/struct/fail_dot_string_equals.carbon
  44. 29 0
      toolchain/parser/testdata/struct/fail_extra_token_in_type.carbon
  45. 29 0
      toolchain/parser/testdata/struct/fail_extra_token_in_value.carbon
  46. 22 0
      toolchain/parser/testdata/struct/fail_identifier_colon.carbon
  47. 22 0
      toolchain/parser/testdata/struct/fail_identifier_equals.carbon
  48. 22 0
      toolchain/parser/testdata/struct/fail_identifier_only.carbon
  49. 24 0
      toolchain/parser/testdata/struct/fail_missing_type.carbon
  50. 24 0
      toolchain/parser/testdata/struct/fail_missing_value.carbon
  51. 29 0
      toolchain/parser/testdata/struct/fail_mix_type_and_value.carbon
  52. 27 0
      toolchain/parser/testdata/struct/fail_mix_value_and_type.carbon
  53. 24 0
      toolchain/parser/testdata/struct/fail_no_colon_or_equals.carbon
  54. 22 0
      toolchain/parser/testdata/struct/fail_type_no_designator.carbon
  55. 20 0
      toolchain/parser/testdata/struct/no_entries.carbon
  56. 28 0
      toolchain/parser/testdata/struct/one_entry_no_comma.carbon
  57. 30 0
      toolchain/parser/testdata/struct/one_entry_with_comma.carbon
  58. 0 31
      toolchain/parser/testdata/struct/two_entries.carbon
  59. 0 17
      toolchain/parser/testdata/tuple/nested.carbon
  60. 26 0
      toolchain/parser/testdata/tuple/two_entries.carbon

+ 0 - 129
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<const Diagnostic&> 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<const Diagnostic&> 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

+ 0 - 35
toolchain/parser/testdata/basics/package.carbon

@@ -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;

+ 22 - 0
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;

+ 1 - 1
toolchain/parser/testdata/operators/fail_missing_precedence_and_or.carbon → 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;
 }

+ 1 - 1
toolchain/parser/testdata/operators/fail_missing_precedence_or_and.carbon → 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;
 }

+ 22 - 0
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;

+ 22 - 0
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;

+ 25 - 0
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;

+ 20 - 0
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;

+ 20 - 0
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;

+ 22 - 0
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);

+ 22 - 0
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;

+ 19 - 0
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*;

+ 0 - 0
toolchain/parser/testdata/operators/postfix_unary.carbon → toolchain/parser/testdata/operators/postfix_repeat.carbon


+ 19 - 0
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* ;

+ 19 - 0
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;

+ 20 - 0
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

+ 0 - 0
toolchain/parser/testdata/operators/prefix_unary.carbon → toolchain/parser/testdata/operators/prefix_repeat.carbon


+ 21 - 0
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;

+ 20 - 0
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 *;

+ 25 - 0
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);

+ 23 - 0
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 *);

+ 21 - 0
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 * ;

+ 21 - 0
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;

+ 20 - 0
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;

+ 15 - 0
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;

+ 17 - 0
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;

+ 17 - 0
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";

+ 15 - 0
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;

+ 14 - 0
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;

+ 14 - 0
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;

+ 14 - 0
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;

+ 16 - 0
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

+ 15 - 0
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;

+ 15 - 0
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;

+ 15 - 0
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;

+ 17 - 0
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;

+ 23 - 0
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: {,} = {};

+ 28 - 0
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,,} = {};

+ 28 - 0
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,,} = {};

+ 24 - 0
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: {.} = {};

+ 30 - 0
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} = {};

+ 30 - 0
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} = {};

+ 29 - 0
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};

+ 29 - 0
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};

+ 22 - 0
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:} = {};

+ 22 - 0
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=} = {};

+ 22 - 0
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} = {};

+ 24 - 0
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:} = {};

+ 24 - 0
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=} = {};

+ 29 - 0
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} = {};

+ 27 - 0
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} = {};

+ 24 - 0
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} = {};

+ 22 - 0
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} = {};

+ 20 - 0
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: {} = {};

+ 28 - 0
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};

+ 30 - 0
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,};

+ 0 - 31
toolchain/parser/testdata/basics/structs.carbon → 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,};

+ 0 - 17
toolchain/parser/testdata/basics/tuples.carbon → 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: ((), (), ());

+ 26 - 0
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);