refactor: restructure list/map compilation loops and extract syntax error tests

- Convert list() and map() compiler functions from if/do-while to do-while loops
- Remove redundant empty literal handling by breaking on right bracket/brace
- Add new test files for duplicate comma, duplicate trailing comma, and empty list/map with comma
- Expand newlines test to cover trailing comma and empty list/map cases
- Simplify trailing_comma tests by removing inline syntax error checks
- Update Test.fail() to handle variable arguments without kwargs
This commit is contained in:
Bob Nystrom
2015-08-31 14:23:36 +00:00
parent d608a03244
commit 075f487b6e
12 changed files with 82 additions and 51 deletions
+1
View File
@@ -0,0 +1 @@
[1,,2] // expect error
@@ -0,0 +1 @@
[1,,] // expect error
@@ -0,0 +1 @@
[,] // expect error
+14
View File
@@ -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 -9
View File
@@ -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.