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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# file : tests/function/string/testscript
# license : MIT; see accompanying LICENSE file
.include ../../common.testscript
: icasecmp
:
{
: equal
:
{
$* <'print $icasecmp([string] "a", [string] "A")' >'true' : string-string
$* <'print $icasecmp([string] "a", "A")' >'true' : string-untyped
$* <'print $icasecmp("a", [string] "A")' >'true' : untyped-string
$* <'print $string.icasecmp("a", "A")' >'true' : untyped-untyped
}
: different
:
{
$* <'print $icasecmp([string] "a", [string] "b")' >'false' : string-string
$* <'print $icasecmp([string] "a", "b")' >'false' : string-untyped
$* <'print $icasecmp("a", [string] "b")' >'false' : untyped-string
$* <'print $string.icasecmp("a", "b")' >'false' : untyped-untyped
}
}
: replace
:
{
: basics
:
{
$* <'print $string.replace( abcb, b, BB)' >'aBBcBB' : expand
$* <'print $string.replace( aabbccbb, bb, B)' >'aaBccB' : shrink
$* <'print $replace([string] abc, b, B)' >'aBc' : typed
$* <'print $replace([string] "", b, B)' >'' : empty
$* <'print $replace([string] bbb, b, "")' >'' : to-empty
}
: icase
:
{
$* <'print $string.replace(abcB, b, X, icase)' >'aXcX'
}
: first
:
{
$* <'print $string.replace(babc, b, B, first_only)' >'Babc' : first
$* <'print $string.replace(abcb, b, B, first_only)' >'aBcb' : middle
$* <'print $string.replace(b, b, B, first_only)' >'B' : only
}
: last
:
{
$* <'print $string.replace(babc, b, B, last_only)' >'baBc' : middle
$* <'print $string.replace(abcb, b, B, last_only)' >'abcB' : last
$* <'print $string.replace(b, b, B, last_only)' >'B' : only
}
: first-and-last
:
{
$* <'print $string.replace(ac, b, B, first_only last_only)' >'ac' : zero
$* <'print $string.replace(abc, b, B, first_only last_only)' >'aBc' : one
$* <'print $string.replace(abcb, b, B, first_only last_only)' >'abcb' : two
$* <'print $string.replace(b, b, B, first_only last_only)' >'B' : only
}
}
: trim
:
{
$* <'print $trim([string] " a ")' >'a' : string
$* <'print $string.trim( " a ")' >'a' : untyped
}
: sort
:
{
$* <'print $sort([strings] a c b a)' >'a a b c' : basics
$* <'print $sort([strings] a c b a, dedup)' >'a b c' : dedup
$* <'print $sort([strings] a C B a, icase)' >'a a B C' : icase
}
: size
:
{
$* <'print $size([string] abc)' >'3' : basics
$* <'print $size([string] )' >'0' : zero
$* <'print $size([strings] a b c)' >'3' : strings
$* <'print $size([string_set] a b b)' >'2' : string-set
$* <'print $size([string_map] a@1 b@2 b@3)' >'2' : string-map
}
: find
:
{
$* <'print $find([strings] x y z, y)' >'true' : basics-true
$* <'print $find([strings] x y z, Y)' >'false' : basics-false
$* <'print $find([strings] x y z, Y, icase)' >'true' : icase
}
: find_index
:
{
$* <'print $find_index([strings] x y z, y)' >'1' : basics-true
$* <'print $find_index([strings] x y z, Y)' >'3' : basics-false
$* <'print $find_index([strings] x y z, Y, icase)' >'1' : icase
}
: keys
:
$* <'print $keys([string_map] a@1 b@2 c@3)' >'a b c'
|