-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstring_test.go
93 lines (77 loc) · 1.98 KB
/
string_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
88
89
90
91
92
93
package gojs
import (
"bytes"
"testing"
)
var (
strtests = []string{"a string", "unicode \u65e5\u672c\u8a9e"}
)
func TestString(t *testing.T) {
str := NewString("a string")
defer str.Release()
}
func TestString2(t *testing.T) {
str := NewString("a string")
defer str.Release()
str.Retain()
str.Release()
}
func TestStringString(t *testing.T) {
for _, item := range strtests {
str := NewString(item)
defer str.Release()
if str.String() != item {
t.Errorf("str.String() returned \"%v\", expected \"%v\"", str.String(), item)
}
if str.Length() != uint32(len([]rune(item))) {
t.Errorf("str.Length() returned \"%v\", expected \"%v\"", str.Length(), len([]rune(item)))
}
}
}
func TestStringBytes(t *testing.T) {
for _, item := range strtests {
str := NewString(item)
defer str.Release()
wantBytes := []byte(item)
gotBytes := str.Bytes()
if !bytes.Equal(wantBytes, gotBytes) {
t.Errorf("%q: want Bytes %q, got %q", item, wantBytes, gotBytes)
}
}
}
func TestStringEqual(t *testing.T) {
lhs := NewString("dummy")
defer lhs.Release()
for _, item := range strtests {
str := NewString(item)
defer str.Release()
if lhs.Equal(str) {
t.Errorf("Strings compared as equal \"%v\", and \"%v\"", lhs, str)
}
if str.Equal(lhs) {
t.Errorf("Strings compared as equal \"%v\", and \"%v\"", str, lhs)
}
if !str.Equal(str) {
t.Errorf("String did not compared as equal to itself \"%v\", and \"%v\"", str)
}
str2 := NewString(item)
defer str2.Release()
if !str.Equal(str2) {
t.Errorf("String did not compared as equal to itself \"%v\", and \"%v\"", str2)
}
}
}
func TestStringEqualToString(t *testing.T) {
lhs := NewString("dummy")
defer lhs.Release()
for _, item := range strtests {
str := NewString(item)
defer str.Release()
if lhs.EqualToString(item) {
t.Errorf("Strings compared as equal \"%v\", and \"%v\"", lhs, item)
}
if !str.EqualToString(item) {
t.Errorf("String did not compare as equal to itself \"%v\"", item)
}
}
}