aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-09-27 13:55:07 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-09-30 15:30:45 +0200
commit12268f7741ba73c75a73fafb6063f1393e485aae (patch)
treec80fe4918c18702f6cb199c9016366338f8f5061 /tests
parente59c2bc979293d8cdea3f9733ecd59c080fce63c (diff)
Add support for custom match/extract functions in switch expression
Diffstat (limited to 'tests')
-rw-r--r--tests/switch/testscript113
1 files changed, 113 insertions, 0 deletions
diff --git a/tests/switch/testscript b/tests/switch/testscript
index 1399df0..c8adaf0 100644
--- a/tests/switch/testscript
+++ b/tests/switch/testscript
@@ -68,6 +68,83 @@ EOI
d
EOO
+: basics-matcher
+:
+$* <<EOI >>EOO
+for i: 123 abc
+{
+ switch $i: regex.match
+ {
+ case '[0-9]+'
+ print n
+ case '[a-z]+'
+ print a
+ }
+}
+EOI
+n
+a
+EOO
+
+: basics-matcher-arg
+:
+$* <<EOI >>EOO
+for i: abc ABC aBC
+{
+ switch $i: regex.match icase
+ {
+ case '[a-z]+'
+ print a
+ }
+}
+EOI
+a
+a
+a
+EOO
+
+: basics-matcher-multiple
+:
+$* <<EOI >>EOO
+for i: 123 abc
+{
+ switch $i: regex.match, $i: regex.match
+ {
+ case '[0-9]+', '[0-9]+'
+ print nn
+ case '[0-9]+', '[a-z]+'
+ print na
+ case '[a-z]+', '[0-9]+'
+ print an
+ case '[a-z]+', '[a-z]+'
+ print aa
+ }
+}
+EOI
+nn
+aa
+EOO
+
+#\
+: basics-extractor
+:
+$* <<EOI >>EOO
+for i: 123 abc
+{
+ switch $i: regex.extract
+ {
+ case '([0-9]+)'
+ print n
+ default
+ print d
+ }
+}
+EOI
+n
+d
+EOO
+#\
+
: empty
:
$* <<EOI
@@ -199,3 +276,39 @@ switch 1
EOI
<stdin>:3:11: error: more patterns than switch expressions
EOE
+
+: matcher-missing
+:
+$* <<EOI 2>>EOE != 0
+switch 1:
+{
+ case 1
+ x = 1
+}
+EOI
+<stdin>:1:10: error: expected function name instead of <newline>
+EOE
+
+: matcher-bad-name
+:
+$* <<EOI 2>>EOE != 0
+switch 1: file{x}
+{
+ case 1
+ x = 1
+}
+EOI
+<stdin>:1:11: error: function name expected instead of file{x}
+EOE
+
+: matcher-unknown
+:
+$* <<EOI 2>>EOE != 0
+switch 1: no_such_matcher
+{
+ case 1
+ x = 1
+}
+EOI
+<stdin>:3:8: error: unmatched call to no_such_matcher(<untyped>, <untyped>)
+EOE