terraform/config/expr_lex_test.go

52 lines
862 B
Go
Raw Normal View History

2014-09-09 23:33:50 +02:00
package config
import (
"io/ioutil"
"path/filepath"
"reflect"
"testing"
)
func TestLex(t *testing.T) {
cases := []struct {
Input string
Output []int
}{
{
"concat.hcl",
[]int{IDENTIFIER, LEFTPAREN,
STRING, COMMA, STRING, COMMA, STRING,
RIGHTPAREN, lexEOF},
},
}
for _, tc := range cases {
d, err := ioutil.ReadFile(filepath.Join(
fixtureDir, "interpolations", tc.Input))
if err != nil {
t.Fatalf("err: %s", err)
}
l := &exprLex{Input: string(d)}
var actual []int
for {
token := l.Lex(new(exprSymType))
actual = append(actual, token)
if token == lexEOF {
break
}
if len(actual) > 500 {
t.Fatalf("Input:%s\n\nExausted.", tc.Input)
}
}
if !reflect.DeepEqual(actual, tc.Output) {
t.Fatalf(
"Input: %s\n\nBad: %#v\n\nExpected: %#v",
tc.Input, actual, tc.Output)
}
}
}