-
Notifications
You must be signed in to change notification settings - Fork 1
/
thingid_test.go
53 lines (42 loc) · 1.12 KB
/
thingid_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
package grokeddit
import (
"strings"
"testing"
)
func TestInvalidThingIdParsing(t *testing.T) {
invalidInputs := []string {
"",
"blah ",
}
for _, invalidInput := range invalidInputs {
_, error := ParseId(invalidInput)
if error == nil {
t.Errorf("Expected error for input \"%s\"", invalidInput)
}
}
}
func TestValidThingIdParsing(t *testing.T) {
validInputs := []struct {
externalValue string
internalValue ThingId
}{
{"20ko77", ThingId(121896835)},
{"0", ThingId(0)},
{"3W5E11264SGSF", ThingId(^uint64(0))},
}
for _, validInput := range validInputs {
internalResult, error := ParseId(validInput.externalValue)
if error != nil {
t.Fatalf("Unexpected error for input \"%s\"", validInput.externalValue)
}
if internalResult != validInput.internalValue {
t.Errorf("Expected value %d but got %d", validInput.internalValue, internalResult)
}
externalResult := validInput.internalValue.String()
if externalResult != strings.ToLower(validInput.externalValue) {
t.Errorf("Expected value \"%s\" but got \"%s\"",
strings.ToLower(validInput.externalValue),
externalResult)
}
}
}