-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpipeline_parser_test.go
53 lines (49 loc) · 1.1 KB
/
pipeline_parser_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
53
package main
import (
"reflect"
"testing"
)
func runParserTest(t *testing.T, pipeline string, expected []PipelineNode) {
nodes := parsePipeline(pipeline)
if !reflect.DeepEqual(nodes, expected) {
t.Logf("FAIL %s", pipeline)
t.Fatalf("Expected: %+v, Found: %+v", expected, nodes)
} else {
t.Logf("PASS %s", pipeline)
}
}
func TestPipelineParser(t *testing.T) {
runParserTest(t, "a", []PipelineNode{
Command{Command: "a"},
})
runParserTest(t, "ab", []PipelineNode{
Command{Command: "ab"},
})
runParserTest(t, "a|b", []PipelineNode{
Command{Command: "a"},
Command{Command: "b"},
})
}
func TestPipelineParserExpressions(t *testing.T) {
runParserTest(t, "a+b", []PipelineNode{
UnionNode{
Left: Command{Command: "a"},
Right: Command{Command: "b"},
},
})
runParserTest(t, "a-b", []PipelineNode{
DifferenceNode{
Left: Command{Command: "a"},
Right: Command{Command: "b"},
},
})
runParserTest(t, "a-b+c", []PipelineNode{
DifferenceNode{
Left: Command{Command: "a"},
Right: UnionNode{
Left: Command{Command: "b"},
Right: Command{Command: "c"},
},
},
})
}