summaryrefslogtreecommitdiff
path: root/usr/austin/eval/stmt_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'usr/austin/eval/stmt_test.go')
-rw-r--r--usr/austin/eval/stmt_test.go303
1 files changed, 152 insertions, 151 deletions
diff --git a/usr/austin/eval/stmt_test.go b/usr/austin/eval/stmt_test.go
index 9a62b2e0f..0324a40f1 100644
--- a/usr/austin/eval/stmt_test.go
+++ b/usr/austin/eval/stmt_test.go
@@ -18,45 +18,45 @@ var stmtTests = []test {
// Parallel assignment
Val2("a, b := 1, 2", "a", 1, "b", 2),
Val2("a, i := 1, 2", "a", 1, "i", 2),
- SErr("a, i := 1, f", opTypes),
+ CErr("a, i := 1, f", opTypes),
// TODO(austin) The parser produces an error message for this
// one that's inconsistent with the errors I give for other
// things
- //SErr("a, b := 1, 2, 3", "too many"),
- SErr("a, b := 1, 2, 3", "arity"),
- SErr("a := 1, 2", "too many"),
- SErr("a, b := 1", "not enough"),
+ //CErr("a, b := 1, 2, 3", "too many"),
+ CErr("a, b := 1, 2, 3", "arity"),
+ CErr("a := 1, 2", "too many"),
+ CErr("a, b := 1", "not enough"),
// Mixed declarations
- SErr("i := 1", atLeastOneDecl),
- SErr("i, u := 1, 2", atLeastOneDecl),
+ CErr("i := 1", atLeastOneDecl),
+ CErr("i, u := 1, 2", atLeastOneDecl),
Val2("i, x := 2, f", "i", 2, "x", 1.0),
// Various errors
- SErr("1 := 2", "left side of := must be a name"),
- SErr("c, a := 1, 1", "cannot assign"),
+ CErr("1 := 2", "left side of := must be a name"),
+ CErr("c, a := 1, 1", "cannot assign"),
// Unpacking
Val2("x, y := oneTwo()", "x", 1, "y", 2),
- SErr("x := oneTwo()", "too many"),
- SErr("x, y, z := oneTwo()", "not enough"),
- SErr("x, y := oneTwo(), 2", "multi-valued"),
- SErr("x := oneTwo()+2", opTypes),
+ CErr("x := oneTwo()", "too many"),
+ CErr("x, y, z := oneTwo()", "not enough"),
+ CErr("x, y := oneTwo(), 2", "multi-valued"),
+ CErr("x := oneTwo()+2", opTypes),
// TOOD(austin) This error message is weird
- SErr("x := void()", "not enough"),
+ CErr("x := void()", "not enough"),
// Placeholders
- SErr("x := 1+\"x\"; i=x+1", opTypes),
+ CErr("x := 1+\"x\"; i=x+1", opTypes),
// Assignment
Val1("i = 2", "i", 2),
Val1("(i) = 2", "i", 2),
- SErr("1 = 2", "cannot assign"),
- SErr("1-1 = 2", "- expression"),
+ CErr("1 = 2", "cannot assign"),
+ CErr("1-1 = 2", "- expression"),
Val1("i = 2.0", "i", 2),
- SErr("i = 2.2", constantTruncated),
- SErr("u = -2", constantUnderflows),
- SErr("i = f", opTypes),
- SErr("i, u = 0, f", opTypes),
- SErr("i, u = 0, f", "value 2"),
+ CErr("i = 2.2", constantTruncated),
+ CErr("u = -2", constantUnderflows),
+ CErr("i = f", opTypes),
+ CErr("i, u = 0, f", opTypes),
+ CErr("i, u = 0, f", "value 2"),
Val2("i, i2 = i2, i", "i", 2, "i2", 1),
- SErr("c = 1", "cannot assign"),
+ CErr("c = 1", "cannot assign"),
Val1("x := &i; *x = 2", "i", 2),
@@ -65,65 +65,66 @@ var stmtTests = []test {
Val1("aai = aai2", "aai", varray{ varray{5, 6}, varray{7, 8} }),
// Assignment conversions
- SRuns("var sl []int; sl = &ai"),
- SErr("type ST []int; type AT *[2]int; var x AT = &ai; var y ST = x", opTypes),
- SRuns("type ST []int; var y ST = &ai"),
- SRuns("type AT *[2]int; var x AT = &ai; var y []int = x"),
+ Run("var sl []int; sl = &ai"),
+ CErr("type ST []int; type AT *[2]int; var x AT = &ai; var y ST = x", opTypes),
+ Run("type ST []int; var y ST = &ai"),
+ Run("type AT *[2]int; var x AT = &ai; var y []int = x"),
// Op-assignment
Val1("i += 2", "i", 3),
+ Val("i", 1),
Val1("f += 2", "f", 3.0),
- SErr("2 += 2", "cannot assign"),
- SErr("i, j += 2", "cannot be combined"),
- SErr("i += 2, 3", "cannot be combined"),
+ CErr("2 += 2", "cannot assign"),
+ CErr("i, j += 2", "cannot be combined"),
+ CErr("i += 2, 3", "cannot be combined"),
Val2("s2 := s; s += \"def\"", "s2", "abc", "s", "abcdef"),
- SErr("s += 1", opTypes),
+ CErr("s += 1", opTypes),
// Single evaluation
Val2("ai[func()int{i+=1;return 0}()] *= 3; i2 = ai[0]", "i", 2, "i2", 3),
// Type declarations
// Identifiers
- SRuns("type T int"),
- SErr("type T x", "undefined"),
- SErr("type T c", "constant"),
- SErr("type T i", "variable"),
- SErr("type T T", "recursive"),
- SErr("type T x; type U T; var v U; v = 1", "undefined"),
+ Run("type T int"),
+ CErr("type T x", "undefined"),
+ CErr("type T c", "constant"),
+ CErr("type T i", "variable"),
+ CErr("type T T", "recursive"),
+ CErr("type T x; type U T; var v U; v = 1", "undefined"),
// Pointer types
- SRuns("type T *int"),
- SRuns("type T *T"),
+ Run("type T *int"),
+ Run("type T *T"),
// Array types
- SRuns("type T [5]int"),
- SRuns("type T [c+42/2]int"),
- SRuns("type T [2.0]int"),
- SErr("type T [i]int", "constant expression"),
- SErr("type T [2.5]int", constantTruncated),
- SErr("type T [-1]int", "negative"),
- SErr("type T [2]T", "recursive"),
+ Run("type T [5]int"),
+ Run("type T [c+42/2]int"),
+ Run("type T [2.0]int"),
+ CErr("type T [i]int", "constant expression"),
+ CErr("type T [2.5]int", constantTruncated),
+ CErr("type T [-1]int", "negative"),
+ CErr("type T [2]T", "recursive"),
// Struct types
- SRuns("type T struct { a int; b int }"),
- SRuns("type T struct { a int; int }"),
- SRuns("type T struct { x *T }"),
- SRuns("type T int; type U struct { T }"),
- SErr("type T *int; type U struct { T }", "embedded.*pointer"),
- SErr("type T *struct { T }", "embedded.*pointer"),
- SErr("type T struct { a int; a int }", " a .*redeclared.*:1:17"),
- SErr("type T struct { int; int }", "int .*redeclared.*:1:17"),
- SErr("type T struct { int int; int }", "int .*redeclared.*:1:17"),
- SRuns("type T struct { x *struct { T } }"),
- SErr("type T struct { x struct { T } }", "recursive"),
- SErr("type T struct { x }; type U struct { T }", "undefined"),
+ Run("type T struct { a int; b int }"),
+ Run("type T struct { a int; int }"),
+ Run("type T struct { x *T }"),
+ Run("type T int; type U struct { T }"),
+ CErr("type T *int; type U struct { T }", "embedded.*pointer"),
+ CErr("type T *struct { T }", "embedded.*pointer"),
+ CErr("type T struct { a int; a int }", " a .*redeclared.*:1:17"),
+ CErr("type T struct { int; int }", "int .*redeclared.*:1:17"),
+ CErr("type T struct { int int; int }", "int .*redeclared.*:1:17"),
+ Run("type T struct { x *struct { T } }"),
+ CErr("type T struct { x struct { T } }", "recursive"),
+ CErr("type T struct { x }; type U struct { T }", "undefined"),
// Function types
- SRuns("type T func()"),
- SRuns("type T func(a, b int) int"),
- SRuns("type T func(a, b int) (x int, y int)"),
- SRuns("type T func(a, a int) (a int, a int)"),
- SRuns("type T func(a, b int) (x, y int)"),
- SRuns("type T func(int, int) (int, int)"),
- SErr("type T func(x); type U T", "undefined"),
- SErr("type T func(a T)", "recursive"),
+ Run("type T func()"),
+ Run("type T func(a, b int) int"),
+ Run("type T func(a, b int) (x int, y int)"),
+ Run("type T func(a, a int) (a int, a int)"),
+ Run("type T func(a, b int) (x, y int)"),
+ Run("type T func(int, int) (int, int)"),
+ CErr("type T func(x); type U T", "undefined"),
+ CErr("type T func(a T)", "recursive"),
// Parens
- SRuns("type T (int)"),
+ Run("type T (int)"),
// Variable declarations
Val2("var x int", "i", 1, "x", 0),
@@ -131,15 +132,15 @@ var stmtTests = []test {
Val1("var x = 1.0", "x", 1.0),
Val1("var x int = 1.0", "x", 1),
// Placeholders
- SErr("var x foo; x = 1", "undefined"),
- SErr("var x foo = 1; x = 1", "undefined"),
+ CErr("var x foo; x = 1", "undefined"),
+ CErr("var x foo = 1; x = 1", "undefined"),
// Redeclaration
- SErr("var i, x int", " i .*redeclared"),
- SErr("var x int; var x int", " x .*redeclared.*:1:5"),
+ CErr("var i, x int", " i .*redeclared"),
+ CErr("var x int; var x int", " x .*redeclared.*:1:5"),
// Expression statements
- SErr("1-1", "expression statement"),
- SErr("1-1", "- expression"),
+ CErr("x := func(){ 1-1 }", "expression statement"),
+ CErr("x := func(){ 1-1 }", "- expression"),
Val1("fn(2)", "i", 1),
// IncDec statements
@@ -152,10 +153,10 @@ var stmtTests = []test {
// Single evaluation
Val2("ai[func()int{i+=1;return 0}()]++; i2 = ai[0]", "i", 2, "i2", 2),
// Operand types
- SErr("s++", opTypes),
- SErr("s++", "'\\+\\+'"),
- SErr("2++", "cannot assign"),
- SErr("c++", "cannot assign"),
+ CErr("s++", opTypes),
+ CErr("s++", "'\\+\\+'"),
+ CErr("2++", "cannot assign"),
+ CErr("c++", "cannot assign"),
// Function scoping
Val1("fn1 := func() { i=2 }; fn1()", "i", 2),
@@ -163,9 +164,9 @@ var stmtTests = []test {
Val2("fn1 := func() int { i=2; i:=3; i=4; return i }; x := fn1()", "i", 2, "x", 4),
// Basic returns
- SErr("fn1 := func() int {}", "return"),
- SRuns("fn1 := func() {}"),
- SErr("fn1 := func() (r int) {}", "return"),
+ CErr("fn1 := func() int {}", "return"),
+ Run("fn1 := func() {}"),
+ CErr("fn1 := func() (r int) {}", "return"),
Val1("fn1 := func() (r int) {return}; i = fn1()", "i", 0),
Val1("fn1 := func() (r int) {r = 2; return}; i = fn1()", "i", 2),
Val1("fn1 := func() (r int) {return 2}; i = fn1()", "i", 2),
@@ -173,40 +174,40 @@ var stmtTests = []test {
// Multi-valued returns
Val2("fn1 := func() (bool, int) {return true, 2}; x, y := fn1()", "x", true, "y", 2),
- SErr("fn1 := func() int {return}", "not enough values"),
- SErr("fn1 := func() int {return 1,2}", "too many values"),
- SErr("fn1 := func() {return 1}", "too many values"),
- SErr("fn1 := func() (int,int,int) {return 1,2}", "not enough values"),
+ CErr("fn1 := func() int {return}", "not enough values"),
+ CErr("fn1 := func() int {return 1,2}", "too many values"),
+ CErr("fn1 := func() {return 1}", "too many values"),
+ CErr("fn1 := func() (int,int,int) {return 1,2}", "not enough values"),
Val2("fn1 := func() (int, int) {return oneTwo()}; x, y := fn1()", "x", 1, "y", 2),
- SErr("fn1 := func() int {return oneTwo()}", "too many values"),
- SErr("fn1 := func() (int,int,int) {return oneTwo()}", "not enough values"),
+ CErr("fn1 := func() int {return oneTwo()}", "too many values"),
+ CErr("fn1 := func() (int,int,int) {return oneTwo()}", "not enough values"),
Val1("fn1 := func(x,y int) int {return x+y}; x := fn1(oneTwo())", "x", 3),
// Return control flow
Val2("fn1 := func(x *int) bool { *x = 2; return true; *x = 3; }; x := fn1(&i)", "i", 2, "x", true),
// Break/continue/goto/fallthrough
- SErr("break", "outside"),
- SErr("break foo", "break.*foo.*not defined"),
- SErr("continue", "outside"),
- SErr("continue foo", "continue.*foo.*not defined"),
- SErr("fallthrough", "outside"),
- SErr("goto foo", "foo.*not defined"),
- SErr(" foo: foo:;", "foo.*redeclared.*:1:2"),
+ CErr("break", "outside"),
+ CErr("break foo", "break.*foo.*not defined"),
+ CErr("continue", "outside"),
+ CErr("continue foo", "continue.*foo.*not defined"),
+ CErr("fallthrough", "outside"),
+ CErr("goto foo", "foo.*not defined"),
+ CErr(" foo: foo:;", "foo.*redeclared.*:1:2"),
Val1("i+=2; goto L; i+=4; L: i+=8", "i", 1+2+8),
// Return checking
- SErr("fn1 := func() int { goto L; return 1; L: }", "return"),
- SRuns("fn1 := func() int { L: goto L; i = 2 }"),
- SRuns("fn1 := func() int { return 1; L: goto L }"),
+ CErr("fn1 := func() int { goto L; return 1; L: }", "return"),
+ Run("fn1 := func() int { L: goto L; i = 2 }"),
+ Run("fn1 := func() int { return 1; L: goto L }"),
// Scope checking
- SRuns("fn1 := func() { { L: x:=1 } goto L }"),
- SErr("fn1 := func() { { x:=1; L: } goto L }", "into scope"),
- SErr("fn1 := func() { goto L; x:=1; L: }", "into scope"),
- SRuns("fn1 := func() { goto L; { L: x:=1 } }"),
- SErr("fn1 := func() { goto L; { x:=1; L: } }", "into scope"),
+ Run("fn1 := func() { { L: x:=1 } goto L }"),
+ CErr("fn1 := func() { { x:=1; L: } goto L }", "into scope"),
+ CErr("fn1 := func() { goto L; x:=1; L: }", "into scope"),
+ Run("fn1 := func() { goto L; { L: x:=1 } }"),
+ CErr("fn1 := func() { goto L; { x:=1; L: } }", "into scope"),
// Blocks
- SErr("fn1 := func() int {{}}", "return"),
+ CErr("fn1 := func() int {{}}", "return"),
Val1("fn1 := func() bool { { return true } }; b := fn1()", "b", true),
// If
@@ -227,44 +228,44 @@ var stmtTests = []test {
Val2("if true { i := 2 } else { i := 3 }; i2 = i", "i", 1, "i2", 1),
Val2("if false { i := 2 } else { i := 3 }; i2 = i", "i", 1, "i2", 1),
Val2("if false { i := 2 } else i := 3; i2 = i", "i", 1, "i2", 1),
- SErr("if true { x := 2 }; x = 4", undefined),
+ CErr("if true { x := 2 }; x = 4", undefined),
Val2("if i := 2; true { i2 = i; i := 3 }", "i", 1, "i2", 2),
Val2("if i := 2; false {} else { i2 = i; i := 3 }", "i", 1, "i2", 2),
// Return checking
- SRuns("fn1 := func() int { if true { return 1 } else { return 2 } }"),
- SRuns("fn1 := func() int { if true { return 1 } else return 2 }"),
- SErr("fn1 := func() int { if true { return 1 } else { } }", "return"),
- SErr("fn1 := func() int { if true { } else { return 1 } }", "return"),
- SErr("fn1 := func() int { if true { } else return 1 }", "return"),
- SErr("fn1 := func() int { if true { } else { } }", "return"),
- SErr("fn1 := func() int { if true { return 1 } }", "return"),
- SErr("fn1 := func() int { if true { } }", "return"),
- SRuns("fn1 := func() int { if true { }; return 1 }"),
- SErr("fn1 := func() int { if { } }", "return"),
- SErr("fn1 := func() int { if { } else { return 2 } }", "return"),
- SRuns("fn1 := func() int { if { return 1 } }"),
- SRuns("fn1 := func() int { if { return 1 } else { } }"),
- SRuns("fn1 := func() int { if { return 1 } else { } }"),
+ Run("fn1 := func() int { if true { return 1 } else { return 2 } }"),
+ Run("fn1 := func() int { if true { return 1 } else return 2 }"),
+ CErr("fn1 := func() int { if true { return 1 } else { } }", "return"),
+ CErr("fn1 := func() int { if true { } else { return 1 } }", "return"),
+ CErr("fn1 := func() int { if true { } else return 1 }", "return"),
+ CErr("fn1 := func() int { if true { } else { } }", "return"),
+ CErr("fn1 := func() int { if true { return 1 } }", "return"),
+ CErr("fn1 := func() int { if true { } }", "return"),
+ Run("fn1 := func() int { if true { }; return 1 }"),
+ CErr("fn1 := func() int { if { } }", "return"),
+ CErr("fn1 := func() int { if { } else { return 2 } }", "return"),
+ Run("fn1 := func() int { if { return 1 } }"),
+ Run("fn1 := func() int { if { return 1 } else { } }"),
+ Run("fn1 := func() int { if { return 1 } else { } }"),
// Switch
Val1("switch { case false: i += 2; case true: i += 4; default: i += 8 }", "i", 1+4),
Val1("switch { default: i += 2; case false: i += 4; case true: i += 8 }", "i", 1+8),
- SErr("switch { default: i += 2; default: i += 4 }", "more than one"),
+ CErr("switch { default: i += 2; default: i += 4 }", "more than one"),
Val1("switch false { case false: i += 2; case true: i += 4; default: i += 8 }", "i", 1+2),
- SErr("switch s { case 1: }", opTypes),
- SErr("switch ai { case ai: i += 2 }", opTypes),
+ CErr("switch s { case 1: }", opTypes),
+ CErr("switch ai { case ai: i += 2 }", opTypes),
Val1("switch 1.0 { case 1: i += 2; case 2: i += 4 }", "i", 1+2),
Val1("switch 1.5 { case 1: i += 2; case 2: i += 4 }", "i", 1),
- SErr("switch oneTwo() {}", "multi-valued expression"),
+ CErr("switch oneTwo() {}", "multi-valued expression"),
Val1("switch 2 { case 1: i += 2; fallthrough; case 2: i += 4; fallthrough; case 3: i += 8; fallthrough }", "i", 1+4+8),
Val1("switch 5 { case 1: i += 2; fallthrough; default: i += 4; fallthrough; case 2: i += 8; fallthrough; case 3: i += 16; fallthrough }", "i", 1+4+8+16),
- SErr("switch { case true: fallthrough; i += 2 }", "final statement"),
+ CErr("switch { case true: fallthrough; i += 2 }", "final statement"),
Val1("switch { case true: i += 2; fallthrough; ; ; case false: i += 4 }", "i", 1+2+4),
Val1("switch 2 { case 0, 1: i += 2; case 2, 3: i += 4 }", "i", 1+4),
Val2("switch func()int{i2++;return 5}() { case 1, 2: i += 2; case 4, 5: i += 4 }", "i", 1+4, "i2", 3),
- SRuns("switch i { case i: }"),
+ Run("switch i { case i: }"),
// TODO(austin) Why doesn't this fail?
- //SErr("case 1:", "XXX"),
+ //CErr("case 1:", "XXX"),
// For
Val2("for x := 1; x < 5; x++ { i+=x }; i2 = 4", "i", 11, "i2", 4),
@@ -278,44 +279,44 @@ var stmtTests = []test {
// Labeled break/continue
Val1("L1: for { L2: for { i+=2; break L1; i+=4 } i+=8 }", "i", 1+2),
Val1("L1: for { L2: for { i+=2; break L2; i+=4 } i+=8; break; i+=16 }", "i", 1+2+8),
- SErr("L1: { for { break L1 } }", "break.*not defined"),
- SErr("L1: for {} for { break L1 }", "break.*not defined"),
- SErr("L1:; for { break L1 }", "break.*not defined"),
+ CErr("L1: { for { break L1 } }", "break.*not defined"),
+ CErr("L1: for {} for { break L1 }", "break.*not defined"),
+ CErr("L1:; for { break L1 }", "break.*not defined"),
Val2("L1: for i = 0; i < 2; i++ { L2: for { i2++; continue L1; i2++ } }", "i", 2, "i2", 4),
- SErr("L1: { for { continue L1 } }", "continue.*not defined"),
- SErr("L1:; for { continue L1 }", "continue.*not defined"),
+ CErr("L1: { for { continue L1 } }", "continue.*not defined"),
+ CErr("L1:; for { continue L1 }", "continue.*not defined"),
// Return checking
- SRuns("fn1 := func() int{ for {} }"),
- SErr("fn1 := func() int{ for true {} }", "return"),
- SErr("fn1 := func() int{ for true {return 1} }", "return"),
- SErr("fn1 := func() int{ for {break} }", "return"),
- SRuns("fn1 := func() int{ for { for {break} } }"),
- SErr("fn1 := func() int{ L1: for { for {break L1} } }", "return"),
- SRuns("fn1 := func() int{ for true {} return 1 }"),
+ Run("fn1 := func() int{ for {} }"),
+ CErr("fn1 := func() int{ for true {} }", "return"),
+ CErr("fn1 := func() int{ for true {return 1} }", "return"),
+ CErr("fn1 := func() int{ for {break} }", "return"),
+ Run("fn1 := func() int{ for { for {break} } }"),
+ CErr("fn1 := func() int{ L1: for { for {break L1} } }", "return"),
+ Run("fn1 := func() int{ for true {} return 1 }"),
// Selectors
Val1("var x struct { a int; b int }; x.a = 42; i = x.a", "i", 42),
Val1("type T struct { x int }; var y struct { T }; y.x = 42; i = y.x", "i", 42),
Val2("type T struct { x int }; var y struct { T; x int }; y.x = 42; i = y.x; i2 = y.T.x", "i", 42, "i2", 0),
- SRuns("type T struct { x int }; var y struct { *T }; a := func(){i=y.x}"),
- SErr("type T struct { x int }; var x T; x.y = 42", "no field"),
- SErr("type T struct { x int }; type U struct { x int }; var y struct { T; U }; y.x = 42", "ambiguous.*\tT\\.x\n\tU\\.x"),
- SErr("type T struct { *T }; var x T; x.foo", "no field"),
+ Run("type T struct { x int }; var y struct { *T }; a := func(){i=y.x}"),
+ CErr("type T struct { x int }; var x T; x.y = 42", "no field"),
+ CErr("type T struct { x int }; type U struct { x int }; var y struct { T; U }; y.x = 42", "ambiguous.*\tT\\.x\n\tU\\.x"),
+ CErr("type T struct { *T }; var x T; x.foo", "no field"),
Val1("fib := func(int) int{return 0;}; fib = func(v int) int { if v < 2 { return 1 } return fib(v-1)+fib(v-2) }; i = fib(20)", "i", 10946),
// Make slice
Val2("x := make([]int, 2); x[0] = 42; i, i2 = x[0], x[1]", "i", 42, "i2", 0),
Val2("x := make([]int, 2); x[1] = 42; i, i2 = x[0], x[1]", "i", 0, "i2", 42),
- SRTErr("x := make([]int, 2); x[-i] = 42", "negative index"),
- SRTErr("x := make([]int, 2); x[2] = 42", "index 2 exceeds"),
+ RErr("x := make([]int, 2); x[-i] = 42", "negative index"),
+ RErr("x := make([]int, 2); x[2] = 42", "index 2 exceeds"),
Val2("x := make([]int, 2, 3); i, i2 = len(x), cap(x)", "i", 2, "i2", 3),
Val2("x := make([]int, 3, 2); i, i2 = len(x), cap(x)", "i", 3, "i2", 3),
- SRTErr("x := make([]int, -i)", "negative length"),
- SRTErr("x := make([]int, 2, -i)", "negative capacity"),
- SRTErr("x := make([]int, 2, 3); x[2] = 42", "index 2 exceeds"),
- SErr("x := make([]int, 2, 3, 4)", "too many"),
- SErr("x := make([]int)", "not enough"),
+ RErr("x := make([]int, -i)", "negative length"),
+ RErr("x := make([]int, 2, -i)", "negative capacity"),
+ RErr("x := make([]int, 2, 3); x[2] = 42", "index 2 exceeds"),
+ CErr("x := make([]int, 2, 3, 4)", "too many"),
+ CErr("x := make([]int)", "not enough"),
// TODO(austin) Test make map
@@ -326,10 +327,10 @@ var stmtTests = []test {
// Not implemented
//Val1("x := make(map[int] int); x[1] = 42, true; i = x[1]", "i", 42),
//Val2("x := make(map[int] int); x[1] = 42; x[1] = 42, false; i, y := x[1]", "i", 0, "y", false),
- SRuns("var x int; a := make(map[int] int); a[0], x = 1, 2"),
- SErr("x := make(map[int] int); (func(a,b int){})(x[0])", "not enough"),
- SErr("x := make(map[int] int); x[1] = oneTwo()", "too many"),
- SRTErr("x := make(map[int] int); i = x[1]", "key '1' not found"),
+ Run("var x int; a := make(map[int] int); a[0], x = 1, 2"),
+ CErr("x := make(map[int] int); (func(a,b int){})(x[0])", "not enough"),
+ CErr("x := make(map[int] int); x[1] = oneTwo()", "too many"),
+ RErr("x := make(map[int] int); i = x[1]", "key '1' not found"),
}
func TestStmt(t *testing.T) {