-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_test.go
More file actions
145 lines (134 loc) · 2.48 KB
/
command_test.go
File metadata and controls
145 lines (134 loc) · 2.48 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package main
import (
"log"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewCommandLine(t *testing.T) {
dir, err := os.Getwd()
if err != nil {
t.Errorf("%v", err)
}
items := []struct {
item []string
result CommandLine
err error
}{
{item: []string{"fmt", "TODO"},
result: CommandLine{
Path: dir,
File: "fmt",
Pattern: "TODO",
},
err: nil},
{item: []string{"math", "TODO"},
result: CommandLine{
Path: dir,
File: "math",
Pattern: "TODO",
},
err: nil},
{item: []string{"strings", "TODO"},
result: CommandLine{
Path: dir,
File: "strings",
Pattern: "TODO",
},
err: nil},
{item: []string{"strings", "NOTE"},
result: CommandLine{
Path: dir,
File: "strings",
Pattern: "NOTE",
},
err: nil},
{item: []string{"runtime", ""},
result: CommandLine{
Path: dir,
File: "runtime",
Pattern: "",
},
err: err},
{item: []string{"", ""},
result: CommandLine{
Path: dir,
File: "",
Pattern: "",
},
err: err},
}
for _, test := range items {
result, err := newCommandLine(test.item[0], test.item[1])
assert.IsType(t, test.err, err)
assert.Equal(t, &test.result, result)
}
}
//getDir gets current directory and returns it.
//this function is only used in Test Functions.
func getDir() string {
dir, err := os.Getwd()
if err != nil {
log.Fatalln(err)
}
return dir
}
func TestRun(t *testing.T) {
var err error
items := []struct {
result CommandLine
err error
}{
{result: CommandLine{
Path: getDir(),
File: "fmt",
Pattern: "TODO",
},
err: nil},
{result: CommandLine{
Path: getDir(),
File: "math",
Pattern: "TODO",
},
err: nil},
{result: CommandLine{
Path: getDir(),
File: "strings",
Pattern: "TODO",
},
err: nil},
{result: CommandLine{
Path: getDir(),
File: "",
Pattern: "",
},
err: err},
}
for _, test := range items {
err := test.result.Run()
if err == nil {
assert.IsType(t, test.err, err)
}
}
}
func TestCLWord(t *testing.T) {
var err error
tests := []struct {
fname string
err error
}{
{fname: "fmt", err: nil},
{fname: "math", err: nil},
{fname: "strings", err: nil},
{fname: "bytes", err: nil},
{fname: "runtime", err: nil},
{fname: "", err: err},
}
for _, test := range tests {
var r CommandLine
err := r.CLWord(test.fname)
if err == nil {
assert.IsType(t, test.err, err)
}
}
}