mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
Reorganize trailing comma code a bit.
- Split out syntax error tests. - Avoid redundant handling of empty literals.
This commit is contained in:
1
test/language/list/duplicate_comma.wren
Normal file
1
test/language/list/duplicate_comma.wren
Normal file
@ -0,0 +1 @@
|
||||
[1,,2] // expect error
|
||||
1
test/language/list/duplicate_trailing_comma.wren
Normal file
1
test/language/list/duplicate_trailing_comma.wren
Normal file
@ -0,0 +1 @@
|
||||
[1,,] // expect error
|
||||
1
test/language/list/empty_list_with_comma.wren
Normal file
1
test/language/list/empty_list_with_comma.wren
Normal file
@ -0,0 +1 @@
|
||||
[,] // expect error
|
||||
@ -8,3 +8,17 @@ var list = [
|
||||
|
||||
IO.print(list[0]) // expect: a
|
||||
IO.print(list[1]) // expect: b
|
||||
|
||||
// Newline after trailing comma.
|
||||
list = ["c",
|
||||
|
||||
]
|
||||
|
||||
IO.print(list[0]) // expect: c
|
||||
|
||||
// Newline in empty list.
|
||||
list = [
|
||||
|
||||
]
|
||||
|
||||
IO.print(list.count) // expect: 0
|
||||
|
||||
@ -1,12 +1,4 @@
|
||||
var list = [
|
||||
"a",
|
||||
"b",
|
||||
]
|
||||
var list = ["a", "b",]
|
||||
|
||||
IO.print(list[0]) // expect: a
|
||||
IO.print(list[1]) // expect: b
|
||||
|
||||
// Invalid syntax
|
||||
IO.print(new Fiber { Meta.eval("[,]") }.try()) // expect: Could not compile source code.
|
||||
IO.print(new Fiber { Meta.eval("[1,,]") }.try()) // expect: Could not compile source code.
|
||||
IO.print(new Fiber { Meta.eval("[1,,2]") }.try()) // expect: Could not compile source code.
|
||||
|
||||
1
test/language/map/duplicate_comma.wren
Normal file
1
test/language/map/duplicate_comma.wren
Normal file
@ -0,0 +1 @@
|
||||
{1:1,,2:2} // expect error
|
||||
1
test/language/map/duplicate_trailing_comma.wren
Normal file
1
test/language/map/duplicate_trailing_comma.wren
Normal file
@ -0,0 +1 @@
|
||||
{1:1,,} // expect error
|
||||
1
test/language/map/empty_map_with_comma.wren
Normal file
1
test/language/map/empty_map_with_comma.wren
Normal file
@ -0,0 +1 @@
|
||||
{,} // expect error
|
||||
27
test/language/map/newlines.wren
Normal file
27
test/language/map/newlines.wren
Normal file
@ -0,0 +1,27 @@
|
||||
// Allow after '{', ':', and ',', and before ']'.
|
||||
var map = {
|
||||
|
||||
"a":
|
||||
|
||||
"a value",
|
||||
|
||||
"b": "b value"
|
||||
|
||||
}
|
||||
|
||||
IO.print(map["a"]) // expect: a value
|
||||
IO.print(map["b"]) // expect: b value
|
||||
|
||||
// Newline after trailing comma.
|
||||
map = {"c": "c value",
|
||||
|
||||
}
|
||||
|
||||
IO.print(map["c"]) // expect: c value
|
||||
|
||||
// Newline in empty map.
|
||||
map = {
|
||||
|
||||
}
|
||||
|
||||
IO.print(map.count) // expect: 0
|
||||
@ -5,9 +5,3 @@ var map = {
|
||||
|
||||
IO.print(map["a"]) // expect: 1
|
||||
IO.print(map["b"]) // expect: 2
|
||||
|
||||
// Invalid syntax
|
||||
// Parentheses are necessary to have these interpret as maps and not as blocks.
|
||||
IO.print(new Fiber { Meta.eval("({,})") }.try()) // expect: Could not compile source code.
|
||||
IO.print(new Fiber { Meta.eval("({1:1,,})") }.try()) // expect: Could not compile source code.
|
||||
IO.print(new Fiber { Meta.eval("({1:1,,2:2})") }.try()) // expect: Could not compile source code.
|
||||
|
||||
Reference in New Issue
Block a user