package main import "testing" func testInput(t *testing.T, s []string, ty int) { for _, input := range s { l := lex(input + "\n") typ, s := l.Lex() if input[0] == '\'' { input = input[1 : len(input)-1] } if typ != ty || s != input { t.Error("expeced", input, "got", s) } } } func TestInteger(t *testing.T) { testInput(t, []string{"1", "¯1", "123"}, INTEGER) } func TestFloat(t *testing.T) { testInput(t, []string{"1.120", "¯1.1", "1e1", "¯1.1e¯1"}, FLOAT) } func TestComplex(t *testing.T) { testInput(t, []string{"1.1J1", "¯1J1", "1J¯1.1", "¯1.1e1J¯1"}, COMPLEX) } func TestString(t *testing.T) { testInput(t, []string{"abc"}, STRING) } func TestQuoted(t *testing.T) { testInput(t, []string{"'abc''xyz'"}, QUOTED) }