-
Notifications
You must be signed in to change notification settings - Fork 1
/
kind_test.go
49 lines (38 loc) · 1006 Bytes
/
kind_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 grokeddit
import "testing"
func TestParsingInvalidKinds(t *testing.T) {
invalidInputs := []string {
"t2",
"",
"no such kind",
}
for _, invalidInput := range invalidInputs {
_, error := ParseKind(invalidInput)
if error == nil {
t.Error("Expected error with input \"%s\"", invalidInput)
}
}
}
func TestParsingValidKinds(t *testing.T) {
validInputs := []struct {
external string
internal KindType
}{
{"t1", Comment},
{"t3", Link},
{"t5", Subreddit},
}
for _, validInput := range validInputs {
internalResult, error := ParseKind(validInput.external)
if error != nil {
t.Errorf("Unexpected error with input \"%s\"", validInput.external)
}
if validInput.internal != internalResult {
t.Errorf("Expected %d but got %d", validInput.internal, internalResult)
}
externalResult := validInput.internal.String()
if externalResult != validInput.external {
t.Errorf("Expected \"%s\" but got \"%s\"", validInput.external, externalResult)
}
}
}