From dd434b62e588651cf70d9cfdd4509dc09279a8c7 Mon Sep 17 00:00:00 2001 From: Nguyen Tran Date: Mon, 6 Mar 2023 20:14:49 -0500 Subject: [PATCH] Object destructuring literal properties test on const tags --- .../_config.js | 19 ++++++++++++ .../main.svelte | 23 ++++++++++++++ .../_config.js | 30 +++++++++++++++++++ .../main.svelte | 19 ++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 test/runtime/samples/const-tag-await-then-destructuring-literals/_config.js create mode 100644 test/runtime/samples/const-tag-await-then-destructuring-literals/main.svelte create mode 100644 test/runtime/samples/const-tag-each-destructure-literals/_config.js create mode 100644 test/runtime/samples/const-tag-each-destructure-literals/main.svelte diff --git a/test/runtime/samples/const-tag-await-then-destructuring-literals/_config.js b/test/runtime/samples/const-tag-await-then-destructuring-literals/_config.js new file mode 100644 index 0000000000..cb40e7c456 --- /dev/null +++ b/test/runtime/samples/const-tag-await-then-destructuring-literals/_config.js @@ -0,0 +1,19 @@ +export default { + html: '
12 120 70, 30+4=34
', + async test({ component, target, assert }) { + component.promise1 = Promise.resolve({width: 5, height: 6}); + component.promise2 = Promise.reject({width: 6, height: 7}); + + await Promise.resolve(); + assert.htmlEqual(target.innerHTML, ` +
30 300 110, 50+6=56
+
42 420 130, 60+7=67
+ `); + + component.constant = 20; + assert.htmlEqual(target.innerHTML, ` +
30 600 220, 100+6=106
+
42 840 260, 120+7=127
+ `); + } +}; diff --git a/test/runtime/samples/const-tag-await-then-destructuring-literals/main.svelte b/test/runtime/samples/const-tag-await-then-destructuring-literals/main.svelte new file mode 100644 index 0000000000..0875820e4a --- /dev/null +++ b/test/runtime/samples/const-tag-await-then-destructuring-literals/main.svelte @@ -0,0 +1,23 @@ + + +{#await promise1 then { width, height }} + {@const {'the-area': area, 'the-volume': volume} = calculate(width, height, constant)} + {@const perimeter = (width + height) * constant} + {@const { 0: _width, 1: _height, 2: sum } = [width * constant, height, width * constant + height]} +
{area} {volume} {perimeter}, {_width}+{_height}={sum}
+{/await} + +{#await promise2 catch { width, height }} + {@const {'the-area': area, 'the-volume': volume} = calculate(width, height, constant)} + {@const perimeter = (width + height) * constant} + {@const { 0: _width, 1: _height, 2: sum } = [width * constant, height, width * constant + height]} +
{area} {volume} {perimeter}, {_width}+{_height}={sum}
+{/await} diff --git a/test/runtime/samples/const-tag-each-destructure-literals/_config.js b/test/runtime/samples/const-tag-each-destructure-literals/_config.js new file mode 100644 index 0000000000..00f8b31540 --- /dev/null +++ b/test/runtime/samples/const-tag-each-destructure-literals/_config.js @@ -0,0 +1,30 @@ +export default { + html: ` +
12 120 70, 30+4=34
+
35 350 120, 50+7=57
+
48 480 140, 60+8=68
+ `, + async test({ component, target, assert }) { + component.constant = 20; + + assert.htmlEqual(target.innerHTML, ` +
12 240 140, 60+4=64
+
35 700 240, 100+7=107
+
48 960 280, 120+8=128
+ `); + + component.boxes = [ + {width: 3, height: 4}, + {width: 4, height: 5}, + {width: 5, height: 6}, + {width: 6, height: 7} + ]; + + assert.htmlEqual(target.innerHTML, ` +
12 240 140, 60+4=64
+
20 400 180, 80+5=85
+
30 600 220, 100+6=106
+
42 840 260, 120+7=127
+ `); + } +}; diff --git a/test/runtime/samples/const-tag-each-destructure-literals/main.svelte b/test/runtime/samples/const-tag-each-destructure-literals/main.svelte new file mode 100644 index 0000000000..b0fc221ec9 --- /dev/null +++ b/test/runtime/samples/const-tag-each-destructure-literals/main.svelte @@ -0,0 +1,19 @@ + + +{#each boxes as { width, height }} + {@const { 'the-area': area, 'the-volume': volume } = calculate(width, height, constant)} + {@const perimeter = (width + height) * constant} + {@const { 2: sum, 0: _width, 1: _height } = [width * constant, height, width * constant + height]} +
{area} {volume} {perimeter}, {_width}+{_height}={sum}
+{/each}