Add support for switch/case/default statements.
This commit is contained in:
22
unittests/switch_break.chai
Normal file
22
unittests/switch_break.chai
Normal file
@@ -0,0 +1,22 @@
|
||||
var total = 0;
|
||||
|
||||
switch(2) {
|
||||
case (1) {
|
||||
total += 1;
|
||||
break;
|
||||
}
|
||||
case (2) {
|
||||
total += 2;
|
||||
break;
|
||||
}
|
||||
case (3) {
|
||||
total += 4;
|
||||
break;
|
||||
}
|
||||
case (4) {
|
||||
total += 8;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert_equal(total, 2)
|
18
unittests/switch_default.chai
Normal file
18
unittests/switch_default.chai
Normal file
@@ -0,0 +1,18 @@
|
||||
var total = 0;
|
||||
|
||||
switch(2) {
|
||||
case (1) {
|
||||
total += 1;
|
||||
}
|
||||
case (3) {
|
||||
total += 4;
|
||||
}
|
||||
case (4) {
|
||||
total += 8;
|
||||
}
|
||||
default {
|
||||
total += 16;
|
||||
}
|
||||
}
|
||||
|
||||
assert_equal(total, 16)
|
18
unittests/switch_fallthru.chai
Normal file
18
unittests/switch_fallthru.chai
Normal file
@@ -0,0 +1,18 @@
|
||||
var total = 0;
|
||||
|
||||
switch(2) {
|
||||
case (1) {
|
||||
total += 1;
|
||||
}
|
||||
case (2) {
|
||||
total += 2;
|
||||
}
|
||||
case (3) {
|
||||
total += 4;
|
||||
}
|
||||
case (4) {
|
||||
total += 8;
|
||||
}
|
||||
}
|
||||
|
||||
assert_equal(total, 14);
|
19
unittests/switch_fallthru_and_break.chai
Normal file
19
unittests/switch_fallthru_and_break.chai
Normal file
@@ -0,0 +1,19 @@
|
||||
var total = 0;
|
||||
|
||||
switch(2) {
|
||||
case (1) {
|
||||
total += 1;
|
||||
}
|
||||
case (2) {
|
||||
total += 2;
|
||||
}
|
||||
case (3) {
|
||||
total += 4;
|
||||
break;
|
||||
}
|
||||
case (4) {
|
||||
total += 8;
|
||||
}
|
||||
}
|
||||
|
||||
assert_equal(total, 6)
|
Reference in New Issue
Block a user