56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
import { expect, describe, test } from 'bun:test'
|
|
|
|
describe('Array destructuring', () => {
|
|
test('parses array pattern with two variables', () => {
|
|
expect('[ a b ] = [ 1 2 3 4]').toMatchTree(`
|
|
Assign
|
|
Array
|
|
Identifier a
|
|
Identifier b
|
|
Eq =
|
|
Array
|
|
Number 1
|
|
Number 2
|
|
Number 3
|
|
Number 4`)
|
|
})
|
|
|
|
test('parses array pattern with one variable', () => {
|
|
expect('[ x ] = [ 42 ]').toMatchTree(`
|
|
Assign
|
|
Array
|
|
Identifier x
|
|
Eq =
|
|
Array
|
|
Number 42`)
|
|
})
|
|
|
|
test('parses array pattern with emoji identifiers', () => {
|
|
expect('[ 🚀 💎 ] = [ 1 2 ]').toMatchTree(`
|
|
Assign
|
|
Array
|
|
Identifier 🚀
|
|
Identifier 💎
|
|
Eq =
|
|
Array
|
|
Number 1
|
|
Number 2`)
|
|
})
|
|
|
|
test('works with dotget', () => {
|
|
expect('[ a ] = [ [1 2 3] ]; a.1').toMatchTree(`
|
|
Assign
|
|
Array
|
|
Identifier a
|
|
Eq =
|
|
Array
|
|
Array
|
|
Number 1
|
|
Number 2
|
|
Number 3
|
|
FunctionCallOrIdentifier
|
|
DotGet
|
|
IdentifierBeforeDot a
|
|
Number 1`)
|
|
})
|
|
}) |