-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_test.go
64 lines (49 loc) · 954 Bytes
/
text_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 domain_test
import (
"testing"
"github.com/sokool/domain"
)
func TestBodyJson(t *testing.T) {
n := domain.MustText("hi there")
if n.IsZero() {
t.Fatalf("expected not zero, got %s", n)
}
if n.Words() != 2 {
t.Fatal()
}
if !n.Word(0).Is("hi") || !n.Word(1).Is("there") {
t.Fatal("x")
}
if s := n.Length(); s != 8 {
t.Fatalf("wrong size, got %d", s)
}
if !n.LengthBetween(0, n.Length()) {
t.Fatalf("wrong length")
}
b, err := n.MarshalJSON()
if err != nil {
t.Fatal(err)
}
var m domain.Text
if err = m.UnmarshalJSON(b); err != nil {
t.Fatal(err)
}
if n != m {
t.Fatalf("expected `%s`, got `%s`", n, m)
}
}
func TestJSONMultiUnmarshal(t *testing.T) {
n := domain.MustText("Hello\nWorld")
for i := 0; i < 5; i++ {
x, err := n.MarshalJSON()
if err != nil {
t.Fatal(err)
}
if err = n.UnmarshalJSON(x); err != nil {
t.Fatal(err)
}
}
if !n.Is("Hello\nWorld") {
t.Fatal("uuu")
}
}