1package parser
2
3import (
4	"testing"
5	"time"
6)
7
8func TestParseSeconds(t *testing.T) {
9	tests := []struct {
10		in string
11		d  time.Duration
12	}{
13		{"", 0},
14		{"4", 4 * time.Second},
15		{"0.1", 100 * time.Millisecond},
16		{"0.050", 50 * time.Millisecond},
17		{"2.003", 2*time.Second + 3*time.Millisecond},
18	}
19
20	for _, test := range tests {
21		d := parseSeconds(test.in)
22		if d != test.d {
23			t.Errorf("parseSeconds(%q) == %v, want %v\n", test.in, d, test.d)
24		}
25	}
26}
27
28func TestParseNanoseconds(t *testing.T) {
29	tests := []struct {
30		in string
31		d  time.Duration
32	}{
33		{"", 0},
34		{"0.1", 0 * time.Nanosecond},
35		{"0.9", 0 * time.Nanosecond},
36		{"4", 4 * time.Nanosecond},
37		{"5000", 5 * time.Microsecond},
38		{"2000003", 2*time.Millisecond + 3*time.Nanosecond},
39	}
40
41	for _, test := range tests {
42		d := parseNanoseconds(test.in)
43		if d != test.d {
44			t.Errorf("parseSeconds(%q) == %v, want %v\n", test.in, d, test.d)
45		}
46	}
47}
48