mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +00:00
Libraries: Move to Userland/Libraries/
This commit is contained in:
parent
dc28c07fa5
commit
13d7c09125
1857 changed files with 266 additions and 274 deletions
78
Userland/Libraries/LibJS/Tests/switch-basic.js
Normal file
78
Userland/Libraries/LibJS/Tests/switch-basic.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
describe("basic switch tests", () => {
|
||||
test("string case does not match number target", () => {
|
||||
switch (1 + 2) {
|
||||
case "3":
|
||||
expect().fail();
|
||||
case 3:
|
||||
return;
|
||||
case 5:
|
||||
case 1:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
expect().fail();
|
||||
});
|
||||
|
||||
test("string concatenation in target", () => {
|
||||
var a = "foo";
|
||||
|
||||
switch (a + "bar") {
|
||||
case 1:
|
||||
expect().fail();
|
||||
case "foobar":
|
||||
case 2:
|
||||
return;
|
||||
}
|
||||
expect().fail();
|
||||
});
|
||||
|
||||
test("default", () => {
|
||||
switch (100) {
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
expect().fail();
|
||||
});
|
||||
|
||||
test("return from switch statement", () => {
|
||||
function foo(value) {
|
||||
switch (value) {
|
||||
case 42:
|
||||
return "return from 'case 42'";
|
||||
default:
|
||||
return "return from 'default'";
|
||||
}
|
||||
}
|
||||
expect(foo(42)).toBe("return from 'case 42'");
|
||||
expect(foo(43)).toBe("return from 'default'");
|
||||
});
|
||||
|
||||
test("continue from switch statement", () => {
|
||||
let i = 0;
|
||||
for (; i < 5; ++i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
continue;
|
||||
expect().fail();
|
||||
case 0:
|
||||
expect().fail();
|
||||
default:
|
||||
continue;
|
||||
expect().fail();
|
||||
}
|
||||
expect().fail();
|
||||
}
|
||||
expect(i).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("syntax errors", () => {
|
||||
expect("switch () {}").not.toEval();
|
||||
expect("switch (foo) { bar }").not.toEval();
|
||||
expect("switch (foo) { default: default: }").not.toEval();
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue