github.com/lamielle/terraform@v0.3.2-0.20141121070651-81f008ba53d5/config/expr_lex_test.go (about)

     1  package config
     2  
     3  import (
     4  	"io/ioutil"
     5  	"path/filepath"
     6  	"reflect"
     7  	"testing"
     8  )
     9  
    10  func TestLex(t *testing.T) {
    11  	cases := []struct {
    12  		Input  string
    13  		Output []int
    14  	}{
    15  		{
    16  			"concat.hcl",
    17  			[]int{IDENTIFIER, LEFTPAREN,
    18  				STRING, COMMA, STRING, COMMA, STRING,
    19  				RIGHTPAREN, lexEOF},
    20  		},
    21  	}
    22  
    23  	for _, tc := range cases {
    24  		d, err := ioutil.ReadFile(filepath.Join(
    25  			fixtureDir, "interpolations", tc.Input))
    26  		if err != nil {
    27  			t.Fatalf("err: %s", err)
    28  		}
    29  
    30  		l := &exprLex{Input: string(d)}
    31  		var actual []int
    32  		for {
    33  			token := l.Lex(new(exprSymType))
    34  			actual = append(actual, token)
    35  
    36  			if token == lexEOF {
    37  				break
    38  			}
    39  
    40  			if len(actual) > 500 {
    41  				t.Fatalf("Input:%s\n\nExausted.", tc.Input)
    42  			}
    43  		}
    44  
    45  		if !reflect.DeepEqual(actual, tc.Output) {
    46  			t.Fatalf(
    47  				"Input: %s\n\nBad: %#v\n\nExpected: %#v",
    48  				tc.Input, actual, tc.Output)
    49  		}
    50  	}
    51  }