forked from robertkrimen/otto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtin_test.go
92 lines (74 loc) · 2.1 KB
/
builtin_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
package otto
import (
. "./terst"
"testing"
)
func TestString_substr(t *testing.T) {
Terst(t)
test := runTest()
test(`"abc".substr(0,1)`, "a")
test(`"abc".substr(0,2)`, "ab")
test(`"abc".substr(0,3)`, "abc")
test(`"abc".substr(0,4)`, "abc")
test(`"abc".substr(0,9)`, "abc")
test(`"abc".substr(1,1)`, "b")
test(`"abc".substr(1,2)`, "bc")
test(`"abc".substr(1,3)`, "bc")
test(`"abc".substr(1,4)`, "bc")
test(`"abc".substr(1,9)`, "bc")
test(`"abc".substr(2,1)`, "c")
test(`"abc".substr(2,2)`, "c")
test(`"abc".substr(2,3)`, "c")
test(`"abc".substr(2,4)`, "c")
test(`"abc".substr(2,9)`, "c")
test(`"abc".substr(3,1)`, "")
test(`"abc".substr(3,2)`, "")
test(`"abc".substr(3,3)`, "")
test(`"abc".substr(3,4)`, "")
test(`"abc".substr(3,9)`, "")
test(`"abc".substr(0)`, "abc")
test(`"abc".substr(1)`, "bc")
test(`"abc".substr(2)`, "c")
test(`"abc".substr(3)`, "")
test(`"abc".substr(9)`, "")
test(`"abc".substr(-9)`, "abc")
test(`"abc".substr(-3)`, "abc")
test(`"abc".substr(-2)`, "bc")
test(`"abc".substr(-1)`, "c")
test(`"abc".substr(-9, 1)`, "a")
test(`"abc".substr(-3, 1)`, "a")
test(`"abc".substr(-2, 1)`, "b")
test(`"abc".substr(-1, 1)`, "c")
test(`"abc".substr(-1, 2)`, "c")
test(`"abcd".substr(3, 5)`, "d")
}
func Test_builtin_escape(t *testing.T) {
Terst(t)
Is(builtin_escape("abc"), "abc")
Is(builtin_escape("="), "%3D")
Is(builtin_escape("abc=%+32"), "abc%3D%25+32")
Is(builtin_escape("世界"), "%u4E16%u754C")
}
func Test_builtin_unescape(t *testing.T) {
Terst(t)
Is(builtin_unescape("abc"), "abc")
Is(builtin_unescape("=%3D"), "==")
Is(builtin_unescape("abc%3D%25+32"), "abc=%+32")
Is(builtin_unescape("%u4E16%u754C"), "世界")
}
func TestGlobal_escape(t *testing.T) {
Terst(t)
test := runTest()
test(`escape("abc")`, "abc")
test(`escape("=")`, "%3D")
test(`escape("abc=%+32")`, "abc%3D%25+32")
test(`escape("\u4e16\u754c")`, "%u4E16%u754C")
}
func TestGlobal_unescape(t *testing.T) {
Terst(t)
test := runTest()
test(`unescape("abc")`, "abc")
test(`unescape("=%3D")`, "==")
test(`unescape("abc%3D%25+32")`, "abc=%+32")
test(`unescape("%u4E16%u754C")`, "世界")
}