string_escape_sequences.gravity 593 B

123456789101112131415161718192021222324252627282930313233
  1. #unittest {
  2. name: "String escape sequences.";
  3. error: NONE;
  4. result: true;
  5. };
  6. func main() {
  7. // Basic escapes
  8. var s1 = "hello\tworld";
  9. var r1 = s1.length == 11;
  10. // Newline
  11. var s2 = "line1\nline2";
  12. var r2 = s2.length == 11;
  13. // Hex escape
  14. var s3 = "\x41\x42\x43";
  15. var r3 = (s3 == "ABC");
  16. // Unicode escape (2-byte UTF-8)
  17. var s4 = "\u00E9"; // e with accent
  18. var r4 = s4.bytes == 2;
  19. // Multiple escapes in sequence
  20. var s5 = "\t\n\r";
  21. var r5 = s5.length == 3;
  22. // Escaped backslash
  23. var s6 = "a\\b";
  24. var r6 = s6.length == 3;
  25. return r1 and r2 and r3 and r4 and r5 and r6;
  26. }