fail_bad_raw_identifier.carbon 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/lex/testdata/fail_bad_raw_identifier.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lex/testdata/fail_bad_raw_identifier.carbon
  10. // --- fail_bad_raw_identifier.carbon
  11. // CHECK:STDOUT: - filename: fail_bad_raw_identifier.carbon
  12. // CHECK:STDOUT: tokens:
  13. // Missing the character after `#`.
  14. // CHECK:STDERR: fail_bad_raw_identifier.carbon:[[@LINE+4]]:2: error: encountered unrecognized characters while parsing [UnrecognizedCharacters]
  15. // CHECK:STDERR: r#
  16. // CHECK:STDERR: ^
  17. // CHECK:STDERR:
  18. r#
  19. // CHECK:STDOUT: - { index: 1, kind: "Identifier", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "r", identifier: 0, has_leading_space: true }
  20. // CHECK:STDOUT: - { index: 2, kind: "Error", line: {{ *}}[[@LINE-2]], column: 2, indent: 1, spelling: "#" }
  21. // Not a valid identifier.
  22. // CHECK:STDERR: fail_bad_raw_identifier.carbon:[[@LINE+4]]:2: error: encountered unrecognized characters while parsing [UnrecognizedCharacters]
  23. // CHECK:STDERR: r#3
  24. // CHECK:STDERR: ^
  25. // CHECK:STDERR:
  26. r#3
  27. // CHECK:STDOUT: - { index: 3, kind: "Identifier", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "r", identifier: 0, has_leading_space: true }
  28. // CHECK:STDOUT: - { index: 4, kind: "Error", line: {{ *}}[[@LINE-2]], column: 2, indent: 1, spelling: "#" }
  29. // CHECK:STDOUT: - { index: 5, kind: "IntLiteral", line: {{ *}}[[@LINE-3]], column: 3, indent: 1, spelling: "3", value: "3" }
  30. // Non ascii start to identifier.
  31. // CHECK:STDERR: fail_bad_raw_identifier.carbon:[[@LINE+4]]:2: error: encountered unrecognized characters while parsing [UnrecognizedCharacters]
  32. // CHECK:STDERR: r#<C3><A1>
  33. // CHECK:STDERR: ^
  34. // CHECK:STDERR:
  35. r#á
  36. // CHECK:STDOUT: - { index: 6, kind: "Identifier", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "r", identifier: 0, has_leading_space: true }
  37. // CHECK:STDOUT: - { index: 7, kind: "Error", line: {{ *}}[[@LINE-2]], column: 2, indent: 1, spelling: "#\xC3\xA1" }
  38. // Raw `r` identifier doesn't start a second raw identifier.
  39. // CHECK:STDERR: fail_bad_raw_identifier.carbon:[[@LINE+4]]:4: error: encountered unrecognized characters while parsing [UnrecognizedCharacters]
  40. // CHECK:STDERR: r#r#foo
  41. // CHECK:STDERR: ^
  42. // CHECK:STDERR:
  43. r#r#foo
  44. // CHECK:STDOUT: - { index: 8, kind: "Identifier", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "r", identifier: 0, has_leading_space: true }
  45. // CHECK:STDOUT: - { index: 9, kind: "Error", line: {{ *}}[[@LINE-2]], column: 4, indent: 1, spelling: "#" }
  46. // CHECK:STDOUT: - { index: 10, kind: "Identifier", line: {{ *}}[[@LINE-3]], column: 5, indent: 1, spelling: "foo", identifier: 1 }
  47. // Other identifier characters don't start a raw identifier.
  48. // CHECK:STDERR: fail_bad_raw_identifier.carbon:[[@LINE+4]]:2: error: encountered unrecognized characters while parsing [UnrecognizedCharacters]
  49. // CHECK:STDERR: s#foo
  50. // CHECK:STDERR: ^
  51. // CHECK:STDERR:
  52. s#foo
  53. // CHECK:STDOUT: - { index: 11, kind: "Identifier", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "s", identifier: 2, has_leading_space: true }
  54. // CHECK:STDOUT: - { index: 12, kind: "Error", line: {{ *}}[[@LINE-2]], column: 2, indent: 1, spelling: "#" }
  55. // CHECK:STDOUT: - { index: 13, kind: "Identifier", line: {{ *}}[[@LINE-3]], column: 3, indent: 1, spelling: "foo", identifier: 1 }
  56. // Identifier ending in `r` doesn't start a raw identifier.
  57. // CHECK:STDERR: fail_bad_raw_identifier.carbon:[[@LINE+4]]:4: error: encountered unrecognized characters while parsing [UnrecognizedCharacters]
  58. // CHECK:STDERR: arr#foo
  59. // CHECK:STDERR: ^
  60. // CHECK:STDERR:
  61. arr#foo
  62. // CHECK:STDOUT: - { index: 14, kind: "Identifier", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "arr", identifier: 3, has_leading_space: true }
  63. // CHECK:STDOUT: - { index: 15, kind: "Error", line: {{ *}}[[@LINE-2]], column: 4, indent: 1, spelling: "#" }
  64. // CHECK:STDOUT: - { index: 16, kind: "Identifier", line: {{ *}}[[@LINE-3]], column: 5, indent: 1, spelling: "foo", identifier: 1 }
  65. // Whitespace between `r` and `#` isn't allowed.
  66. // CHECK:STDERR: fail_bad_raw_identifier.carbon:[[@LINE+4]]:3: error: encountered unrecognized characters while parsing [UnrecognizedCharacters]
  67. // CHECK:STDERR: r #foo
  68. // CHECK:STDERR: ^
  69. // CHECK:STDERR:
  70. r #foo
  71. // CHECK:STDOUT: - { index: 17, kind: "Identifier", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "r", identifier: 0, has_leading_space: true }
  72. // CHECK:STDOUT: - { index: 18, kind: "Error", line: {{ *}}[[@LINE-2]], column: 3, indent: 1, spelling: "#", has_leading_space: true }
  73. // CHECK:STDOUT: - { index: 19, kind: "Identifier", line: {{ *}}[[@LINE-3]], column: 4, indent: 1, spelling: "foo", identifier: 1 }
  74. // This is an `r` identifier followed by a string literal.
  75. r#"hello"#
  76. // CHECK:STDOUT: - { index: 20, kind: "Identifier", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "r", identifier: 0, has_leading_space: true }
  77. // CHECK:STDOUT: - { index: 21, kind: "StringLiteral", line: {{ *}}[[@LINE-2]], column: 2, indent: 1, spelling: "#\"hello\"#", value: "hello" }
  78. // --- fail_hash_at_start_of_file.carbon
  79. // CHECK:STDOUT: - filename: fail_hash_at_start_of_file.carbon
  80. // CHECK:STDOUT: tokens:
  81. // Ensure that we correctly handle a `#` as the first token in the file.
  82. // CHECK:STDERR: fail_hash_at_start_of_file.carbon:[[@LINE+4]]:1: error: encountered unrecognized characters while parsing [UnrecognizedCharacters]
  83. // CHECK:STDERR: #foo
  84. // CHECK:STDERR: ^
  85. // CHECK:STDERR:
  86. #foo
  87. // CHECK:STDOUT: - { index: 1, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "#", has_leading_space: true }
  88. // CHECK:STDOUT: - { index: 2, kind: "Identifier", line: {{ *}}[[@LINE-2]], column: 2, indent: 1, spelling: "foo", identifier: 0 }