• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/00_syntax/09_string_literals

  1 String literals may be enclosed in single or double quotes.
  2 Embedded escape sequences are started with a backslash, followed
  3 by either a hexadecimal, an octal or a single character escape sequence.
  4 
  5 -- Expect stdout --
  6 Single quoted string
  7 Double quoted string
  8 Unicode escape sequence: ☀💩
  9 Escaped double quote (") character
 10 Escaped single quote (') character
 11 Hexadecimal escape: XYZ xyz
 12 Octal escape: ABC xyz
 13 { "Single char escape": "\u0007\b\u001b\f\r\t\u000b\\\n" }
 14 -- End --
 15 
 16 -- Testcase --
 17 {{ 'Single quoted string' }}
 18 {{ "Double quoted string" }}
 19 {{ "Unicode escape sequence: \u2600\uD83D\uDCA9" }}
 20 {{ "Escaped double quote (\") character" }}
 21 {{ 'Escaped single quote (\') character' }}
 22 {{ "Hexadecimal escape: \x58\x59\x5A \x78\x79\x7a" }}
 23 {{ "Octal escape: \101\102\103 \170\171\172" }}
 24 {{ { "Single char escape": "\a\b\e\f\r\t\v\\\n" } }}
 25 -- End --
 26 
 27 
 28 Testing various parsing corner cases.
 29 
 30 -- Expect stdout --
 31 [ "\t", "\n", "y", "\u0001", "\n", "\u0001\u0002", "\u0001\u0002", "\u0001\u0002", "\u0001a", "\na" ]
 32 -- End --
 33 
 34 -- Testcase --
 35 {%
 36         print([
 37                 "\      ",      // properly handle escaped tab
 38                 "\
 39 ",                              // properly handle escaped newline
 40                 "\y",           // substitute unrecognized escape with escaped char
 41                 "\1",           // handle short octal sequence at end of string
 42                 "\12",          // handle short octal sequence at end of string
 43                 "\1\2",         // handle subsequent short octal sequences
 44                 "\001\2",       // handle short sequence after long one
 45                 "\1\002",       // handle long sequence after short one
 46                 "\1a",          // handle short octal sequence terminated by non-octal char
 47                 "\12a"          // handle short octal sequence terminated by non-octal char
 48         ], "\n");
 49 %}
 50 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt