From 7dfd4f5a3c887d9444303d5183ffefafd187d4e6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 22 Jul 2014 16:08:19 -0700 Subject: [PATCH] config: tests for the parser --- config/expr_parse_test.go | 70 ++++++++++++++++++++++++++++++++++++++ config/expr_test.go | 9 ----- config/interpolate_test.go | 64 ---------------------------------- 3 files changed, 70 insertions(+), 73 deletions(-) create mode 100644 config/expr_parse_test.go delete mode 100644 config/expr_test.go diff --git a/config/expr_parse_test.go b/config/expr_parse_test.go new file mode 100644 index 0000000000..41697d8b62 --- /dev/null +++ b/config/expr_parse_test.go @@ -0,0 +1,70 @@ +package config + +import ( + "reflect" + "testing" +) + +func TestExprParse(t *testing.T) { + cases := []struct { + Input string + Result Interpolation + Error bool + }{ + { + "foo", + nil, + true, + }, + + { + "var.foo", + &VariableInterpolation{ + Variable: &UserVariable{ + Name: "foo", + key: "var.foo", + }, + }, + false, + }, + + { + "lookup(var.foo, var.bar)", + &FunctionInterpolation{ + Func: nil, // Funcs["lookup"] + Args: []Interpolation{ + &VariableInterpolation{ + Variable: &UserVariable{ + Name: "foo", + key: "var.foo", + }, + }, + &VariableInterpolation{ + Variable: &UserVariable{ + Name: "bar", + key: "var.bar", + }, + }, + }, + }, + false, + }, + } + + for i, tc := range cases { + actual, err := ExprParse(tc.Input) + if (err != nil) != tc.Error { + t.Fatalf("%d. Error: %s", i, err) + } + + // This is jank, but reflect.DeepEqual never has functions + // being the same. + if f, ok := actual.(*FunctionInterpolation); ok { + f.Func = nil + } + + if !reflect.DeepEqual(actual, tc.Result) { + t.Fatalf("%d bad: %#v", i, actual) + } + } +} diff --git a/config/expr_test.go b/config/expr_test.go deleted file mode 100644 index 68a6b5fd43..0000000000 --- a/config/expr_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package config - -import ( - "testing" -) - -func TestExprParse(t *testing.T) { - exprParse(&exprLex{input: `lookup(var.foo)`}) -} diff --git a/config/interpolate_test.go b/config/interpolate_test.go index 77188081ea..92bb0f15cb 100644 --- a/config/interpolate_test.go +++ b/config/interpolate_test.go @@ -6,70 +6,6 @@ import ( "testing" ) -/* -func TestNewInterpolation(t *testing.T) { - cases := []struct { - Input string - Result Interpolation - Error bool - }{ - { - "foo", - nil, - true, - }, - - { - "var.foo", - &VariableInterpolation{ - Variable: &UserVariable{ - Name: "foo", - key: "var.foo", - }, - key: "var.foo", - }, - false, - }, - - { - "lookup(var.foo, var.bar)", - &FunctionInterpolation{ - Func: nil, // Funcs["lookup"] - Args: []InterpolatedVariable{ - &UserVariable{ - Name: "foo", - key: "var.foo", - }, - &UserVariable{ - Name: "bar", - key: "var.bar", - }, - }, - key: "lookup(var.foo, var.bar)", - }, - false, - }, - } - - for i, tc := range cases { - actual, err := NewInterpolation(tc.Input) - if (err != nil) != tc.Error { - t.Fatalf("%d. Error: %s", i, err) - } - - // This is jank, but reflect.DeepEqual never has functions - // being the same. - if f, ok := actual.(*FunctionInterpolation); ok { - f.Func = nil - } - - if !reflect.DeepEqual(actual, tc.Result) { - t.Fatalf("%d bad: %#v", i, actual) - } - } -} -*/ - func TestNewInterpolatedVariable(t *testing.T) { cases := []struct { Input string