Skip to content

Commit 7dfd4f5

Browse files
committed
config: tests for the parser
1 parent de1c236 commit 7dfd4f5

3 files changed

Lines changed: 70 additions & 73 deletions

File tree

‎config/expr_parse_test.go‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package config
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func TestExprParse(t *testing.T) {
9+
cases := []struct {
10+
Input string
11+
Result Interpolation
12+
Error bool
13+
}{
14+
{
15+
"foo",
16+
nil,
17+
true,
18+
},
19+
20+
{
21+
"var.foo",
22+
&VariableInterpolation{
23+
Variable: &UserVariable{
24+
Name: "foo",
25+
key: "var.foo",
26+
},
27+
},
28+
false,
29+
},
30+
31+
{
32+
"lookup(var.foo, var.bar)",
33+
&FunctionInterpolation{
34+
Func: nil, // Funcs["lookup"]
35+
Args: []Interpolation{
36+
&VariableInterpolation{
37+
Variable: &UserVariable{
38+
Name: "foo",
39+
key: "var.foo",
40+
},
41+
},
42+
&VariableInterpolation{
43+
Variable: &UserVariable{
44+
Name: "bar",
45+
key: "var.bar",
46+
},
47+
},
48+
},
49+
},
50+
false,
51+
},
52+
}
53+
54+
for i, tc := range cases {
55+
actual, err := ExprParse(tc.Input)
56+
if (err != nil) != tc.Error {
57+
t.Fatalf("%d. Error: %s", i, err)
58+
}
59+
60+
// This is jank, but reflect.DeepEqual never has functions
61+
// being the same.
62+
if f, ok := actual.(*FunctionInterpolation); ok {
63+
f.Func = nil
64+
}
65+
66+
if !reflect.DeepEqual(actual, tc.Result) {
67+
t.Fatalf("%d bad: %#v", i, actual)
68+
}
69+
}
70+
}

‎config/expr_test.go‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎config/interpolate_test.go‎

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,6 @@ import (
66
"testing"
77
)
88

9-
/*
10-
func TestNewInterpolation(t *testing.T) {
11-
cases := []struct {
12-
Input string
13-
Result Interpolation
14-
Error bool
15-
}{
16-
{
17-
"foo",
18-
nil,
19-
true,
20-
},
21-
22-
{
23-
"var.foo",
24-
&VariableInterpolation{
25-
Variable: &UserVariable{
26-
Name: "foo",
27-
key: "var.foo",
28-
},
29-
key: "var.foo",
30-
},
31-
false,
32-
},
33-
34-
{
35-
"lookup(var.foo, var.bar)",
36-
&FunctionInterpolation{
37-
Func: nil, // Funcs["lookup"]
38-
Args: []InterpolatedVariable{
39-
&UserVariable{
40-
Name: "foo",
41-
key: "var.foo",
42-
},
43-
&UserVariable{
44-
Name: "bar",
45-
key: "var.bar",
46-
},
47-
},
48-
key: "lookup(var.foo, var.bar)",
49-
},
50-
false,
51-
},
52-
}
53-
54-
for i, tc := range cases {
55-
actual, err := NewInterpolation(tc.Input)
56-
if (err != nil) != tc.Error {
57-
t.Fatalf("%d. Error: %s", i, err)
58-
}
59-
60-
// This is jank, but reflect.DeepEqual never has functions
61-
// being the same.
62-
if f, ok := actual.(*FunctionInterpolation); ok {
63-
f.Func = nil
64-
}
65-
66-
if !reflect.DeepEqual(actual, tc.Result) {
67-
t.Fatalf("%d bad: %#v", i, actual)
68-
}
69-
}
70-
}
71-
*/
72-
739
func TestNewInterpolatedVariable(t *testing.T) {
7410
cases := []struct {
7511
Input string

0 commit comments

Comments
 (0)