aboutsummaryrefslogtreecommitdiff
path: root/lexer_test.go
blob: e5b4b700d3237606ccfa2fbd6fdc2d176d34634b (plain)
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
package main

import "testing"

func testInput(t *testing.T, ty int, s ...string) {
	for _, input := range s {
		yy := new(yySymType)
		l := lex(input + "\n")
		typ := l.Lex(yy)
		if input[0] == '\'' {
			input = input[1 : len(input)-1]
		}
		if typ != ty || yy.sval != input {
			t.Error("expeced", input, "got", yy.sval)
		}
	}
}

func TestInteger(t *testing.T) {
	testInput(t, INTEGER, "1", "¯1", "123")
}

func TestFloat(t *testing.T) {
	testInput(t, FLOAT, "1.120", "¯1.1", "1e1", "¯1.1e¯1")
}

func TestComplex(t *testing.T) {
	testInput(t, COMPLEX, "1.1J1", "¯1J1", "1J¯1.1", "¯1.1e1J¯1")
}

func TestString(t *testing.T) {
	testInput(t, STRING, "abc", "abc xyz")
}

func TestQuoted(t *testing.T) {
	testInput(t, QUOTED, "'abc'", "'abc''xyz'")
}