-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_test.go
47 lines (42 loc) · 913 Bytes
/
parser_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
package main
import (
"testing"
"time"
)
func TestParseSeconds(t *testing.T) {
tests := []struct {
in string
d time.Duration
}{
{"", 0},
{"4", 4 * time.Second},
{"0.1", 100 * time.Millisecond},
{"0.050", 50 * time.Millisecond},
{"2.003", 2*time.Second + 3*time.Millisecond},
}
for _, test := range tests {
d := parseSeconds(test.in)
if d != test.d {
t.Errorf("parseSeconds(%q) == %v, want %v\n", test.in, d, test.d)
}
}
}
func TestParseNanoseconds(t *testing.T) {
tests := []struct {
in string
d time.Duration
}{
{"", 0},
{"0.1", 0 * time.Nanosecond},
{"0.9", 0 * time.Nanosecond},
{"4", 4 * time.Nanosecond},
{"5000", 5 * time.Microsecond},
{"2000003", 2*time.Millisecond + 3*time.Nanosecond},
}
for _, test := range tests {
d := parseNanoseconds(test.in)
if d != test.d {
t.Errorf("parseSeconds(%q) == %v, want %v\n", test.in, d, test.d)
}
}
}