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:
James Shubin
2018-11-18 20:10:05 -05:00
parent 958d3f6094
commit 48beea3884
8 changed files with 244 additions and 233 deletions

View File

@@ -305,11 +305,11 @@ func TestInterpretMany(t *testing.T) {
fail bool
graph *pgraph.Graph
}
values := []test{}
testCases := []test{}
{
graph, _ := pgraph.NewGraph("g")
values = append(values, test{ // 0
testCases = append(testCases, test{ // 0
"nil",
``,
false,
@@ -318,7 +318,7 @@ func TestInterpretMany(t *testing.T) {
}
{
graph, _ := pgraph.NewGraph("g")
values = append(values, test{ // 1
testCases = append(testCases, test{ // 1
name: "empty",
code: ``,
fail: false,
@@ -332,7 +332,7 @@ func TestInterpretMany(t *testing.T) {
i := int64(42 + 13)
x.Int64Ptr = &i
graph.AddVertex(x)
values = append(values, test{
testCases = append(testCases, test{
name: "simple addition",
code: `
test "t" {
@@ -350,7 +350,7 @@ func TestInterpretMany(t *testing.T) {
i := int64(42 + 13 + 99)
x.Int64Ptr = &i
graph.AddVertex(x)
values = append(values, test{
testCases = append(testCases, test{
name: "triple addition",
code: `
test "t" {
@@ -368,7 +368,7 @@ func TestInterpretMany(t *testing.T) {
i := int64(42 + 13 - 99)
x.Int64Ptr = &i
graph.AddVertex(x)
values = append(values, test{
testCases = append(testCases, test{
name: "triple addition/subtraction",
code: `
test "t" {
@@ -386,7 +386,7 @@ func TestInterpretMany(t *testing.T) {
s1 := "hello"
x1.StringPtr = &s1
graph.AddVertex(x1)
values = append(values, test{
testCases = append(testCases, test{
name: "single include",
code: `
class c1($a, $b) {
@@ -410,7 +410,7 @@ func TestInterpretMany(t *testing.T) {
x1.StringPtr = &s1
x2.StringPtr = &s2
graph.AddVertex(x1, x2)
values = append(values, test{
testCases = append(testCases, test{
name: "double include",
code: `
class c1($a, $b) {
@@ -435,7 +435,7 @@ func TestInterpretMany(t *testing.T) {
//x1.StringPtr = &s1
//x2.Int64Ptr = &i2
//graph.AddVertex(x1, x2)
values = append(values, test{
testCases = append(testCases, test{
name: "double include different types error",
code: `
class c1($a, $b) {
@@ -466,7 +466,7 @@ func TestInterpretMany(t *testing.T) {
x1.StringPtr = &s1
x2.StringPtr = &s2
graph.AddVertex(x1, x2)
values = append(values, test{
testCases = append(testCases, test{
name: "double include different types allowed",
code: `
class c1($a, $b) {
@@ -494,7 +494,7 @@ func TestInterpretMany(t *testing.T) {
// x1.StringPtr = &s1
// x2.StringPtr = &s2
// graph.AddVertex(x1, x2)
// values = append(values, test{
// testCases = append(testCases, test{
// name: "double include different printf types allowed",
// code: `
// import "fmt"
@@ -520,7 +520,7 @@ func TestInterpretMany(t *testing.T) {
x1.StringPtr = &s1
x2.StringPtr = &s2
graph.AddVertex(x1, x2)
values = append(values, test{
testCases = append(testCases, test{
name: "double include with variable in parent scope",
code: `
$foo = "hey"
@@ -546,7 +546,7 @@ func TestInterpretMany(t *testing.T) {
x1.StringPtr = &s1
x2.StringPtr = &s2
graph.AddVertex(x1, x2)
values = append(values, test{
testCases = append(testCases, test{
name: "double include with out of order variable in parent scope",
code: `
include c1("t1")
@@ -569,7 +569,7 @@ func TestInterpretMany(t *testing.T) {
s1 := "hello"
x1.StringPtr = &s1
graph.AddVertex(x1)
values = append(values, test{
testCases = append(testCases, test{
name: "duplicate include identical",
code: `
include c1("t1", "hello")
@@ -591,7 +591,7 @@ func TestInterpretMany(t *testing.T) {
s1 := "hello"
x1.StringPtr = &s1
graph.AddVertex(x1)
values = append(values, test{
testCases = append(testCases, test{
name: "duplicate include non-identical",
code: `
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",
code: `
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",
code: `
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",
code: `
include c1("hello", 42) # added second arg
@@ -665,7 +665,7 @@ func TestInterpretMany(t *testing.T) {
x1.StringPtr = &s1
x2.StringPtr = &s2
graph.AddVertex(x1, x2)
values = append(values, test{
testCases = append(testCases, test{
name: "nested classes 1",
code: `
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",
code: `
import "fmt"
@@ -722,7 +722,7 @@ func TestInterpretMany(t *testing.T) {
// TODO: recursive classes are not currently supported (should they be?)
//{
// graph, _ := pgraph.NewGraph("g")
// values = append(values, test{
// testCases = append(testCases, test{
// name: "recursive classes 0",
// code: `
// include c1(0) # start at zero
@@ -744,7 +744,7 @@ func TestInterpretMany(t *testing.T) {
// s0 := "count is 3"
// x0.StringPtr = &s0
// graph.AddVertex(x0)
// values = append(values, test{
// testCases = append(testCases, test{
// name: "recursive classes 1",
// code: `
// import "fmt"
@@ -782,7 +782,7 @@ func TestInterpretMany(t *testing.T) {
// x2.StringPtr = &s2
// x3.StringPtr = &s3
// graph.AddVertex(x0, x1, x2, x3)
// values = append(values, test{
// testCases = append(testCases, test{
// name: "recursive classes 2",
// code: `
// import "fmt"
@@ -810,7 +810,7 @@ func TestInterpretMany(t *testing.T) {
//}
// TODO: remove this test if we ever support recursive classes
{
values = append(values, test{
testCases = append(testCases, test{
name: "recursive classes fail 1",
code: `
import "fmt"
@@ -831,7 +831,7 @@ func TestInterpretMany(t *testing.T) {
}
// TODO: remove this test if we ever support recursive classes
{
values = append(values, test{
testCases = append(testCases, test{
name: "recursive classes fail 2",
code: `
import "fmt"
@@ -861,8 +861,8 @@ func TestInterpretMany(t *testing.T) {
}
names := []string{}
for index, test := range values { // run all the tests
name, code, fail, exp := test.name, test.code, test.fail, test.graph
for index, tc := range testCases { // run all the tests
name, code, fail, exp := tc.name, tc.code, tc.fail, tc.graph
if name == "" {
name = "<sub test not named>"
@@ -874,7 +874,7 @@ func TestInterpretMany(t *testing.T) {
names = append(names, name)
//if index != 3 { // hack to run a subset (useful for debugging)
//if test.name != "nil" {
//if tc.name != "nil" {
// continue
//}