-
Notifications
You must be signed in to change notification settings - Fork 0
/
gt_raw_test.go
87 lines (72 loc) · 1.71 KB
/
gt_raw_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package gt_test
import (
"fmt"
"testing"
"github.com/mitranim/gt"
)
func TestRaw(t *testing.T) {
t.Run(`Grow`, func(t *testing.T) {
prev := gt.Raw(nil)
eq(0, len(prev))
eq(0, cap(prev))
next := prev.Grow(1)
sliceNotShared(prev, next)
eq(0, len(next))
eq(1, cap(next))
prev = next
next = prev.Grow(11)
sliceNotShared(prev, next)
eq(0, len(next))
eq(13, cap(next))
prev = next
next = prev.Grow(7)
sliceShared(prev, next)
eq(0, len(next))
eq(13, cap(next))
prev = next
next = prev[:1][1:]
sliceNotShared(prev, next)
eq(0, len(next))
eq(12, cap(next))
prev = next
next = prev.Grow(7)
sliceShared(prev, next)
eq(0, len(next))
eq(12, cap(next))
prev = next
next = prev.Grow(11)
sliceShared(prev, next)
eq(0, len(next))
eq(12, cap(next))
prev = next
next = prev.Grow(13)
sliceNotShared(prev, next)
eq(0, len(next))
eq(37, cap(next))
prev = next
next = prev.Grow(0)
sliceShared(prev, next)
eq(prev, next)
eq(0, len(next))
eq(37, cap(next))
prev = next
})
t.Run(`GoString`, func(t *testing.T) {
test := func(exp string, val gt.Raw) {
t.Helper()
eq(exp, fmt.Sprintf(`%#v`, val))
}
test("gt.Raw(nil)", gt.Raw(nil))
test("gt.Raw(nil)", gt.Raw{})
test("gt.Raw(nil)", gt.Raw(``))
test("gt.Raw(`one`)", gt.Raw(`one`))
test("gt.Raw(`one two`)", gt.Raw(`one two`))
test("gt.Raw(`\t`)", gt.Raw("\t"))
test(`gt.Raw("\v")`, gt.Raw("\v"))
test(`gt.Raw("\r")`, gt.Raw("\r"))
test("gt.Raw(`{\"hello\": \"world\"}`)", gt.Raw(`{"hello": "world"}`))
// Result of `strconv.CanBackquote` which only allows single lines.
// Kind of unfortunate since backquoted strings can include newlines.
test(`gt.Raw("\n")`, gt.Raw("\n"))
})
}