From ea997c89f7ea59db0164c79ac0fda5b607754753 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 25 Sep 2019 13:44:31 +0200 Subject: Pattern matching support (switch): single value implementation --- tests/switch/buildfile | 5 ++ tests/switch/testscript | 134 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 tests/switch/buildfile create mode 100644 tests/switch/testscript (limited to 'tests/switch') diff --git a/tests/switch/buildfile b/tests/switch/buildfile new file mode 100644 index 0000000..0fe074a --- /dev/null +++ b/tests/switch/buildfile @@ -0,0 +1,5 @@ +# file : tests/switch/buildfile +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +./: testscript $b diff --git a/tests/switch/testscript b/tests/switch/testscript new file mode 100644 index 0000000..d59b33d --- /dev/null +++ b/tests/switch/testscript @@ -0,0 +1,134 @@ +# file : tests/switch/testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Test switch. + +.include ../common.testscript + +: basics +: +$* <>EOO +for i: 1 2 3 +{ + switch $i + { + case 1 + print 1 + case 2 + { + print 2 + } + default + print default + } +} +EOI +1 +2 +default +EOO + +: empty +: +$* <>EOO +switch 1 +{ + default + print default +} +EOI +default +EOO + +: nested +: +$* <>EOO +switch 1 +{ + case 1 + { + switch 2 + { + case 2 + print 2 + case 1 + assert + } + } + case 2 + assert +} +EOI +2 +EOO + +: default-before-case +: +$* <>EOE != 0 +switch 1 +{ + default + x = 1 + case 2 + x = 2 +} +EOI +:5:3: error: case after default + info: default must be last in the switch block +EOE + +: default-multiple +: +$* <>EOE != 0 +switch 1 +{ + default + x = 1 + default + x = 2 +} +EOI +:5:3: error: multiple defaults +EOE + +: empty-switch +: +$* <>EOE != 0 +switch +{ +} +EOI +:1:7: error: expected switch expression instead of +EOE + +: empty-case +: +$* <>EOE != 0 +switch 1 +{ + case + x = 1 +} +EOI +:3:7: error: expected case pattern instead of +EOE + +: junk-in-switch +: +$* <>EOE != 0 +switch 1 +{ + x = 0 +} +EOI +:3:3: error: expected case or default instead of 'x' +EOE -- cgit v1.1