Prelude of builtin functions #7

Merged
defunkt merged 45 commits from prelude into main 2025-10-29 20:15:37 +00:00
3 changed files with 192 additions and 0 deletions
Showing only changes of commit 34c1177636 - Show all commits

1
packages/ReefVM Submodule

@ -0,0 +1 @@
Subproject commit 97b6722a113417398a1c47d583bfe07a906f87a0

View File

@ -33,4 +33,64 @@ describe('array literals', () => {
three
]`).toEvaluateTo(['one', 'two', 'three'])
})
test('empty arrays', () => {
expect('[]').toEvaluateTo([])
})
test('mixed types', () => {
expect("[1 'two' three true null]").toEvaluateTo([1, 'two', 'three', true, null])
})
test('semicolons as separators', () => {
expect('[1; 2; 3]').toEvaluateTo([1, 2, 3])
})
test('expressions in arrays', () => {
expect('[(1 + 2) (3 * 4)]').toEvaluateTo([3, 12])
})
test('mixed separators - spaces and newlines', () => {
expect(`[1 2
3 4]`).toEvaluateTo([1, 2, 3, 4])
})
test('mixed separators - spaces and semicolons', () => {
expect('[1 2; 3 4]').toEvaluateTo([1, 2, 3, 4])
})
test('empty lines within arrays', () => {
expect(`[1
2]`).toEvaluateTo([1, 2])
})
test('comments within arrays', () => {
expect(`[1 # first
2 # second
]`).toEvaluateTo([1, 2])
})
test('complex nested multiline', () => {
expect(`[
[1 2]
[3 4]
[5 6]
]`).toEvaluateTo([[1, 2], [3, 4], [5, 6]])
})
test('boolean and null literals', () => {
expect('[true false null]').toEvaluateTo([true, false, null])
})
test('regex literals', () => {
expect('[//[0-9]+//]').toEvaluateTo([/[0-9]+/])
})
test('trailing newlines', () => {
expect(`[
1
2
]`).toEvaluateTo([1, 2])
})
})

View File

@ -69,4 +69,135 @@ describe('array literals', () => {
Identifier three
`)
})
test('empty arrays', () => {
expect('[]').toMatchTree(`
Array []
`)
})
test('mixed types', () => {
expect("[1 'two' three true null]").toMatchTree(`
Array
Number 1
String
StringFragment two
Identifier three
Boolean true
Null null
`)
})
test('semicolons as separators', () => {
expect('[1; 2; 3]').toMatchTree(`
Array
Number 1
Number 2
Number 3
`)
})
test('expressions in arrays', () => {
expect('[(1 + 2) (3 * 4)]').toMatchTree(`
Array
ParenExpr
BinOp
Number 1
Plus +
Number 2
ParenExpr
BinOp
Number 3
Star *
Number 4
`)
})
test('mixed separators - spaces and newlines', () => {
expect(`[1 2
3 4]`).toMatchTree(`
Array
Number 1
Number 2
Number 3
Number 4
`)
})
test('mixed separators - spaces and semicolons', () => {
expect('[1 2; 3 4]').toMatchTree(`
Array
Number 1
Number 2
Number 3
Number 4
`)
})
test('empty lines within arrays', () => {
expect(`[1
2]`).toMatchTree(`
Array
Number 1
Number 2
`)
})
test('comments within arrays', () => {
expect(`[ # something...
1 # first
2 # second
]`).toMatchTree(`
Array
Number 1
Number 2
`)
})
test('complex nested multiline', () => {
expect(`[
[1 2]
[3 4]
[5 6]
]`).toMatchTree(`
Array
Array
Number 1
Number 2
Array
Number 3
Number 4
Array
Number 5
Number 6
`)
})
test('boolean and null literals', () => {
expect('[true false null]').toMatchTree(`
Array
Boolean true
Boolean false
Null null
`)
})
test('regex literals', () => {
expect('[//[0-9]+//]').toMatchTree(`
Array
Regex //[0-9]+//
`)
})
test('trailing newlines', () => {
expect(`[
1
2
]`).toMatchTree(`
Array
Number 1
Number 2
`)
})
})