-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
entity_test.go
64 lines (56 loc) · 1.42 KB
/
entity_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
53
54
55
56
57
58
59
60
61
62
63
64
package mediawiki
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/tozd/go/x"
)
func TestTime(t *testing.T) {
t.Parallel()
tests := []struct {
time string
precision TimePrecision
}{
{"+1994-01-01T00:00:00Z", Minute},
{"+1952-00-00T00:00:00Z", Year},
{"+0001-00-00T00:00:00Z", Year},
{"-0001-00-00T00:00:00Z", Year},
{"+11994-01-01T00:00:00Z", Minute},
{"+11952-00-00T00:00:00Z", Year},
{"+10001-00-00T00:00:00Z", Year},
{"-10001-00-00T00:00:00Z", Year},
{"-13798000000-00-00T00:00:00Z", Year},
}
for _, test := range tests {
t.Run(test.time, func(t *testing.T) {
t.Parallel()
p, err := parseTime(test.time)
require.NoError(t, err, "% -+#.1v", err)
s := formatTime(p, test.precision)
assert.Equal(t, test.time, s)
})
}
}
func TestAmount(t *testing.T) {
t.Parallel()
tests := []string{
"+123.34",
"-123.34",
"+0.3333333333333333333333333333333333333333333333333333333333333333333333333333",
"-2.0000000000000000000000000000000000000000000000000000000000000000000000000001",
"+0",
}
for _, test := range tests {
t.Run(test, func(t *testing.T) {
t.Parallel()
in := `"` + test + `"`
var a Amount
err := json.Unmarshal([]byte(in), &a)
require.NoError(t, err)
out, err := x.MarshalWithoutEscapeHTML(a)
require.NoError(t, err, "% -+#.1v", err)
assert.Equal(t, in, string(out))
})
}
}