-
Notifications
You must be signed in to change notification settings - Fork 2
/
line_test.go
79 lines (65 loc) · 1.3 KB
/
line_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"bytes"
"strings"
"testing"
)
func TestParseLine(t *testing.T) {
line := "#foo#blafasel blubb"
l := &Line{}
l.read(line)
if l.tag != "foo" {
t.Errorf("Can't detect tag for %s", line)
}
if l.cmd != "blafasel blubb" {
t.Errorf("Can't detect tag for %s", line)
}
l = &Line{}
line = "ls -la"
l.read(line)
if l.tag != "" {
t.Errorf("Tag was found in %s", line)
}
if l.cmd != "ls -la" {
t.Errorf("Command was not found in %s", line)
}
}
/*func TestExecute(t *testing.T) {
l := &Line{
cmd: "/not/abdcdef",
}
err := l.execute()
if err != nil {
t.Errorf("Command was executed without error: %s", l.cmd)
}
}*/
func TestPrint(t *testing.T) {
// test without tag
l := &Line{
cmd: "echo foobar",
}
var b bytes.Buffer
l.print(&b, 2, false)
if strings.Compare(b.String(), " 2\techo foobar\n") != 0 {
t.Error("Line was printed incorrect.")
}
// test with tag but without line tag
l = &Line{
cmd: "foo",
}
var d bytes.Buffer
l.print(&d, 3, true)
if strings.Compare(d.String(), " 3\t - \tfoo\n") != 0 {
t.Error("Line was printed incorrect.")
}
// test with tag
l = &Line{
tag: "foo",
cmd: "bar",
}
var c bytes.Buffer
l.print(&c, 4, true)
if strings.Compare(c.String(), " 4\tfoo\tbar\n") != 0 {
t.Error("Line with tag was printed incorrect.")
}
}