string_literals.carbon 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/string_literals.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lex/testdata/string_literals.carbon
  10. // --- fail_decimal_escape.carbon
  11. // CHECK:STDOUT: - filename: fail_decimal_escape.carbon
  12. // CHECK:STDOUT: tokens:
  13. // CHECK:STDERR: fail_decimal_escape.carbon:[[@LINE+4]]:4: error: decimal digit follows `\0` escape sequence. Use `\x00` instead of `\0` if the next character is a digit [DecimalEscapeSequence]
  14. // CHECK:STDERR: "\01"
  15. // CHECK:STDERR: ^
  16. // CHECK:STDERR:
  17. "\01"
  18. // CHECK:STDOUT: - { index: 1, kind: "StringLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "\"\\01\"", value: "\x001", has_leading_space: true }
  19. // --- fail_unterminated.carbon
  20. // CHECK:STDOUT: - filename: fail_unterminated.carbon
  21. // CHECK:STDOUT: tokens:
  22. // CHECK:STDERR: fail_unterminated.carbon:[[@LINE+4]]:1: error: string literal is missing a terminator [UnterminatedString]
  23. // CHECK:STDERR: "s
  24. // CHECK:STDERR: ^
  25. // CHECK:STDERR:
  26. "s
  27. // CHECK:STDOUT: - { index: 1, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "\"s", has_leading_space: true }
  28. // --- fail_unknown_escape.carbon
  29. // CHECK:STDOUT: - filename: fail_unknown_escape.carbon
  30. // CHECK:STDOUT: tokens:
  31. // CHECK:STDERR: fail_unknown_escape.carbon:[[@LINE+4]]:3: error: unrecognized escape sequence `w` [UnknownEscapeSequence]
  32. // CHECK:STDERR: "\w"
  33. // CHECK:STDERR: ^
  34. // CHECK:STDERR:
  35. "\w"
  36. // CHECK:STDOUT: - { index: 1, kind: "StringLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "\"\\w\"", value: "w", has_leading_space: true }
  37. // --- fail_unicode_escape_missing_braced_digits.carbon
  38. // CHECK:STDOUT: - filename: fail_unicode_escape_missing_braced_digits.carbon
  39. // CHECK:STDOUT: tokens:
  40. // CHECK:STDERR: fail_unicode_escape_missing_braced_digits.carbon:[[@LINE+4]]:4: error: escape sequence `\u` must be followed by a braced sequence of uppercase hexadecimal digits, for example `\u{70AD}}` [UnicodeEscapeMissingBracedDigits]
  41. // CHECK:STDERR: "\u"
  42. // CHECK:STDERR: ^
  43. // CHECK:STDERR:
  44. "\u"
  45. // CHECK:STDOUT: - { index: 1, kind: "StringLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "\"\\u\"", value: "u", has_leading_space: true }
  46. // --- fail_hex_escape_missing_digits.carbon
  47. // CHECK:STDOUT: - filename: fail_hex_escape_missing_digits.carbon
  48. // CHECK:STDOUT: tokens:
  49. // CHECK:STDERR: fail_hex_escape_missing_digits.carbon:[[@LINE+4]]:4: error: escape sequence `\x` must be followed by two uppercase hexadecimal digits, for example `\x0F` [HexadecimalEscapeMissingDigits]
  50. // CHECK:STDERR: "\x"
  51. // CHECK:STDERR: ^
  52. // CHECK:STDERR:
  53. "\x"
  54. // CHECK:STDOUT: - { index: 1, kind: "StringLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "\"\\x\"", value: "x", has_leading_space: true }
  55. // --- fail_literal_tab_in_string.carbon
  56. // CHECK:STDOUT: - filename: fail_literal_tab_in_string.carbon
  57. // CHECK:STDOUT: tokens:
  58. // CHECK:STDERR: fail_literal_tab_in_string.carbon:[[@LINE+4]]:2: error: whitespace other than plain space must be expressed with an escape sequence in a string literal [InvalidHorizontalWhitespaceInString]
  59. // CHECK:STDERR: "<09>"
  60. // CHECK:STDERR: ^~~~
  61. // CHECK:STDERR:
  62. " "
  63. // CHECK:STDOUT: - { index: 1, kind: "StringLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "\"\t\"", value: "\t", has_leading_space: true }
  64. // --- fail_unicode_surrogate.carbon
  65. // CHECK:STDOUT: - filename: fail_unicode_surrogate.carbon
  66. // CHECK:STDOUT: tokens:
  67. // CHECK:STDERR: fail_unicode_surrogate.carbon:[[@LINE+4]]:5: error: code point specified by `\u{...}}` escape is a surrogate character [UnicodeEscapeSurrogate]
  68. // CHECK:STDERR: "\u{D800}"
  69. // CHECK:STDERR: ^
  70. // CHECK:STDERR:
  71. "\u{D800}"
  72. // CHECK:STDOUT: - { index: 1, kind: "StringLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "\"\\u{D800}\"", value: "u{D800}", has_leading_space: true }
  73. // --- fail_unicode_length.carbon
  74. // CHECK:STDOUT: - filename: fail_unicode_length.carbon
  75. // CHECK:STDOUT: tokens:
  76. // CHECK:STDERR: fail_unicode_length.carbon:[[@LINE+4]]:5: error: code point specified by `\u{...}}` escape is greater than 0x10FFFF [UnicodeEscapeTooLarge]
  77. // CHECK:STDERR: "\u{FFFFFFFF}"
  78. // CHECK:STDERR: ^
  79. // CHECK:STDERR:
  80. "\u{FFFFFFFF}"
  81. // CHECK:STDOUT: - { index: 1, kind: "StringLiteral", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "\"\\u{FFFFFFFF}\"", value: "u{FFFFFFFF}", has_leading_space: true }