-
Notifications
You must be signed in to change notification settings - Fork 2
/
pipeline_lexer_test.go
49 lines (46 loc) · 1.36 KB
/
pipeline_lexer_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
package main
import (
"reflect"
"testing"
)
func runLexerTest(t *testing.T, pipeline string, expected []token) {
tokens := lex(pipeline)
if !reflect.DeepEqual(tokens, expected) {
t.Logf("FAIL %s", pipeline)
t.Fatalf("Expected: %+v, Found: %+v", expected, tokens)
} else {
t.Logf("PASS %s", pipeline)
}
}
func TestPipelineLexer(t *testing.T) {
runLexerTest(t, "a", []token{
token{tokenType: identifier_token, tokenValue: "a"},
})
runLexerTest(t, "ab", []token{
token{tokenType: identifier_token, tokenValue: "ab"},
})
runLexerTest(t, "a|b", []token{
token{tokenType: identifier_token, tokenValue: "a"},
token{tokenType: pipe_token},
token{tokenType: identifier_token, tokenValue: "b"},
})
runLexerTest(t, "a+b", []token{
token{tokenType: identifier_token, tokenValue: "a"},
token{tokenType: plus_token},
token{tokenType: identifier_token, tokenValue: "b"},
})
runLexerTest(t, "a-b", []token{
token{tokenType: identifier_token, tokenValue: "a"},
token{tokenType: minus_token},
token{tokenType: identifier_token, tokenValue: "b"},
})
runLexerTest(t, "abcdefg", []token{
token{tokenType: identifier_token, tokenValue: "abcdefg"},
})
runLexerTest(t, "\"a\"", []token{
token{tokenType: string_literal_token, tokenValue: "a"},
})
runLexerTest(t, "\"abcdefg\"", []token{
token{tokenType: string_literal_token, tokenValue: "abcdefg"},
})
}