From 12268f7741ba73c75a73fafb6063f1393e485aae Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 27 Sep 2019 13:55:07 +0200 Subject: Add support for custom match/extract functions in switch expression --- tests/switch/testscript | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) (limited to 'tests/switch') 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 +: +$* <>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 +: +$* <>EOO +for i: abc ABC aBC +{ + switch $i: regex.match icase + { + case '[a-z]+' + print a + } +} +EOI +a +a +a +EOO + +: basics-matcher-multiple +: +$* <>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 +: +$* <>EOO +for i: 123 abc +{ + switch $i: regex.extract + { + case '([0-9]+)' + print n + default + print d + } +} +EOI +n +d +EOO +#\ + : empty : $* <:3:11: error: more patterns than switch expressions EOE + +: matcher-missing +: +$* <>EOE != 0 +switch 1: +{ + case 1 + x = 1 +} +EOI +:1:10: error: expected function name instead of +EOE + +: matcher-bad-name +: +$* <>EOE != 0 +switch 1: file{x} +{ + case 1 + x = 1 +} +EOI +:1:11: error: function name expected instead of file{x} +EOE + +: matcher-unknown +: +$* <>EOE != 0 +switch 1: no_such_matcher +{ + case 1 + x = 1 +} +EOI +:3:8: error: unmatched call to no_such_matcher(, ) +EOE -- cgit v1.1