diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-11-30 17:38:50 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-11-30 17:38:50 +0100 |
commit | ac5cb8736f89f8da0c1bbe407d7d4ae9df530a5c (patch) | |
tree | 8e1f0a1e5e1bcde78f275839fb109e3eaf9bdb7b /tests/00_syntax/21_regex_literals | |
parent | f7b079ce3a41a0f92adb623b0de10419fc9f5df9 (diff) |
syntax: fix string and regex literal parsing quirks
- Do not interprete escape sequences in regexp literals
- Do not improperly substitute control escape sequences such as
`\n` or `\a` after a backslash
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/00_syntax/21_regex_literals')
-rw-r--r-- | tests/00_syntax/21_regex_literals | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/00_syntax/21_regex_literals b/tests/00_syntax/21_regex_literals new file mode 100644 index 0000000..bbb78fb --- /dev/null +++ b/tests/00_syntax/21_regex_literals @@ -0,0 +1,89 @@ +Regex literals are enclosed in forward slashes and may contain zero +or more trailing flag characters. Interpretation of escape sequences +within regular expression literals is subject of the underlying +regular expression engine. + +-- Expect stdout -- +[ "/Hello world/", "/test/gis", "/test/g", "/test1 \\\/ test2/", "/\\x31\\n\\.\\a\\b\\c\\u2600\\\\/" ] +-- End -- + +-- Testcase -- +{% + print([ + /Hello world/, // A very simple expression + /test/gsi, // Regular expression flags + /test/gg, // Repeated flags + /test1 \/ test2/, // Escaped forward slash + /\x31\n\.\a\b\c\u2600\\/ // Ensure that escape sequences are passed as-is + ], "\n"); +%} +-- End -- + + +Testing regular expression type. + +-- Expect stdout -- +object +-- End -- + +-- Testcase -- +{{ type(/foo/) }} +-- End -- + + +Testing invalid flag characters. + +-- Expect stderr -- +Syntax error: Unexpected token +Expecting ',' or ';' +In line 2, byte 8: + + ` /test/x` + ^-- Near here + + +-- End -- + +-- Testcase -- +{% + /test/x +%} +-- End -- + + +Testing unclosed regular expression. + +-- Expect stderr -- +Syntax error: Unterminated string +In line 2, byte 2: + + ` /foo \/` + ^-- Near here + + +-- End -- + +-- Testcase -- +{% + /foo \/ +%} +-- End -- + + +Testing regex compilation errors. + +-- Expect stderr -- +Syntax error: Unmatched \{ +In line 2, byte 3: + + ` /foo {/` + ^-- Near here + + +-- End -- + +-- Testcase -- +{% + /foo {/ +%} +-- End -- |