Skip to content

Commit d134165

Browse files
committed
Add tests for variable declarations in switch statements without
brackets
1 parent a98ece8 commit d134165

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* generated by Svelte vX.Y.Z */
2+
import { SvelteComponent, init, safe_not_equal } from "svelte/internal";
3+
4+
function instance($$self) {
5+
switch (1) {
6+
case 1:
7+
const value = Math.random();
8+
}
9+
10+
return [];
11+
}
12+
13+
class Component extends SvelteComponent {
14+
constructor(options) {
15+
super();
16+
init(this, options, instance, null, safe_not_equal, {});
17+
}
18+
}
19+
20+
export default Component;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
switch (1) {
3+
case 1:
4+
const value = Math.random();
5+
}
6+
</script>
7+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default {
2+
props: {
3+
q: 0
4+
},
5+
6+
html: '<p>3</p>',
7+
8+
test({ assert, component, target }) {
9+
component.q = 1;
10+
assert.htmlEqual(target.innerHTML, '<p>4</p>');
11+
component.q = 2;
12+
assert.htmlEqual(target.innerHTML, '<p>5</p>');
13+
component.q = 3;
14+
assert.htmlEqual(target.innerHTML, '<p>6</p>');
15+
}
16+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script>
2+
export let q;
3+
let p = 3;
4+
$: {
5+
switch (q) {
6+
case 1:
7+
let value = Math.floor(Math.random()); // gives 0
8+
p = 4 + value;
9+
break;
10+
case 2:
11+
var number = Math.ceil(Math.random()); // gives 1
12+
p = 4 + number;
13+
break;
14+
case 3:
15+
const foo = 2; // gives 2
16+
p = 4 + foo;
17+
break;
18+
}
19+
}
20+
</script>
21+
22+
<p>
23+
{p}
24+
</p>
25+

0 commit comments

Comments
 (0)