test: Clean up and improve golang tests
This adds some consistency to the tests and properly catches difficult scenarios in some of the lexparse tests.
This commit is contained in:
@@ -68,7 +68,7 @@ func TestInstance1(t *testing.T) {
|
|||||||
fail bool
|
fail bool
|
||||||
expect map[string]string
|
expect map[string]string
|
||||||
}
|
}
|
||||||
values := []test{}
|
testCases := []test{}
|
||||||
|
|
||||||
{
|
{
|
||||||
code := util.Code(`
|
code := util.Code(`
|
||||||
@@ -79,7 +79,7 @@ func TestInstance1(t *testing.T) {
|
|||||||
state => "exists",
|
state => "exists",
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "hello world",
|
name: "hello world",
|
||||||
code: code,
|
code: code,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -89,9 +89,9 @@ func TestInstance1(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for index, test := range values { // run all the tests
|
for index, tc := range testCases { // run all the tests
|
||||||
t.Run(fmt.Sprintf("test #%d (%s)", index, test.name), func(t *testing.T) {
|
t.Run(fmt.Sprintf("test #%d (%s)", index, tc.name), func(t *testing.T) {
|
||||||
code, fail, expect := test.code, test.fail, test.expect
|
code, fail, expect := tc.code, tc.fail, tc.expect
|
||||||
|
|
||||||
m := Instance{
|
m := Instance{
|
||||||
Hostname: "h1",
|
Hostname: "h1",
|
||||||
@@ -151,7 +151,7 @@ func TestCluster1(t *testing.T) {
|
|||||||
hosts []string
|
hosts []string
|
||||||
expect map[string]map[string]string // hostname, file, contents
|
expect map[string]map[string]string // hostname, file, contents
|
||||||
}
|
}
|
||||||
values := []test{}
|
testCases := []test{}
|
||||||
|
|
||||||
{
|
{
|
||||||
code := util.Code(`
|
code := util.Code(`
|
||||||
@@ -162,7 +162,7 @@ func TestCluster1(t *testing.T) {
|
|||||||
state => "exists",
|
state => "exists",
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple pair",
|
name: "simple pair",
|
||||||
code: code,
|
code: code,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -186,7 +186,7 @@ func TestCluster1(t *testing.T) {
|
|||||||
state => "exists",
|
state => "exists",
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "hello world",
|
name: "hello world",
|
||||||
code: code,
|
code: code,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -205,9 +205,9 @@ func TestCluster1(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for index, test := range values { // run all the tests
|
for index, tc := range testCases { // run all the tests
|
||||||
t.Run(fmt.Sprintf("test #%d (%s)", index, test.name), func(t *testing.T) {
|
t.Run(fmt.Sprintf("test #%d (%s)", index, tc.name), func(t *testing.T) {
|
||||||
code, fail, hosts, expect := test.code, test.fail, test.hosts, test.expect
|
code, fail, hosts, expect := tc.code, tc.fail, tc.hosts, tc.expect
|
||||||
|
|
||||||
c := Cluster{
|
c := Cluster{
|
||||||
Hostnames: hosts,
|
Hostnames: hosts,
|
||||||
|
|||||||
@@ -130,6 +130,10 @@ func TestInterpolate0(t *testing.T) {
|
|||||||
|
|
||||||
names := []string{}
|
names := []string{}
|
||||||
for index, tc := range testCases { // run all the tests
|
for index, tc := range testCases { // run all the tests
|
||||||
|
if tc.name == "" {
|
||||||
|
t.Errorf("test #%d: not named", index)
|
||||||
|
continue
|
||||||
|
}
|
||||||
if util.StrInList(tc.name, names) {
|
if util.StrInList(tc.name, names) {
|
||||||
t.Errorf("test #%d: duplicate sub test name of: %s", index, tc.name)
|
t.Errorf("test #%d: duplicate sub test name of: %s", index, tc.name)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -77,11 +77,11 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
scope *interfaces.Scope
|
scope *interfaces.Scope
|
||||||
graph *pgraph.Graph
|
graph *pgraph.Graph
|
||||||
}
|
}
|
||||||
values := []test{}
|
testCases := []test{}
|
||||||
|
|
||||||
{
|
{
|
||||||
graph, _ := pgraph.NewGraph("g")
|
graph, _ := pgraph.NewGraph("g")
|
||||||
values = append(values, test{ // 0
|
testCases = append(testCases, test{ // 0
|
||||||
"nil",
|
"nil",
|
||||||
``,
|
``,
|
||||||
false,
|
false,
|
||||||
@@ -91,7 +91,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
graph, _ := pgraph.NewGraph("g")
|
graph, _ := pgraph.NewGraph("g")
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "scope only",
|
name: "scope only",
|
||||||
code: ``,
|
code: ``,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -105,7 +105,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
e1 := edge("x")
|
e1 := edge("x")
|
||||||
graph.AddVertex(&v1, &v2)
|
graph.AddVertex(&v1, &v2)
|
||||||
graph.AddEdge(&v1, &v2, &e1)
|
graph.AddEdge(&v1, &v2, &e1)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "two vars",
|
name: "two vars",
|
||||||
code: `
|
code: `
|
||||||
$x = 42
|
$x = 42
|
||||||
@@ -118,7 +118,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
graph, _ := pgraph.NewGraph("g")
|
graph, _ := pgraph.NewGraph("g")
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "self-referential vars",
|
name: "self-referential vars",
|
||||||
code: `
|
code: `
|
||||||
$x = $y
|
$x = $y
|
||||||
@@ -136,7 +136,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
graph.AddEdge(&v1, &v2, &e1)
|
graph.AddEdge(&v1, &v2, &e1)
|
||||||
graph.AddEdge(&v2, &v3, &e2)
|
graph.AddEdge(&v2, &v3, &e2)
|
||||||
graph.AddEdge(&v3, &v4, &e3)
|
graph.AddEdge(&v3, &v4, &e3)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "chained vars",
|
name: "chained vars",
|
||||||
code: `
|
code: `
|
||||||
test "t" {
|
test "t" {
|
||||||
@@ -156,7 +156,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
graph.AddVertex(&v1, &v2)
|
graph.AddVertex(&v1, &v2)
|
||||||
e1 := edge("b")
|
e1 := edge("b")
|
||||||
graph.AddEdge(&v1, &v2, &e1)
|
graph.AddEdge(&v1, &v2, &e1)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple bool",
|
name: "simple bool",
|
||||||
code: `
|
code: `
|
||||||
if $b {
|
if $b {
|
||||||
@@ -175,7 +175,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
graph.AddEdge(&v2, &v5, &e1)
|
graph.AddEdge(&v2, &v5, &e1)
|
||||||
graph.AddEdge(&v3, &v5, &e2)
|
graph.AddEdge(&v3, &v5, &e2)
|
||||||
graph.AddEdge(&v4, &v5, &e3)
|
graph.AddEdge(&v4, &v5, &e3)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple operator",
|
name: "simple operator",
|
||||||
code: `
|
code: `
|
||||||
test "t" {
|
test "t" {
|
||||||
@@ -203,7 +203,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
graph.AddEdge(&v2, &v8, &e4)
|
graph.AddEdge(&v2, &v8, &e4)
|
||||||
graph.AddEdge(&v7, &v8, &e5)
|
graph.AddEdge(&v7, &v8, &e5)
|
||||||
graph.AddEdge(&v6, &v8, &e6)
|
graph.AddEdge(&v6, &v8, &e6)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple operators",
|
name: "simple operators",
|
||||||
code: `
|
code: `
|
||||||
test "t" {
|
test "t" {
|
||||||
@@ -230,7 +230,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
graph.AddEdge(&v5, &v8, &e3)
|
graph.AddEdge(&v5, &v8, &e3)
|
||||||
|
|
||||||
graph.AddEdge(&v8, &v6, &e5)
|
graph.AddEdge(&v8, &v6, &e5)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "nested resource and scoped var",
|
name: "nested resource and scoped var",
|
||||||
code: `
|
code: `
|
||||||
if true {
|
if true {
|
||||||
@@ -246,7 +246,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "out of scope error",
|
name: "out of scope error",
|
||||||
code: `
|
code: `
|
||||||
# should be out of scope, and a compile error!
|
# should be out of scope, and a compile error!
|
||||||
@@ -260,7 +260,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "variable re-declaration error",
|
name: "variable re-declaration error",
|
||||||
code: `
|
code: `
|
||||||
# this should fail b/c of variable re-declaration
|
# this should fail b/c of variable re-declaration
|
||||||
@@ -280,7 +280,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
// only one edge! (cool)
|
// only one edge! (cool)
|
||||||
graph.AddEdge(&v1, &v4, &e1)
|
graph.AddEdge(&v1, &v4, &e1)
|
||||||
|
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "variable shadowing",
|
name: "variable shadowing",
|
||||||
code: `
|
code: `
|
||||||
# this should be okay, because var is shadowed
|
# this should be okay, because var is shadowed
|
||||||
@@ -306,7 +306,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
// only one edge! (cool)
|
// only one edge! (cool)
|
||||||
graph.AddEdge(&v2, &v4, &e1)
|
graph.AddEdge(&v2, &v4, &e1)
|
||||||
|
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "variable shadowing inner",
|
name: "variable shadowing inner",
|
||||||
code: `
|
code: `
|
||||||
# this should be okay, because var is shadowed
|
# this should be okay, because var is shadowed
|
||||||
@@ -335,7 +335,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
// graph.AddEdge(&v1, &v3, &e1)
|
// graph.AddEdge(&v1, &v3, &e1)
|
||||||
// graph.AddEdge(&v2, &v4, &e2)
|
// graph.AddEdge(&v2, &v4, &e2)
|
||||||
//
|
//
|
||||||
// values = append(values, test{
|
// testCases = append(testCases, test{
|
||||||
// name: "variable shadowing both",
|
// name: "variable shadowing both",
|
||||||
// code: `
|
// code: `
|
||||||
// # this should be okay, because var is shadowed
|
// # this should be okay, because var is shadowed
|
||||||
@@ -355,7 +355,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
// })
|
// })
|
||||||
//}
|
//}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "variable re-declaration and type change error",
|
name: "variable re-declaration and type change error",
|
||||||
code: `
|
code: `
|
||||||
# this should fail b/c of variable re-declaration
|
# this should fail b/c of variable re-declaration
|
||||||
@@ -367,8 +367,8 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
names := []string{}
|
names := []string{}
|
||||||
for index, test := range values { // run all the tests
|
for index, tc := range testCases { // run all the tests
|
||||||
name, code, fail, scope, exp := test.name, test.code, test.fail, test.scope, test.graph
|
name, code, fail, scope, exp := tc.name, tc.code, tc.fail, tc.scope, tc.graph
|
||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = "<sub test not named>"
|
name = "<sub test not named>"
|
||||||
@@ -380,7 +380,7 @@ func TestAstFunc0(t *testing.T) {
|
|||||||
names = append(names, name)
|
names = append(names, name)
|
||||||
|
|
||||||
//if index != 3 { // hack to run a subset (useful for debugging)
|
//if index != 3 { // hack to run a subset (useful for debugging)
|
||||||
//if test.name != "simple operators" {
|
//if tc.name != "simple operators" {
|
||||||
// continue
|
// continue
|
||||||
//}
|
//}
|
||||||
|
|
||||||
@@ -495,11 +495,11 @@ func TestAstInterpret0(t *testing.T) {
|
|||||||
fail bool
|
fail bool
|
||||||
graph *pgraph.Graph
|
graph *pgraph.Graph
|
||||||
}
|
}
|
||||||
values := []test{}
|
testCases := []test{}
|
||||||
|
|
||||||
{
|
{
|
||||||
graph, _ := pgraph.NewGraph("g")
|
graph, _ := pgraph.NewGraph("g")
|
||||||
values = append(values, test{ // 0
|
testCases = append(testCases, test{ // 0
|
||||||
"nil",
|
"nil",
|
||||||
``,
|
``,
|
||||||
false,
|
false,
|
||||||
@@ -507,7 +507,7 @@ func TestAstInterpret0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "wrong res field type",
|
name: "wrong res field type",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -530,7 +530,7 @@ func TestAstInterpret0(t *testing.T) {
|
|||||||
int8ptrptrptr := &int8ptrptr
|
int8ptrptrptr := &int8ptrptr
|
||||||
x.Int8PtrPtrPtr = &int8ptrptrptr
|
x.Int8PtrPtrPtr = &int8ptrptrptr
|
||||||
graph.AddVertex(t1)
|
graph.AddVertex(t1)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "resource with three pointer fields",
|
name: "resource with three pointer fields",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -550,7 +550,7 @@ func TestAstInterpret0(t *testing.T) {
|
|||||||
stringptr := "wow"
|
stringptr := "wow"
|
||||||
x.StringPtr = &stringptr
|
x.StringPtr = &stringptr
|
||||||
graph.AddVertex(t1)
|
graph.AddVertex(t1)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "resource with simple string pointer field",
|
name: "resource with simple string pointer field",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -582,7 +582,7 @@ func TestAstInterpret0(t *testing.T) {
|
|||||||
Notify: false,
|
Notify: false,
|
||||||
}
|
}
|
||||||
graph.AddEdge(t1, t2, edge)
|
graph.AddEdge(t1, t2, edge)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "two resources and send/recv edge",
|
name: "two resources and send/recv edge",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -599,8 +599,8 @@ func TestAstInterpret0(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
names := []string{}
|
names := []string{}
|
||||||
for index, test := range values { // run all the tests
|
for index, tc := range testCases { // run all the tests
|
||||||
name, code, fail, exp := test.name, test.code, test.fail, test.graph
|
name, code, fail, exp := tc.name, tc.code, tc.fail, tc.graph
|
||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = "<sub test not named>"
|
name = "<sub test not named>"
|
||||||
@@ -612,7 +612,7 @@ func TestAstInterpret0(t *testing.T) {
|
|||||||
names = append(names, name)
|
names = append(names, name)
|
||||||
|
|
||||||
//if index != 3 { // hack to run a subset (useful for debugging)
|
//if index != 3 { // hack to run a subset (useful for debugging)
|
||||||
//if test.name != "nil" {
|
//if tc.name != "nil" {
|
||||||
// continue
|
// continue
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|||||||
@@ -305,11 +305,11 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
fail bool
|
fail bool
|
||||||
graph *pgraph.Graph
|
graph *pgraph.Graph
|
||||||
}
|
}
|
||||||
values := []test{}
|
testCases := []test{}
|
||||||
|
|
||||||
{
|
{
|
||||||
graph, _ := pgraph.NewGraph("g")
|
graph, _ := pgraph.NewGraph("g")
|
||||||
values = append(values, test{ // 0
|
testCases = append(testCases, test{ // 0
|
||||||
"nil",
|
"nil",
|
||||||
``,
|
``,
|
||||||
false,
|
false,
|
||||||
@@ -318,7 +318,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
graph, _ := pgraph.NewGraph("g")
|
graph, _ := pgraph.NewGraph("g")
|
||||||
values = append(values, test{ // 1
|
testCases = append(testCases, test{ // 1
|
||||||
name: "empty",
|
name: "empty",
|
||||||
code: ``,
|
code: ``,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -332,7 +332,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
i := int64(42 + 13)
|
i := int64(42 + 13)
|
||||||
x.Int64Ptr = &i
|
x.Int64Ptr = &i
|
||||||
graph.AddVertex(x)
|
graph.AddVertex(x)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple addition",
|
name: "simple addition",
|
||||||
code: `
|
code: `
|
||||||
test "t" {
|
test "t" {
|
||||||
@@ -350,7 +350,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
i := int64(42 + 13 + 99)
|
i := int64(42 + 13 + 99)
|
||||||
x.Int64Ptr = &i
|
x.Int64Ptr = &i
|
||||||
graph.AddVertex(x)
|
graph.AddVertex(x)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "triple addition",
|
name: "triple addition",
|
||||||
code: `
|
code: `
|
||||||
test "t" {
|
test "t" {
|
||||||
@@ -368,7 +368,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
i := int64(42 + 13 - 99)
|
i := int64(42 + 13 - 99)
|
||||||
x.Int64Ptr = &i
|
x.Int64Ptr = &i
|
||||||
graph.AddVertex(x)
|
graph.AddVertex(x)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "triple addition/subtraction",
|
name: "triple addition/subtraction",
|
||||||
code: `
|
code: `
|
||||||
test "t" {
|
test "t" {
|
||||||
@@ -386,7 +386,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
s1 := "hello"
|
s1 := "hello"
|
||||||
x1.StringPtr = &s1
|
x1.StringPtr = &s1
|
||||||
graph.AddVertex(x1)
|
graph.AddVertex(x1)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "single include",
|
name: "single include",
|
||||||
code: `
|
code: `
|
||||||
class c1($a, $b) {
|
class c1($a, $b) {
|
||||||
@@ -410,7 +410,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
x1.StringPtr = &s1
|
x1.StringPtr = &s1
|
||||||
x2.StringPtr = &s2
|
x2.StringPtr = &s2
|
||||||
graph.AddVertex(x1, x2)
|
graph.AddVertex(x1, x2)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "double include",
|
name: "double include",
|
||||||
code: `
|
code: `
|
||||||
class c1($a, $b) {
|
class c1($a, $b) {
|
||||||
@@ -435,7 +435,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
//x1.StringPtr = &s1
|
//x1.StringPtr = &s1
|
||||||
//x2.Int64Ptr = &i2
|
//x2.Int64Ptr = &i2
|
||||||
//graph.AddVertex(x1, x2)
|
//graph.AddVertex(x1, x2)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "double include different types error",
|
name: "double include different types error",
|
||||||
code: `
|
code: `
|
||||||
class c1($a, $b) {
|
class c1($a, $b) {
|
||||||
@@ -466,7 +466,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
x1.StringPtr = &s1
|
x1.StringPtr = &s1
|
||||||
x2.StringPtr = &s2
|
x2.StringPtr = &s2
|
||||||
graph.AddVertex(x1, x2)
|
graph.AddVertex(x1, x2)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "double include different types allowed",
|
name: "double include different types allowed",
|
||||||
code: `
|
code: `
|
||||||
class c1($a, $b) {
|
class c1($a, $b) {
|
||||||
@@ -494,7 +494,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
// x1.StringPtr = &s1
|
// x1.StringPtr = &s1
|
||||||
// x2.StringPtr = &s2
|
// x2.StringPtr = &s2
|
||||||
// graph.AddVertex(x1, x2)
|
// graph.AddVertex(x1, x2)
|
||||||
// values = append(values, test{
|
// testCases = append(testCases, test{
|
||||||
// name: "double include different printf types allowed",
|
// name: "double include different printf types allowed",
|
||||||
// code: `
|
// code: `
|
||||||
// import "fmt"
|
// import "fmt"
|
||||||
@@ -520,7 +520,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
x1.StringPtr = &s1
|
x1.StringPtr = &s1
|
||||||
x2.StringPtr = &s2
|
x2.StringPtr = &s2
|
||||||
graph.AddVertex(x1, x2)
|
graph.AddVertex(x1, x2)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "double include with variable in parent scope",
|
name: "double include with variable in parent scope",
|
||||||
code: `
|
code: `
|
||||||
$foo = "hey"
|
$foo = "hey"
|
||||||
@@ -546,7 +546,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
x1.StringPtr = &s1
|
x1.StringPtr = &s1
|
||||||
x2.StringPtr = &s2
|
x2.StringPtr = &s2
|
||||||
graph.AddVertex(x1, x2)
|
graph.AddVertex(x1, x2)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "double include with out of order variable in parent scope",
|
name: "double include with out of order variable in parent scope",
|
||||||
code: `
|
code: `
|
||||||
include c1("t1")
|
include c1("t1")
|
||||||
@@ -569,7 +569,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
s1 := "hello"
|
s1 := "hello"
|
||||||
x1.StringPtr = &s1
|
x1.StringPtr = &s1
|
||||||
graph.AddVertex(x1)
|
graph.AddVertex(x1)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "duplicate include identical",
|
name: "duplicate include identical",
|
||||||
code: `
|
code: `
|
||||||
include c1("t1", "hello")
|
include c1("t1", "hello")
|
||||||
@@ -591,7 +591,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
s1 := "hello"
|
s1 := "hello"
|
||||||
x1.StringPtr = &s1
|
x1.StringPtr = &s1
|
||||||
graph.AddVertex(x1)
|
graph.AddVertex(x1)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "duplicate include non-identical",
|
name: "duplicate include non-identical",
|
||||||
code: `
|
code: `
|
||||||
include c1("t1", "hello")
|
include c1("t1", "hello")
|
||||||
@@ -613,7 +613,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "duplicate include incompatible",
|
name: "duplicate include incompatible",
|
||||||
code: `
|
code: `
|
||||||
include c1("t1", "hello")
|
include c1("t1", "hello")
|
||||||
@@ -628,7 +628,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "class wrong number of args 1",
|
name: "class wrong number of args 1",
|
||||||
code: `
|
code: `
|
||||||
include c1("hello") # missing second arg
|
include c1("hello") # missing second arg
|
||||||
@@ -642,7 +642,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "class wrong number of args 2",
|
name: "class wrong number of args 2",
|
||||||
code: `
|
code: `
|
||||||
include c1("hello", 42) # added second arg
|
include c1("hello", 42) # added second arg
|
||||||
@@ -665,7 +665,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
x1.StringPtr = &s1
|
x1.StringPtr = &s1
|
||||||
x2.StringPtr = &s2
|
x2.StringPtr = &s2
|
||||||
graph.AddVertex(x1, x2)
|
graph.AddVertex(x1, x2)
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "nested classes 1",
|
name: "nested classes 1",
|
||||||
code: `
|
code: `
|
||||||
import "fmt"
|
import "fmt"
|
||||||
@@ -693,7 +693,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "nested classes out of scope 1",
|
name: "nested classes out of scope 1",
|
||||||
code: `
|
code: `
|
||||||
import "fmt"
|
import "fmt"
|
||||||
@@ -722,7 +722,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
// TODO: recursive classes are not currently supported (should they be?)
|
// TODO: recursive classes are not currently supported (should they be?)
|
||||||
//{
|
//{
|
||||||
// graph, _ := pgraph.NewGraph("g")
|
// graph, _ := pgraph.NewGraph("g")
|
||||||
// values = append(values, test{
|
// testCases = append(testCases, test{
|
||||||
// name: "recursive classes 0",
|
// name: "recursive classes 0",
|
||||||
// code: `
|
// code: `
|
||||||
// include c1(0) # start at zero
|
// include c1(0) # start at zero
|
||||||
@@ -744,7 +744,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
// s0 := "count is 3"
|
// s0 := "count is 3"
|
||||||
// x0.StringPtr = &s0
|
// x0.StringPtr = &s0
|
||||||
// graph.AddVertex(x0)
|
// graph.AddVertex(x0)
|
||||||
// values = append(values, test{
|
// testCases = append(testCases, test{
|
||||||
// name: "recursive classes 1",
|
// name: "recursive classes 1",
|
||||||
// code: `
|
// code: `
|
||||||
// import "fmt"
|
// import "fmt"
|
||||||
@@ -782,7 +782,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
// x2.StringPtr = &s2
|
// x2.StringPtr = &s2
|
||||||
// x3.StringPtr = &s3
|
// x3.StringPtr = &s3
|
||||||
// graph.AddVertex(x0, x1, x2, x3)
|
// graph.AddVertex(x0, x1, x2, x3)
|
||||||
// values = append(values, test{
|
// testCases = append(testCases, test{
|
||||||
// name: "recursive classes 2",
|
// name: "recursive classes 2",
|
||||||
// code: `
|
// code: `
|
||||||
// import "fmt"
|
// import "fmt"
|
||||||
@@ -810,7 +810,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
//}
|
//}
|
||||||
// TODO: remove this test if we ever support recursive classes
|
// TODO: remove this test if we ever support recursive classes
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "recursive classes fail 1",
|
name: "recursive classes fail 1",
|
||||||
code: `
|
code: `
|
||||||
import "fmt"
|
import "fmt"
|
||||||
@@ -831,7 +831,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// TODO: remove this test if we ever support recursive classes
|
// TODO: remove this test if we ever support recursive classes
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "recursive classes fail 2",
|
name: "recursive classes fail 2",
|
||||||
code: `
|
code: `
|
||||||
import "fmt"
|
import "fmt"
|
||||||
@@ -861,8 +861,8 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
names := []string{}
|
names := []string{}
|
||||||
for index, test := range values { // run all the tests
|
for index, tc := range testCases { // run all the tests
|
||||||
name, code, fail, exp := test.name, test.code, test.fail, test.graph
|
name, code, fail, exp := tc.name, tc.code, tc.fail, tc.graph
|
||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = "<sub test not named>"
|
name = "<sub test not named>"
|
||||||
@@ -874,7 +874,7 @@ func TestInterpretMany(t *testing.T) {
|
|||||||
names = append(names, name)
|
names = append(names, name)
|
||||||
|
|
||||||
//if index != 3 { // hack to run a subset (useful for debugging)
|
//if index != 3 { // hack to run a subset (useful for debugging)
|
||||||
//if test.name != "nil" {
|
//if tc.name != "nil" {
|
||||||
// continue
|
// continue
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|||||||
@@ -41,10 +41,10 @@ func TestLexParse0(t *testing.T) {
|
|||||||
fail bool
|
fail bool
|
||||||
exp interfaces.Stmt
|
exp interfaces.Stmt
|
||||||
}
|
}
|
||||||
values := []test{}
|
testCases := []test{}
|
||||||
|
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
"nil",
|
"nil",
|
||||||
``,
|
``,
|
||||||
false,
|
false,
|
||||||
@@ -52,7 +52,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple assignment",
|
name: "simple assignment",
|
||||||
code: `$rewsna = -42`,
|
code: `$rewsna = -42`,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -69,7 +69,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "one res",
|
name: "one res",
|
||||||
code: `noop "n1" {}`,
|
code: `noop "n1" {}`,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -77,14 +77,14 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "res with keyword",
|
name: "res with keyword",
|
||||||
code: `false "n1" {}`, // false is a special keyword
|
code: `false "n1" {}`, // false is a special keyword
|
||||||
fail: true,
|
fail: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "bad escaping",
|
name: "bad escaping",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -95,7 +95,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "int overflow",
|
name: "int overflow",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -106,7 +106,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "overflow after lexer",
|
name: "overflow after lexer",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -118,7 +118,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "one res with param",
|
name: "one res with param",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -130,7 +130,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "one res with elvis",
|
name: "one res with elvis",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -145,7 +145,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
// TODO: skip trailing comma requirement on one-liners
|
// TODO: skip trailing comma requirement on one-liners
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "two lists",
|
name: "two lists",
|
||||||
code: `
|
code: `
|
||||||
$somelist = [42, 0, -13,]
|
$somelist = [42, 0, -13,]
|
||||||
@@ -162,7 +162,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "one map",
|
name: "one map",
|
||||||
code: `
|
code: `
|
||||||
$somemap = {
|
$somemap = {
|
||||||
@@ -175,7 +175,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "another map",
|
name: "another map",
|
||||||
code: `
|
code: `
|
||||||
$somemap = {
|
$somemap = {
|
||||||
@@ -189,7 +189,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// TODO: alternate possible syntax ?
|
// TODO: alternate possible syntax ?
|
||||||
//{
|
//{
|
||||||
// values = append(values, test{ // ?
|
// testCases = append(testCases, test{ // ?
|
||||||
// code: `
|
// code: `
|
||||||
// $somestruct = struct{
|
// $somestruct = struct{
|
||||||
// foo: "foo1";
|
// foo: "foo1";
|
||||||
@@ -201,7 +201,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
// })
|
// })
|
||||||
//}
|
//}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "one struct",
|
name: "one struct",
|
||||||
code: `
|
code: `
|
||||||
$somestruct = struct{
|
$somestruct = struct{
|
||||||
@@ -214,7 +214,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "struct with nested struct",
|
name: "struct with nested struct",
|
||||||
code: `
|
code: `
|
||||||
$somestruct = struct{
|
$somestruct = struct{
|
||||||
@@ -232,7 +232,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// types
|
// types
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "some lists",
|
name: "some lists",
|
||||||
code: `
|
code: `
|
||||||
$intlist []int = [42, -0, 13,]
|
$intlist []int = [42, -0, 13,]
|
||||||
@@ -243,7 +243,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "maps 1",
|
name: "maps 1",
|
||||||
code: `
|
code: `
|
||||||
# make sure the "str:" part doesn't match a single ident
|
# make sure the "str:" part doesn't match a single ident
|
||||||
@@ -257,7 +257,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "maps 2",
|
name: "maps 2",
|
||||||
code: `
|
code: `
|
||||||
$mapstrintlist map{str: []int} = {
|
$mapstrintlist map{str: []int} = {
|
||||||
@@ -271,7 +271,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "maps and lists",
|
name: "maps and lists",
|
||||||
code: `
|
code: `
|
||||||
$strmap map{str: int} = {
|
$strmap map{str: int} = {
|
||||||
@@ -289,7 +289,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "some structs",
|
name: "some structs",
|
||||||
code: `
|
code: `
|
||||||
$structx struct{a int; b bool; c str} = struct{
|
$structx struct{a int; b bool; c str} = struct{
|
||||||
@@ -308,7 +308,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "res with floats",
|
name: "res with floats",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -325,7 +325,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
// ULP away from the largest floating point number of the given size,
|
// ULP away from the largest floating point number of the given size,
|
||||||
// ParseFloat returns f = ±Inf, err.Err = ErrRange.
|
// ParseFloat returns f = ±Inf, err.Err = ErrRange.
|
||||||
//{
|
//{
|
||||||
// values = append(values, test{
|
// testCases = append(testCases, test{
|
||||||
// name: "overflowing float",
|
// name: "overflowing float",
|
||||||
// code: `
|
// code: `
|
||||||
// test "t1" {
|
// test "t1" {
|
||||||
@@ -336,7 +336,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
// })
|
// })
|
||||||
//}
|
//}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "res and addition",
|
name: "res and addition",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -359,7 +359,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "func call 1",
|
name: "func call 1",
|
||||||
code: `
|
code: `
|
||||||
$x1 = foo1()
|
$x1 = foo1()
|
||||||
@@ -387,7 +387,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "func call 2",
|
name: "func call 2",
|
||||||
code: `
|
code: `
|
||||||
$x1 = foo1(13, "hello")
|
$x1 = foo1(13, "hello")
|
||||||
@@ -408,7 +408,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "func call dotted 1",
|
name: "func call dotted 1",
|
||||||
code: `
|
code: `
|
||||||
$x1 = pkg.foo1()
|
$x1 = pkg.foo1()
|
||||||
@@ -436,7 +436,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "func call dotted 2",
|
name: "func call dotted 2",
|
||||||
code: `
|
code: `
|
||||||
$x1 = pkg.foo1(true, "hello")
|
$x1 = pkg.foo1(true, "hello")
|
||||||
@@ -446,7 +446,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "func call dotted invalid 1",
|
name: "func call dotted invalid 1",
|
||||||
code: `
|
code: `
|
||||||
$x1 = .pkg.foo1(true, "hello")
|
$x1 = .pkg.foo1(true, "hello")
|
||||||
@@ -455,7 +455,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "func call dotted invalid 2",
|
name: "func call dotted invalid 2",
|
||||||
code: `
|
code: `
|
||||||
$x1 = pkg.foo1.(true, "hello")
|
$x1 = pkg.foo1.(true, "hello")
|
||||||
@@ -464,7 +464,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "func call dotted invalid 3",
|
name: "func call dotted invalid 3",
|
||||||
code: `
|
code: `
|
||||||
$x1 = .pkg.foo1.(true, "hello")
|
$x1 = .pkg.foo1.(true, "hello")
|
||||||
@@ -473,7 +473,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "func call dotted invalid 4",
|
name: "func call dotted invalid 4",
|
||||||
code: `
|
code: `
|
||||||
$x1 = pkg..foo1(true, "hello")
|
$x1 = pkg..foo1(true, "hello")
|
||||||
@@ -492,7 +492,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "dotted var 1",
|
name: "dotted var 1",
|
||||||
code: `
|
code: `
|
||||||
$x1 = $pkg.foo1
|
$x1 = $pkg.foo1
|
||||||
@@ -512,7 +512,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "dotted var 2",
|
name: "dotted var 2",
|
||||||
code: `
|
code: `
|
||||||
$x1 = $pkg.foo1.bar
|
$x1 = $pkg.foo1.bar
|
||||||
@@ -522,7 +522,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "invalid dotted var 1",
|
name: "invalid dotted var 1",
|
||||||
code: `
|
code: `
|
||||||
$x1 = $.pkg.foo1.bar
|
$x1 = $.pkg.foo1.bar
|
||||||
@@ -531,7 +531,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "invalid dotted var 2",
|
name: "invalid dotted var 2",
|
||||||
code: `
|
code: `
|
||||||
$x1 = $pkg.foo1.bar.
|
$x1 = $pkg.foo1.bar.
|
||||||
@@ -540,7 +540,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "invalid dotted var 3",
|
name: "invalid dotted var 3",
|
||||||
code: `
|
code: `
|
||||||
$x1 = $.pkg.foo1.bar.
|
$x1 = $.pkg.foo1.bar.
|
||||||
@@ -549,7 +549,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "invalid dotted var 4",
|
name: "invalid dotted var 4",
|
||||||
code: `
|
code: `
|
||||||
$x1 = $pkg..foo1.bar
|
$x1 = $pkg..foo1.bar
|
||||||
@@ -587,7 +587,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "addition",
|
name: "addition",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -639,7 +639,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "multiple float addition",
|
name: "multiple float addition",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -691,7 +691,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "order of operations lucky",
|
name: "order of operations lucky",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -743,7 +743,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "order of operations needs left precedence",
|
name: "order of operations needs left precedence",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -795,7 +795,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "order of operations parens",
|
name: "order of operations parens",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -847,7 +847,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "order of operations bools",
|
name: "order of operations bools",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -899,7 +899,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "order of operations bools reversed",
|
name: "order of operations bools reversed",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -948,7 +948,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "order of operations with not",
|
name: "order of operations with not",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -1000,7 +1000,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "order of operations logical",
|
name: "order of operations logical",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -1062,7 +1062,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "edge stmt",
|
name: "edge stmt",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
@@ -1079,7 +1079,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "parser set type incompatibility str",
|
name: "parser set type incompatibility str",
|
||||||
code: `
|
code: `
|
||||||
$x int = "hello" # type should be str to work
|
$x int = "hello" # type should be str to work
|
||||||
@@ -1091,7 +1091,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "parser set type incompatibility int",
|
name: "parser set type incompatibility int",
|
||||||
code: `
|
code: `
|
||||||
$x int = "hello" # value should be int to work
|
$x int = "hello" # value should be int to work
|
||||||
@@ -1131,7 +1131,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple class 1",
|
name: "simple class 1",
|
||||||
code: `
|
code: `
|
||||||
class c1 {
|
class c1 {
|
||||||
@@ -1174,7 +1174,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple dotted class 1",
|
name: "simple dotted class 1",
|
||||||
code: `
|
code: `
|
||||||
# a dotted identifier only occurs via an imported class
|
# a dotted identifier only occurs via an imported class
|
||||||
@@ -1219,7 +1219,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple dotted class 2",
|
name: "simple dotted class 2",
|
||||||
code: `
|
code: `
|
||||||
# a dotted identifier only occurs via an imported class
|
# a dotted identifier only occurs via an imported class
|
||||||
@@ -1236,7 +1236,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple dotted invalid class 1",
|
name: "simple dotted invalid class 1",
|
||||||
code: `
|
code: `
|
||||||
# a dotted identifier only occurs via an imported class
|
# a dotted identifier only occurs via an imported class
|
||||||
@@ -1247,7 +1247,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple dotted invalid class 2",
|
name: "simple dotted invalid class 2",
|
||||||
code: `
|
code: `
|
||||||
# a dotted identifier only occurs via an imported class
|
# a dotted identifier only occurs via an imported class
|
||||||
@@ -1258,7 +1258,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple dotted invalid include 1",
|
name: "simple dotted invalid include 1",
|
||||||
code: `
|
code: `
|
||||||
class .foo.c1 {
|
class .foo.c1 {
|
||||||
@@ -1268,7 +1268,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple dotted invalid include 2",
|
name: "simple dotted invalid include 2",
|
||||||
code: `
|
code: `
|
||||||
class foo.c1. {
|
class foo.c1. {
|
||||||
@@ -1278,7 +1278,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple dotted invalid include 3",
|
name: "simple dotted invalid include 3",
|
||||||
code: `
|
code: `
|
||||||
class .foo.c1. {
|
class .foo.c1. {
|
||||||
@@ -1288,7 +1288,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple dotted invalid include 4",
|
name: "simple dotted invalid include 4",
|
||||||
code: `
|
code: `
|
||||||
class foo..c1 {
|
class foo..c1 {
|
||||||
@@ -1320,7 +1320,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple class with args 0",
|
name: "simple class with args 0",
|
||||||
code: `
|
code: `
|
||||||
class x() {
|
class x() {
|
||||||
@@ -1334,7 +1334,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple class underscore failure",
|
name: "simple class underscore failure",
|
||||||
code: `
|
code: `
|
||||||
class x_() {
|
class x_() {
|
||||||
@@ -1401,7 +1401,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple class with args 1",
|
name: "simple class with args 1",
|
||||||
code: `
|
code: `
|
||||||
class c1($a, $b) {
|
class c1($a, $b) {
|
||||||
@@ -1474,7 +1474,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple class with typed args 1",
|
name: "simple class with typed args 1",
|
||||||
code: `
|
code: `
|
||||||
class c1($a str, $b) {
|
class c1($a str, $b) {
|
||||||
@@ -1498,7 +1498,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple import 1",
|
name: "simple import 1",
|
||||||
code: `
|
code: `
|
||||||
import "foo1"
|
import "foo1"
|
||||||
@@ -1516,7 +1516,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple import 2",
|
name: "simple import 2",
|
||||||
code: `
|
code: `
|
||||||
import "foo1" as bar
|
import "foo1" as bar
|
||||||
@@ -1542,7 +1542,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple import 3",
|
name: "simple import 3",
|
||||||
code: `
|
code: `
|
||||||
import "foo1"
|
import "foo1"
|
||||||
@@ -1562,7 +1562,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple import 4",
|
name: "simple import 4",
|
||||||
code: `
|
code: `
|
||||||
import "foo1" as *
|
import "foo1" as *
|
||||||
@@ -1594,7 +1594,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple import inside class 1",
|
name: "simple import inside class 1",
|
||||||
code: `
|
code: `
|
||||||
class c1 {
|
class c1 {
|
||||||
@@ -1620,7 +1620,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple function stmt 1",
|
name: "simple function stmt 1",
|
||||||
code: `
|
code: `
|
||||||
func f1() {
|
func f1() {
|
||||||
@@ -1661,7 +1661,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple function stmt 2",
|
name: "simple function stmt 2",
|
||||||
code: `
|
code: `
|
||||||
func f2() int {
|
func f2() int {
|
||||||
@@ -1712,7 +1712,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple function stmt 3",
|
name: "simple function stmt 3",
|
||||||
code: `
|
code: `
|
||||||
func f3($a int, $b) int {
|
func f3($a int, $b) int {
|
||||||
@@ -1758,7 +1758,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple function stmt 4",
|
name: "simple function stmt 4",
|
||||||
code: `
|
code: `
|
||||||
func f4($x str) str {
|
func f4($x str) str {
|
||||||
@@ -1771,68 +1771,71 @@ func TestLexParse0(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
names := []string{}
|
names := []string{}
|
||||||
for index, test := range values { // run all the tests
|
for index, tc := range testCases { // run all the tests
|
||||||
name, code, fail, exp := test.name, test.code, test.fail, test.exp
|
if tc.name == "" {
|
||||||
|
t.Errorf("test #%d: not named", index)
|
||||||
if name == "" {
|
|
||||||
name = "<sub test not named>"
|
|
||||||
}
|
|
||||||
if util.StrInList(name, names) {
|
|
||||||
t.Errorf("test #%d: duplicate sub test name of: %s", index, name)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
names = append(names, name)
|
if util.StrInList(tc.name, names) {
|
||||||
|
t.Errorf("test #%d: duplicate sub test name of: %s", index, tc.name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
names = append(names, tc.name)
|
||||||
|
|
||||||
//if index != 3 { // hack to run a subset (useful for debugging)
|
//if index != 3 { // hack to run a subset (useful for debugging)
|
||||||
//if (index != 20 && index != 21) {
|
//if (index != 20 && index != 21) {
|
||||||
//if test.name != "nil" {
|
//if tc.name != "nil" {
|
||||||
// continue
|
// continue
|
||||||
//}
|
//}
|
||||||
|
|
||||||
t.Logf("\n\ntest #%d (%s) ----------------\n\n", index, name)
|
t.Run(fmt.Sprintf("test #%d (%s)", index, tc.name), func(t *testing.T) {
|
||||||
|
name, code, fail, exp := tc.name, tc.code, tc.fail, tc.exp
|
||||||
|
|
||||||
str := strings.NewReader(code)
|
t.Logf("\n\ntest #%d (%s) ----------------\n\n", index, name)
|
||||||
ast, err := LexParse(str)
|
|
||||||
|
|
||||||
if !fail && err != nil {
|
str := strings.NewReader(code)
|
||||||
t.Errorf("test #%d: lex/parse failed with: %+v", index, err)
|
ast, err := LexParse(str)
|
||||||
continue
|
|
||||||
}
|
|
||||||
if fail && err == nil {
|
|
||||||
t.Errorf("test #%d: lex/parse passed, expected fail", index)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !fail && ast == nil {
|
if !fail && err != nil {
|
||||||
t.Errorf("test #%d: lex/parse was nil", index)
|
t.Errorf("test #%d: lex/parse failed with: %+v", index, err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
if fail && err == nil {
|
||||||
|
t.Errorf("test #%d: lex/parse passed, expected fail", index)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if exp != nil {
|
if !fail && ast == nil {
|
||||||
if !reflect.DeepEqual(ast, exp) {
|
t.Errorf("test #%d: lex/parse was nil", index)
|
||||||
// double check because DeepEqual is different since the func exists
|
return
|
||||||
diff := pretty.Compare(ast, exp)
|
}
|
||||||
if diff != "" { // bonus
|
|
||||||
t.Errorf("test #%d: AST did not match expected", index)
|
|
||||||
// TODO: consider making our own recursive print function
|
|
||||||
t.Logf("test #%d: actual: \n\n%s\n", index, spew.Sdump(ast))
|
|
||||||
t.Logf("test #%d: expected: \n\n%s", index, spew.Sdump(exp))
|
|
||||||
|
|
||||||
// more details, for tricky cases:
|
if exp != nil {
|
||||||
diffable := &pretty.Config{
|
if !reflect.DeepEqual(ast, exp) {
|
||||||
Diffable: true,
|
// double check because DeepEqual is different since the func exists
|
||||||
IncludeUnexported: true,
|
diff := pretty.Compare(ast, exp)
|
||||||
//PrintStringers: false,
|
if diff != "" { // bonus
|
||||||
//PrintTextMarshalers: false,
|
t.Errorf("test #%d: AST did not match expected", index)
|
||||||
//SkipZeroFields: false,
|
// TODO: consider making our own recursive print function
|
||||||
|
t.Logf("test #%d: actual: \n\n%s\n", index, spew.Sdump(ast))
|
||||||
|
t.Logf("test #%d: expected: \n\n%s", index, spew.Sdump(exp))
|
||||||
|
|
||||||
|
// more details, for tricky cases:
|
||||||
|
diffable := &pretty.Config{
|
||||||
|
Diffable: true,
|
||||||
|
IncludeUnexported: true,
|
||||||
|
//PrintStringers: false,
|
||||||
|
//PrintTextMarshalers: false,
|
||||||
|
//SkipZeroFields: false,
|
||||||
|
}
|
||||||
|
t.Logf("test #%d: actual: \n\n%s\n", index, diffable.Sprint(ast))
|
||||||
|
t.Logf("test #%d: expected: \n\n%s", index, diffable.Sprint(exp))
|
||||||
|
t.Logf("test #%d: diff:\n%s", index, diff)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
t.Logf("test #%d: actual: \n\n%s\n", index, diffable.Sprint(ast))
|
|
||||||
t.Logf("test #%d: expected: \n\n%s", index, diffable.Sprint(exp))
|
|
||||||
t.Logf("test #%d: diff:\n%s", index, diff)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func TestType0(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestType1(t *testing.T) {
|
func TestType1(t *testing.T) {
|
||||||
values := map[string]*Type{
|
testCases := map[string]*Type{
|
||||||
"": nil, // error
|
"": nil, // error
|
||||||
"nope": nil, // error
|
"nope": nil, // error
|
||||||
|
|
||||||
@@ -664,7 +664,7 @@ func TestType1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for str, val := range values { // run all the tests
|
for str, val := range testCases { // run all the tests
|
||||||
|
|
||||||
// for debugging
|
// for debugging
|
||||||
//if str != "func(str, int) bool" {
|
//if str != "func(str, int) bool" {
|
||||||
@@ -700,7 +700,7 @@ func TestType1(t *testing.T) {
|
|||||||
|
|
||||||
func TestType2(t *testing.T) {
|
func TestType2(t *testing.T) {
|
||||||
// mapping from golang representation to our expected equivalent
|
// mapping from golang representation to our expected equivalent
|
||||||
values := map[string]*Type{
|
testCases := map[string]*Type{
|
||||||
// basic types
|
// basic types
|
||||||
"bool": {
|
"bool": {
|
||||||
Kind: KindBool,
|
Kind: KindBool,
|
||||||
@@ -1180,7 +1180,7 @@ func TestType2(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for str, typ := range values { // run all the tests
|
for str, typ := range testCases { // run all the tests
|
||||||
// check the type
|
// check the type
|
||||||
reflected := typ.Reflect()
|
reflected := typ.Reflect()
|
||||||
|
|
||||||
@@ -1194,7 +1194,7 @@ func TestType2(t *testing.T) {
|
|||||||
|
|
||||||
func TestType3(t *testing.T) {
|
func TestType3(t *testing.T) {
|
||||||
// functions with named types...
|
// functions with named types...
|
||||||
values := map[string]*Type{
|
testCases := map[string]*Type{
|
||||||
"func(input str) bool": {
|
"func(input str) bool": {
|
||||||
Kind: KindFunc,
|
Kind: KindFunc,
|
||||||
Map: map[string]*Type{
|
Map: map[string]*Type{
|
||||||
@@ -1266,7 +1266,7 @@ func TestType3(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for str, val := range values { // run all the tests
|
for str, val := range testCases { // run all the tests
|
||||||
|
|
||||||
// for debugging
|
// for debugging
|
||||||
//if str != "func(aaa str, bb int) bool" {
|
//if str != "func(aaa str, bb int) bool" {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestPrint1(t *testing.T) {
|
func TestPrint1(t *testing.T) {
|
||||||
values := map[Value]string{
|
testCases := map[Value]string{
|
||||||
&BoolValue{V: true}: "true",
|
&BoolValue{V: true}: "true",
|
||||||
&BoolValue{V: false}: "false",
|
&BoolValue{V: false}: "false",
|
||||||
&StrValue{V: ""}: `""`,
|
&StrValue{V: ""}: `""`,
|
||||||
@@ -82,28 +82,28 @@ func TestPrint1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
d0 := NewMap(NewType("map{str: int}"))
|
d0 := NewMap(NewType("map{str: int}"))
|
||||||
values[d0] = `{}`
|
testCases[d0] = `{}`
|
||||||
|
|
||||||
d1 := NewMap(NewType("map{str: int}"))
|
d1 := NewMap(NewType("map{str: int}"))
|
||||||
d1.Add(&StrValue{V: "answer"}, &IntValue{V: 42})
|
d1.Add(&StrValue{V: "answer"}, &IntValue{V: 42})
|
||||||
values[d1] = `{"answer": 42}`
|
testCases[d1] = `{"answer": 42}`
|
||||||
|
|
||||||
d2 := NewMap(NewType("map{str: int}"))
|
d2 := NewMap(NewType("map{str: int}"))
|
||||||
d2.Add(&StrValue{V: "answer"}, &IntValue{V: 42})
|
d2.Add(&StrValue{V: "answer"}, &IntValue{V: 42})
|
||||||
d2.Add(&StrValue{V: "hello"}, &IntValue{V: 13})
|
d2.Add(&StrValue{V: "hello"}, &IntValue{V: 13})
|
||||||
values[d2] = `{"answer": 42, "hello": 13}`
|
testCases[d2] = `{"answer": 42, "hello": 13}`
|
||||||
|
|
||||||
s0 := NewStruct(NewType("struct{}"))
|
s0 := NewStruct(NewType("struct{}"))
|
||||||
values[s0] = `struct{}`
|
testCases[s0] = `struct{}`
|
||||||
|
|
||||||
s1 := NewStruct(NewType("struct{answer int}"))
|
s1 := NewStruct(NewType("struct{answer int}"))
|
||||||
values[s1] = `struct{answer: 0}`
|
testCases[s1] = `struct{answer: 0}`
|
||||||
|
|
||||||
s2 := NewStruct(NewType("struct{answer int; truth bool; hello str}"))
|
s2 := NewStruct(NewType("struct{answer int; truth bool; hello str}"))
|
||||||
values[s2] = `struct{answer: 0; truth: false; hello: ""}`
|
testCases[s2] = `struct{answer: 0; truth: false; hello: ""}`
|
||||||
|
|
||||||
s3 := NewStruct(NewType("struct{answer int; truth bool; hello str; nested []int}"))
|
s3 := NewStruct(NewType("struct{answer int; truth bool; hello str; nested []int}"))
|
||||||
values[s3] = `struct{answer: 0; truth: false; hello: ""; nested: []}`
|
testCases[s3] = `struct{answer: 0; truth: false; hello: ""; nested: []}`
|
||||||
|
|
||||||
s4 := NewStruct(NewType("struct{answer int; truth bool; hello str; nested []int}"))
|
s4 := NewStruct(NewType("struct{answer int; truth bool; hello str; nested []int}"))
|
||||||
if err := s4.Set("answer", &IntValue{V: 42}); err != nil {
|
if err := s4.Set("answer", &IntValue{V: 42}); err != nil {
|
||||||
@@ -114,9 +114,9 @@ func TestPrint1(t *testing.T) {
|
|||||||
t.Errorf("struct could not set key, error: %v", err)
|
t.Errorf("struct could not set key, error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
values[s4] = `struct{answer: 42; truth: true; hello: ""; nested: []}`
|
testCases[s4] = `struct{answer: 42; truth: true; hello: ""; nested: []}`
|
||||||
|
|
||||||
for v, exp := range values { // run all the tests
|
for v, exp := range testCases { // run all the tests
|
||||||
if s := v.String(); s != exp {
|
if s := v.String(); s != exp {
|
||||||
t.Errorf("value representation of `%s` did not match expected: `%s`", s, exp)
|
t.Errorf("value representation of `%s` did not match expected: `%s`", s, exp)
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ func TestPrint1(t *testing.T) {
|
|||||||
|
|
||||||
func TestReflectValue1(t *testing.T) {
|
func TestReflectValue1(t *testing.T) {
|
||||||
// value string representations in golang can be ambiguous, see below...
|
// value string representations in golang can be ambiguous, see below...
|
||||||
values := map[Value]string{
|
testCases := map[Value]string{
|
||||||
&BoolValue{V: true}: "true",
|
&BoolValue{V: true}: "true",
|
||||||
&BoolValue{V: false}: "false",
|
&BoolValue{V: false}: "false",
|
||||||
&StrValue{V: ""}: ``,
|
&StrValue{V: ""}: ``,
|
||||||
@@ -197,26 +197,26 @@ func TestReflectValue1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
d0 := NewMap(NewType("map{str: int}"))
|
d0 := NewMap(NewType("map{str: int}"))
|
||||||
values[d0] = `map[]`
|
testCases[d0] = `map[]`
|
||||||
|
|
||||||
d1 := NewMap(NewType("map{str: int}"))
|
d1 := NewMap(NewType("map{str: int}"))
|
||||||
d1.Add(&StrValue{V: "answer"}, &IntValue{V: 42})
|
d1.Add(&StrValue{V: "answer"}, &IntValue{V: 42})
|
||||||
values[d1] = `map[answer:42]`
|
testCases[d1] = `map[answer:42]`
|
||||||
|
|
||||||
// multiple key maps are tested below since they have multiple outputs
|
// multiple key maps are tested below since they have multiple outputs
|
||||||
// TODO: https://github.com/golang/go/issues/21095
|
// TODO: https://github.com/golang/go/issues/21095
|
||||||
|
|
||||||
s0 := NewStruct(NewType("struct{}"))
|
s0 := NewStruct(NewType("struct{}"))
|
||||||
values[s0] = `{}`
|
testCases[s0] = `{}`
|
||||||
|
|
||||||
s1 := NewStruct(NewType("struct{Answer int}"))
|
s1 := NewStruct(NewType("struct{Answer int}"))
|
||||||
values[s1] = `{Answer:0}`
|
testCases[s1] = `{Answer:0}`
|
||||||
|
|
||||||
s2 := NewStruct(NewType("struct{Answer int; Truth bool; Hello str}"))
|
s2 := NewStruct(NewType("struct{Answer int; Truth bool; Hello str}"))
|
||||||
values[s2] = `{Answer:0 Truth:false Hello:}`
|
testCases[s2] = `{Answer:0 Truth:false Hello:}`
|
||||||
|
|
||||||
s3 := NewStruct(NewType("struct{Answer int; Truth bool; Hello str; Nested []int}"))
|
s3 := NewStruct(NewType("struct{Answer int; Truth bool; Hello str; Nested []int}"))
|
||||||
values[s3] = `{Answer:0 Truth:false Hello: Nested:[]}`
|
testCases[s3] = `{Answer:0 Truth:false Hello: Nested:[]}`
|
||||||
|
|
||||||
s4 := NewStruct(NewType("struct{Answer int; Truth bool; Hello str; Nested []int}"))
|
s4 := NewStruct(NewType("struct{Answer int; Truth bool; Hello str; Nested []int}"))
|
||||||
if err := s4.Set("Answer", &IntValue{V: 42}); err != nil {
|
if err := s4.Set("Answer", &IntValue{V: 42}); err != nil {
|
||||||
@@ -227,9 +227,9 @@ func TestReflectValue1(t *testing.T) {
|
|||||||
t.Errorf("struct could not set key, error: %v", err)
|
t.Errorf("struct could not set key, error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
values[s4] = `{Answer:42 Truth:true Hello: Nested:[]}`
|
testCases[s4] = `{Answer:42 Truth:true Hello: Nested:[]}`
|
||||||
|
|
||||||
for v, exp := range values { // run all the tests
|
for v, exp := range testCases { // run all the tests
|
||||||
//t.Logf("expected: %s", exp)
|
//t.Logf("expected: %s", exp)
|
||||||
if v == nil {
|
if v == nil {
|
||||||
t.Logf("nil: %s", exp)
|
t.Logf("nil: %s", exp)
|
||||||
@@ -249,7 +249,7 @@ func TestSort1(t *testing.T) {
|
|||||||
values []Value
|
values []Value
|
||||||
sorted []Value
|
sorted []Value
|
||||||
}
|
}
|
||||||
values := []test{
|
testCases := []test{
|
||||||
{
|
{
|
||||||
[]Value{},
|
[]Value{},
|
||||||
[]Value{},
|
[]Value{},
|
||||||
@@ -443,8 +443,8 @@ func TestSort1(t *testing.T) {
|
|||||||
// FIXME: add map and struct sorting tests
|
// FIXME: add map and struct sorting tests
|
||||||
}
|
}
|
||||||
|
|
||||||
for index, test := range values { // run all the tests
|
for index, tc := range testCases { // run all the tests
|
||||||
v1, v2 := test.values, test.sorted
|
v1, v2 := tc.values, tc.sorted
|
||||||
sort.Sort(ValueSlice(v1)) // sort it :)
|
sort.Sort(ValueSlice(v1)) // sort it :)
|
||||||
|
|
||||||
if l1, l2 := len(v1), len(v2); l1 != l2 {
|
if l1, l2 := len(v1), len(v2); l1 != l2 {
|
||||||
|
|||||||
@@ -36,11 +36,11 @@ func TestUnification1(t *testing.T) {
|
|||||||
fail bool
|
fail bool
|
||||||
expect map[interfaces.Expr]*types.Type
|
expect map[interfaces.Expr]*types.Type
|
||||||
}
|
}
|
||||||
values := []test{}
|
testCases := []test{}
|
||||||
|
|
||||||
// this causes a panic, so it can't be used
|
// this causes a panic, so it can't be used
|
||||||
//{
|
//{
|
||||||
// values = append(values, test{
|
// testCases = append(testCases, test{
|
||||||
// "nil",
|
// "nil",
|
||||||
// nil,
|
// nil,
|
||||||
// true, // expect error
|
// true, // expect error
|
||||||
@@ -63,7 +63,7 @@ func TestUnification1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "one res",
|
name: "one res",
|
||||||
ast: stmt,
|
ast: stmt,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -97,7 +97,7 @@ func TestUnification1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "list of strings",
|
name: "list of strings",
|
||||||
ast: stmt,
|
ast: stmt,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -137,7 +137,7 @@ func TestUnification1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "map of int->float",
|
name: "map of int->float",
|
||||||
ast: stmt,
|
ast: stmt,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -179,7 +179,7 @@ func TestUnification1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple struct",
|
name: "simple struct",
|
||||||
ast: stmt,
|
ast: stmt,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -227,7 +227,7 @@ func TestUnification1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "func call",
|
name: "func call",
|
||||||
ast: stmt,
|
ast: stmt,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -282,7 +282,7 @@ func TestUnification1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "func call, multiple ints",
|
name: "func call, multiple ints",
|
||||||
ast: stmt,
|
ast: stmt,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -338,7 +338,7 @@ func TestUnification1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "func call, multiple floats",
|
name: "func call, multiple floats",
|
||||||
ast: stmt,
|
ast: stmt,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -372,7 +372,7 @@ func TestUnification1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "assign from func call or two ints",
|
name: "assign from func call or two ints",
|
||||||
ast: stmt,
|
ast: stmt,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -402,7 +402,7 @@ func TestUnification1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "simple template",
|
name: "simple template",
|
||||||
ast: stmt,
|
ast: stmt,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -439,7 +439,7 @@ func TestUnification1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "complex template",
|
name: "complex template",
|
||||||
ast: stmt,
|
ast: stmt,
|
||||||
fail: false,
|
fail: false,
|
||||||
@@ -470,7 +470,7 @@ func TestUnification1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "single fact unification",
|
name: "single fact unification",
|
||||||
ast: stmt,
|
ast: stmt,
|
||||||
fail: true,
|
fail: true,
|
||||||
@@ -505,7 +505,7 @@ func TestUnification1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
values = append(values, test{
|
testCases = append(testCases, test{
|
||||||
name: "function, wrong arg count",
|
name: "function, wrong arg count",
|
||||||
ast: stmt,
|
ast: stmt,
|
||||||
fail: true,
|
fail: true,
|
||||||
@@ -513,14 +513,18 @@ func TestUnification1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
names := []string{}
|
names := []string{}
|
||||||
for index, test := range values { // run all the tests
|
for index, tc := range testCases { // run all the tests
|
||||||
if util.StrInList(test.name, names) {
|
if tc.name == "" {
|
||||||
t.Errorf("test #%d: duplicate sub test name of: %s", index, test.name)
|
t.Errorf("test #%d: not named", index)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
names = append(names, test.name)
|
if util.StrInList(tc.name, names) {
|
||||||
t.Run(fmt.Sprintf("test #%d (%s)", index, test.name), func(t *testing.T) {
|
t.Errorf("test #%d: duplicate sub test name of: %s", index, tc.name)
|
||||||
ast, fail, expect := test.ast, test.fail, test.expect
|
continue
|
||||||
|
}
|
||||||
|
names = append(names, tc.name)
|
||||||
|
t.Run(fmt.Sprintf("test #%d (%s)", index, tc.name), func(t *testing.T) {
|
||||||
|
ast, fail, expect := tc.ast, tc.fail, tc.expect
|
||||||
|
|
||||||
//str := strings.NewReader(code)
|
//str := strings.NewReader(code)
|
||||||
//ast, err := LexParse(str)
|
//ast, err := LexParse(str)
|
||||||
|
|||||||
Reference in New Issue
Block a user