diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2019-09-25 13:44:31 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2019-09-30 15:29:50 +0200 |
commit | ea997c89f7ea59db0164c79ac0fda5b607754753 (patch) | |
tree | 2067c898434d9da4f6cadf0e50737f930b299616 /tests/switch | |
parent | c595aac0142436f64ada4f5412b821bfcc6db008 (diff) |
Pattern matching support (switch): single value implementation
Diffstat (limited to 'tests/switch')
-rw-r--r-- | tests/switch/buildfile | 5 | ||||
-rw-r--r-- | tests/switch/testscript | 134 |
2 files changed, 139 insertions, 0 deletions
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 +: +$* <<EOI >>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 +: +$* <<EOI +switch 1 +{ +} +EOI + +: default +: +$* <<EOI >>EOO +switch 1 +{ + default + print default +} +EOI +default +EOO + +: nested +: +$* <<EOI >>EOO +switch 1 +{ + case 1 + { + switch 2 + { + case 2 + print 2 + case 1 + assert + } + } + case 2 + assert +} +EOI +2 +EOO + +: default-before-case +: +$* <<EOI 2>>EOE != 0 +switch 1 +{ + default + x = 1 + case 2 + x = 2 +} +EOI +<stdin>:5:3: error: case after default + info: default must be last in the switch block +EOE + +: default-multiple +: +$* <<EOI 2>>EOE != 0 +switch 1 +{ + default + x = 1 + default + x = 2 +} +EOI +<stdin>:5:3: error: multiple defaults +EOE + +: empty-switch +: +$* <<EOI 2>>EOE != 0 +switch +{ +} +EOI +<stdin>:1:7: error: expected switch expression instead of <newline> +EOE + +: empty-case +: +$* <<EOI 2>>EOE != 0 +switch 1 +{ + case + x = 1 +} +EOI +<stdin>:3:7: error: expected case pattern instead of <newline> +EOE + +: junk-in-switch +: +$* <<EOI 2>>EOE != 0 +switch 1 +{ + x = 0 +} +EOI +<stdin>:3:3: error: expected case or default instead of 'x' +EOE |