char_literals.carbon 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/char_literals.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lex/testdata/char_literals.carbon
  10. // --- valid.carbon
  11. // CHECK:STDOUT: - filename: valid.carbon
  12. // CHECK:STDOUT: tokens:
  13. 'a'
  14. // CHECK:STDOUT: - { index: 1, kind: "CharLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "'a'", has_leading_space: true }
  15. '\n'
  16. // CHECK:STDOUT: - { index: 2, kind: "CharLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "'\\n'", has_leading_space: true }
  17. '\x7F'
  18. // CHECK:STDOUT: - { index: 3, kind: "CharLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "'\\x7F'", has_leading_space: true }
  19. '\u{123}'
  20. // CHECK:STDOUT: - { index: 4, kind: "CharLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "'\\u{123}'", has_leading_space: true }
  21. '\xC3\xA9'
  22. // CHECK:STDOUT: - { index: 5, kind: "CharLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "'\\xC3\\xA9'", has_leading_space: true }
  23. // --- fail_invalid.carbon
  24. // CHECK:STDOUT: - filename: fail_invalid.carbon
  25. // CHECK:STDOUT: tokens:
  26. // CHECK:STDERR: fail_invalid.carbon:[[@LINE+4]]:1: error: empty character literal [CharLiteralEmpty]
  27. // CHECK:STDERR: ''
  28. // CHECK:STDERR: ^
  29. // CHECK:STDERR:
  30. ''
  31. // CHECK:STDOUT: - { index: 1, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "''", has_leading_space: true }
  32. // CHECK:STDERR: fail_invalid.carbon:[[@LINE+4]]:1: error: too many characters [CharLiteralOverflow]
  33. // CHECK:STDERR: 'abcde'
  34. // CHECK:STDERR: ^
  35. // CHECK:STDERR:
  36. 'abcde'
  37. // CHECK:STDOUT: - { index: 2, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "'abcde'", has_leading_space: true }
  38. // CHECK:STDERR: fail_invalid.carbon:[[@LINE+4]]:1: error: incomplete UTF-8 [CharLiteralUnderflow]
  39. // CHECK:STDERR: '\xC3'
  40. // CHECK:STDERR: ^
  41. // CHECK:STDERR:
  42. '\xC3'
  43. // CHECK:STDOUT: - { index: 3, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "'\\xC3'", has_leading_space: true }
  44. // CHECK:STDERR: fail_invalid.carbon:[[@LINE+4]]:1: error: invalid UTF-8 character [CharLiteralInvalidUTF8]
  45. // CHECK:STDERR: '\xC3\xFF'
  46. // CHECK:STDERR: ^
  47. // CHECK:STDERR:
  48. '\xC3\xFF'
  49. // CHECK:STDOUT: - { index: 4, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "'\\xC3\\xFF'", has_leading_space: true }
  50. // CHECK:STDERR: fail_invalid.carbon:[[@LINE+4]]:1: error: unexpected `#` before character literal [CharLiteralRaw]
  51. // CHECK:STDERR: #'a'#
  52. // CHECK:STDERR: ^
  53. // CHECK:STDERR:
  54. #'a'#
  55. // CHECK:STDOUT: - { index: 5, kind: "CharLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "#'a'#", has_leading_space: true }