summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/00_syntax/21_regex_literals
diff options
context:
space:
mode:
authorPetr Štetiar <ynezz@true.cz>2021-03-19 16:54:55 +0100
committerJo-Philipp Wich <jo@mein.io>2021-04-23 00:42:30 +0200
commit2b59097c3f61fa901e91ac4cea48940760439578 (patch)
tree958d739a78f959dfcd55b3d76e6e970ca53fa1c6 /tests/custom/00_syntax/21_regex_literals
parent80393611fb6634abcc0da1dee2da7c4418dbde8d (diff)
tests: create custom tests from current tests cases
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Diffstat (limited to 'tests/custom/00_syntax/21_regex_literals')
-rw-r--r--tests/custom/00_syntax/21_regex_literals89
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/custom/00_syntax/21_regex_literals b/tests/custom/00_syntax/21_regex_literals
new file mode 100644
index 0000000..3af53bb
--- /dev/null
+++ b/tests/custom/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\\.\u0007\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 ';'
+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 --