-
Notifications
You must be signed in to change notification settings - Fork 21
/
terminal_test.go
55 lines (52 loc) · 1.74 KB
/
terminal_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
54
55
package parsec
import "reflect"
import "testing"
func TestTerminal(t *testing.T) {
term := &Terminal{Name: "TERM", Value: "xyz", Position: 2}
if term.GetName() != "TERM" {
t.Errorf("expected %q, got %q", "TERM", term.GetName())
} else if term.IsTerminal() == false {
t.Errorf("expected true")
} else if term.GetValue() != "xyz" {
t.Errorf("expected %q, got %q", "xyz", term.GetValue())
} else if term.GetChildren() != nil {
t.Errorf("expected nil")
} else if term.GetPosition() != 2 {
t.Errorf("expected %v, got %v", 2, term.GetPosition())
}
// check attribute methods.
term.SetAttribute("name", "one").SetAttribute("name", "two")
term.SetAttribute("key", "one")
ref1 := []string{"one", "two"}
ref2 := map[string][]string{
"name": {"one", "two"},
"key": {"one"},
}
if x := term.GetAttribute("name"); reflect.DeepEqual(x, ref1) == false {
t.Errorf("expected %v, got %v", ref1, x)
} else if x := term.GetAttributes(); reflect.DeepEqual(x, ref2) == false {
t.Errorf("expected %v, got %v", ref2, x)
}
}
func TestMaybeNone(t *testing.T) {
mn := MaybeNone("missing")
if string(mn) != mn.GetName() {
t.Errorf("expected %q, got %q", string(mn), mn.GetName())
} else if mn.IsTerminal() == false {
t.Errorf("expected true")
} else if mn.GetValue() != "" {
t.Errorf("expected %q, got %q", "", mn.GetValue())
} else if mn.GetChildren() != nil {
t.Errorf("expected nil")
} else if mn.GetPosition() != -1 {
t.Errorf("expected %v, got %v", -1, mn.GetPosition())
}
// check attribute methods.
mn.SetAttribute("name", "one").SetAttribute("name", "two")
mn.SetAttribute("key", "one")
if x := mn.GetAttribute("name"); x != nil {
t.Errorf("unexpected %v", x)
} else if x := mn.GetAttributes(); x != nil {
t.Errorf("unexpected %v", x)
}
}