-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
52 lines (38 loc) · 869 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"luthor/token"
)
type result struct {
s string
t token.Token
}
func TestLuthor(t *testing.T) {
var index int
expectedResults := []result{
{s: "car", t: token.VARIABLE},
{s: " ", t: token.WS},
{s: "=", t: token.EQ},
{s: " ", t: token.WS},
{s: "123.456", t: token.NUMBER},
{s: " ", t: token.WS},
{s: "+", t: token.ADD},
{s: " ", t: token.WS},
{s: "bus", t: token.VARIABLE},
{s: string(eof), t: token.EOF},
}
reader := strings.NewReader("car = 123.456 + bus")
l := NewLuthor(reader)
for {
expected := expectedResults[index]
tok, str := l.Lex()
assert.Equal(t, expected.s, str, "invalid string")
assert.Equal(t, expected.t.String(), tok.String(), "invalid token")
index++
if tok == token.EOF || tok == token.ILLEGAL {
break
}
}
}