match_case.carbon 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/parse/testdata/auto/match_case.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/auto/match_case.carbon
  10. fn f() -> bool {
  11. match (true) {
  12. case x: auto if (x == true) => { return true; }
  13. default => { return false; }
  14. }
  15. }
  16. // CHECK:STDOUT: - filename: match_case.carbon
  17. // CHECK:STDOUT: parse_tree: [
  18. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  19. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  20. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'f'},
  21. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  22. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 2},
  23. // CHECK:STDOUT: {kind: 'BoolTypeLiteral', text: 'bool'},
  24. // CHECK:STDOUT: {kind: 'ReturnType', text: '->', subtree_size: 2},
  25. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 7},
  26. // CHECK:STDOUT: {kind: 'MatchIntroducer', text: 'match'},
  27. // CHECK:STDOUT: {kind: 'MatchConditionStart', text: '('},
  28. // CHECK:STDOUT: {kind: 'BoolLiteralTrue', text: 'true'},
  29. // CHECK:STDOUT: {kind: 'MatchCondition', text: ')', subtree_size: 3},
  30. // CHECK:STDOUT: {kind: 'MatchStatementStart', text: '{', subtree_size: 5},
  31. // CHECK:STDOUT: {kind: 'MatchCaseIntroducer', text: 'case'},
  32. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'x'},
  33. // CHECK:STDOUT: {kind: 'AutoTypeLiteral', text: 'auto'},
  34. // CHECK:STDOUT: {kind: 'LetBindingPattern', text: ':', subtree_size: 3},
  35. // CHECK:STDOUT: {kind: 'MatchCaseGuardIntroducer', text: 'if'},
  36. // CHECK:STDOUT: {kind: 'MatchCaseGuardStart', text: '('},
  37. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'x'},
  38. // CHECK:STDOUT: {kind: 'BoolLiteralTrue', text: 'true'},
  39. // CHECK:STDOUT: {kind: 'InfixOperatorEqualEqual', text: '==', subtree_size: 3},
  40. // CHECK:STDOUT: {kind: 'MatchCaseGuard', text: ')', subtree_size: 6},
  41. // CHECK:STDOUT: {kind: 'MatchCaseEqualGreater', text: '=>'},
  42. // CHECK:STDOUT: {kind: 'MatchCaseStart', text: '{', subtree_size: 12},
  43. // CHECK:STDOUT: {kind: 'ReturnStatementStart', text: 'return'},
  44. // CHECK:STDOUT: {kind: 'BoolLiteralTrue', text: 'true'},
  45. // CHECK:STDOUT: {kind: 'ReturnStatement', text: ';', subtree_size: 3},
  46. // CHECK:STDOUT: {kind: 'MatchCase', text: '}', subtree_size: 16},
  47. // CHECK:STDOUT: {kind: 'MatchDefaultIntroducer', text: 'default'},
  48. // CHECK:STDOUT: {kind: 'MatchDefaultEqualGreater', text: '=>'},
  49. // CHECK:STDOUT: {kind: 'MatchDefaultStart', text: '{', subtree_size: 3},
  50. // CHECK:STDOUT: {kind: 'ReturnStatementStart', text: 'return'},
  51. // CHECK:STDOUT: {kind: 'BoolLiteralFalse', text: 'false'},
  52. // CHECK:STDOUT: {kind: 'ReturnStatement', text: ';', subtree_size: 3},
  53. // CHECK:STDOUT: {kind: 'MatchDefault', text: '}', subtree_size: 7},
  54. // CHECK:STDOUT: {kind: 'MatchStatement', text: '}', subtree_size: 29},
  55. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 37},
  56. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  57. // CHECK:STDOUT: ]