aboutsummaryrefslogtreecommitdiff
path: root/tests/function
diff options
context:
space:
mode:
Diffstat (limited to 'tests/function')
-rw-r--r--tests/function/builtin/testscript32
-rw-r--r--tests/function/integer/buildfile4
-rw-r--r--tests/function/integer/testscript41
-rw-r--r--tests/function/json/buildfile4
-rw-r--r--tests/function/json/testscript257
-rw-r--r--tests/function/name/buildfile4
-rw-r--r--tests/function/name/testscript68
-rw-r--r--tests/function/path/testscript142
-rw-r--r--tests/function/regex/testscript116
-rw-r--r--tests/function/string/testscript83
10 files changed, 748 insertions, 3 deletions
diff --git a/tests/function/builtin/testscript b/tests/function/builtin/testscript
index 3d31ca2..04e8bd8 100644
--- a/tests/function/builtin/testscript
+++ b/tests/function/builtin/testscript
@@ -53,6 +53,34 @@
$* <'print $empty(abc)' >'false' : name
$* <'print $empty(abc cxx{foo})' >'false' : names
$* <'print $empty([bool] false)' >'false' : bool
+ $* <'print $empty([json] null)' >'true' : json-null
+ $* <'print $empty([json] "[]")' >'true' : json-array
+ $* <'print $empty([json] "{}")' >'true' : json-object
+}
+
+: first-second
+:
+{
+ $* <'print $first(a@1)' >'a' : first
+ $* <'print $second(a@1)' >'1' : second
+
+ $* <'print $first(@1)' >'{}' : first-empty
+ $* <'print $second(a@)' >'{}' : second-empty
+
+ $* <'print $first(1)' >'[null]' : first-null
+ $* <'print $second(a)' >'[null]' : second-null
+
+ $* <'print $first(1, true)' >'1' : first-all
+ $* <'print $second(a, true)' >'a' : second-all
+
+ $* <'print $first(0 a@1 b@2 c@ 4)' >'a b c' : firsts
+ $* <'print $second(z a@1 b@2 @3 d)' >'1 2 3' : seconds
+
+ $* <'print $first(0 a@1 b@2 c@ 4, true)' >'0 a b c 4' : firsts-all
+ $* <'print $second(z a@1 b@2 @3 d, true)' >'z 1 2 3 d' : seconds-all
+
+ $* <'print $first([name_pair] a@1)' >'a' : first-typed
+ $* <'print $second([name_pair] a@1)' >'1' : second-typed
}
: identity
@@ -86,8 +114,8 @@
: likely is set at the time of login, and on Windows it is set by build2 on
: startup.
:
- : @@ Use a custom variable, when an ability to set environment variables in
- : testscript is implemented.
+ : @@ TMP Use a custom variable, when an ability to set environment variables
+ : in testscript is implemented. It is now!
:
{
: string
diff --git a/tests/function/integer/buildfile b/tests/function/integer/buildfile
new file mode 100644
index 0000000..308fe09
--- /dev/null
+++ b/tests/function/integer/buildfile
@@ -0,0 +1,4 @@
+# file : tests/function/integer/buildfile
+# license : MIT; see accompanying LICENSE file
+
+./: testscript $b
diff --git a/tests/function/integer/testscript b/tests/function/integer/testscript
new file mode 100644
index 0000000..ad2d3bb
--- /dev/null
+++ b/tests/function/integer/testscript
@@ -0,0 +1,41 @@
+# file : tests/function/integer/testscript
+# license : MIT; see accompanying LICENSE file
+
+.include ../../common.testscript
+
+: integer-sequence
+:
+{
+ $* <'print $integer_sequence(1, 3)' >'1 2' : basics
+ $* <'print $integer_sequence(1, 0)' >'' : empty
+ $* <'print $integer_sequence(0, 8, 2)' >'0 2 4 6' : step
+}
+
+: string
+:
+{
+ $* <'print $string([uint64] 0xffff)' >'65535' : uint
+ $* <'print $string([uint64] 0xffff, 16)' >'0xffff' : uint-hex
+ $* <'print $string([uint64] 0xffff, 16, 8)' >'0x0000ffff' : uint-hex-width
+}
+
+: sort
+:
+{
+ $* <'print $sort([uint64s] 0 2 1 000)' >'0 0 1 2' : basics
+ $* <'print $sort([uint64s] 0 2 1 000, dedup)' >'0 1 2' : dedup
+}
+
+: find
+:
+{
+ $* <'print $find([uint64s] 1 2 3, 2)' >'true' : basics-true
+ $* <'print $find([uint64s] 1 2 3, 0)' >'false' : basics-false
+}
+
+: find_index
+:
+{
+ $* <'print $find_index([int64s] -1 -2 -3, -2)' >'1' : basics-true
+ $* <'print $find_index([int64s] -1 -2 -3, 0)' >'3' : basics-false
+}
diff --git a/tests/function/json/buildfile b/tests/function/json/buildfile
new file mode 100644
index 0000000..45c60d2
--- /dev/null
+++ b/tests/function/json/buildfile
@@ -0,0 +1,4 @@
+# file : tests/function/json/buildfile
+# license : MIT; see accompanying LICENSE file
+
+./: testscript $b
diff --git a/tests/function/json/testscript b/tests/function/json/testscript
new file mode 100644
index 0000000..54e524f
--- /dev/null
+++ b/tests/function/json/testscript
@@ -0,0 +1,257 @@
+# file : tests/function/json/testscript
+# license : MIT; see accompanying LICENSE file
+
+# See also tests in type/json/.
+
+.include ../../common.testscript
+
+: type
+:
+$* <<EOI >>EOO
+print $value_type([json] )
+print $value_type([json] null)
+print $value_type([json] true)
+print $value_type([json] 123)
+print $value_type([json] -123)
+print $value_type([json] 123, true)
+print $value_type([json] -123, true)
+print $value_type([json] 1 2 3)
+print $value_type([json] one@1 two@2 three@3)
+
+j = [json] one@1 two@2 three@3
+i = [uint64] 1
+m = ($j[$i])
+print $value_type($j[$i])
+print $value_type($m)
+EOI
+null
+null
+boolean
+number
+number
+unsigned number
+signed number
+array
+object
+object
+object
+EOO
+
+: value-size
+:
+$* <<EOI >>EOO
+print $value_size([json] null)
+print $value_size([json] true)
+print $value_size([json] 123)
+print $value_size([json] abc)
+print $size([string] ([json] abc)) # @@ Should be 3 (quoted, type hint).
+print $value_size([json] 1 2 3)
+print $value_size([json] one@1 two@2 three@3)
+
+print $array_size([json] 1 2 3)
+print $array_size([json] null)
+EOI
+0
+1
+1
+1
+5
+3
+3
+3
+0
+EOO
+
+: member
+:
+$* <<EOI >>EOO
+j = [json] one@1 two@2 three@3
+i = [uint64] 1
+m = ($j[$i])
+print $member_name($j[$i]) $member_value($j[$i])
+print $member_name($m) $member_value($m)
+for m: $j
+ print $member_name($m) $member_value($m)
+EOI
+two 2
+two 2
+one 1
+two 2
+three 3
+EOO
+
+: names
+:
+$* <<EOI >>EOO
+j = [json] one@1 two@2 three@3
+for n: $object_names($j)
+ print $n ($j[$n])
+
+print $object_names([json] null)
+EOI
+one 1
+two 2
+three 3
+
+EOO
+
+: find
+:
+$* <<EOI >>EOO
+j = [json] 1 ([json] one@1 two@2) 2 true 3 null 4 abc -5 null ([json] 1 2 3)
+print $array_find_index($j, null)
+print $array_find_index($j, true)
+print $array_find_index($j, 3)
+print $array_find_index($j, 0x4)
+print $array_find_index($j, -5)
+print $array_find_index($j, abc)
+print $array_find_index($j, [json] 1 2 3)
+print $array_find_index($j, [json] two@2 one@1)
+print $array_find_index($j, [json] 1 2)
+print $array_find_index($j, [json] one@1)
+print $array_find_index($j, [json] one@1 two@2 three@3)
+print $array_find_index($j, [json] one@1 TWO@3)
+print $array_find_index($j, [json] one@1 two@3)
+print $array_find_index([json] null, 1)
+EOI
+5
+3
+4
+6
+8
+7
+10
+1
+11
+11
+11
+11
+11
+0
+EOO
+
+: parse
+:
+{
+ : basics
+ :
+ $* <<EOI >>EOO
+ print $json.parse('[123, "abc", {"one":1, "two":2}]')
+ EOI
+ [123,"abc",{"one":1,"two":2}]
+ EOO
+
+ : diagnostics-invalid-input
+ :
+ $* <<EOI 2>>EOE != 0
+ print $json.parse('{"one":, "two":2}]')
+ EOI
+ error: invalid json input: unexpected byte ',' in value
+ info: line 1, column 8, byte offset 8
+ <stdin>:1:8: info: while calling json.parse(<untyped>)
+ EOE
+
+ : diagnostics-duplicate-input
+ :
+ $* <<EOI 2>>EOE != 0
+ print $json.parse('{"one":1, "one":2}]')
+ EOI
+ error: invalid json input: duplicate object member 'one'
+ info: line 1, column 11, byte offset 15
+ <stdin>:1:8: info: while calling json.parse(<untyped>)
+ EOE
+}
+
+: serialize
+:
+{
+ : basics
+ :
+ $* <<EOI >>EOO
+ j = [json] 123 abc ([json] one@1 two@2)
+ print $json.serialize($j)
+ print $json.serialize($j, 0)
+ EOI
+ [
+ 123,
+ "abc",
+ {
+ "one": 1,
+ "two": 2
+ }
+ ]
+ [123,"abc",{"one":1,"two":2}]
+ EOO
+
+ : diagnostics
+ :
+ if false
+ {
+ # This is not easy to trigger normally so we have a normally-disabled
+ # special hack in the $json.serialize() implementation to trigger this.
+ #
+ $* <<EOI 2>>EOE != 0
+ print $json.serialize([json] deadbeef)
+ EOI
+ error: invalid json value: invalid UTF-8 text
+ info: while serializing string value
+ info: offending byte offset 4
+ <stdin>:1:8: info: while calling json.serialize(json)
+ EOE
+ }
+
+}
+
+: load
+:
+{
+ : basics
+ :
+ cat <<EOI >=input.json;
+ {
+ "str":"abc",
+ "num":123,
+ "arr":[1, 2, 3],
+ "obj":{"one":1, "two":2, "three":3}
+ }
+ EOI
+ $* <<EOI >>EOO
+ j = $json.load(input.json)
+ for m: $j
+ print $member_name($m) $member_value($m)
+ EOI
+ str abc
+ num 123
+ arr [1,2,3]
+ obj {"one":1,"two":2,"three":3}
+ EOO
+
+ : diagnostics
+ :
+ cat <<EOI >=input.json;
+ {
+ "str":"abc",
+ "num":,
+ "arr":[1, 2, 3],
+ "obj":{"one":1, "two":2, "three":3}
+ }
+ EOI
+ $* <<EOI 2>>EOE != 0
+ j = $json.load(input.json)
+ EOI
+ input.json:3:9: error: invalid json input: unexpected byte ',' in value
+ info: byte offset 26
+ <stdin>:1:6: info: while calling json.load(<untyped>)
+ EOE
+}
+
+: size
+:
+{
+ $* <'print $size([json_set] a b b)' >'2' : json-set
+ $* <'print $size([json_map] a@1 b@2 b@3)' >'2' : json-map
+}
+
+: keys
+:
+$* <'print $keys([json_map] 2@([json] a@1 b@2 c@3) 1@([json] 1 2 3))' >'[1,2]'
diff --git a/tests/function/name/buildfile b/tests/function/name/buildfile
new file mode 100644
index 0000000..48be4c3
--- /dev/null
+++ b/tests/function/name/buildfile
@@ -0,0 +1,4 @@
+# file : tests/function/name/buildfile
+# license : MIT; see accompanying LICENSE file
+
+./: testscript $b
diff --git a/tests/function/name/testscript b/tests/function/name/testscript
new file mode 100644
index 0000000..4588e1d
--- /dev/null
+++ b/tests/function/name/testscript
@@ -0,0 +1,68 @@
+# file : tests/function/name/testscript
+# license : MIT; see accompanying LICENSE file
+
+.include ../../common.testscript
+
+: is_a
+:
+{
+ $* <'print $is_a(file{foo}, path_target)' >'true' : basics-true
+ $* <'print $is_a(alias{foo}, path_target)' >'false' : basics-false
+ $* <'print $is_a(file{foo}@./, path_target)' >'true' : out
+ $* <<EOI >'true' : derived
+ define txt: file
+ print $is_a(txt{foo}, path_target)
+ EOI
+}
+
+: filter
+:
+{
+ $* <<EOI >'file{foo}@./ txt{baz}' : basics
+ define txt: file
+ print $filter(file{foo}@./ alias{bar} dir{./} txt{baz}, file)
+ EOI
+
+ $* <<EOI >'file{foo}@./ txt{baz}' : basics-out
+ define txt: file
+ print $filter_out(file{foo}@./ alias{bar} dir{./} txt{baz}, alias)
+ EOI
+
+ $* <<EOI >'file{foo}@./ dir{./} txt{baz}' : multiple
+ define txt: file
+ print $filter(file{foo}@./ alias{bar} dir{./} txt{baz}, file dir)
+ EOI
+
+ $* <<EOI >'file{foo}@./ alias{bar}' : multiple-out
+ define txt: file
+ print $filter_out(file{foo}@./ alias{bar} dir{./} txt{baz}, txt dir)
+ EOI
+}
+
+: size
+:
+{
+ $* <'print $size(a b c@./)' >'3' : basics
+ $* <'print $type($size(a))' >'uint64' : type
+}
+
+: sort
+:
+{
+ $* <'print $sort(d/t{a} t{c b} d/t{a})' >'t{b} t{c} d/t{a} d/t{a}' : basics
+ $* <'print $sort(d/t{a} t{c b} d/t{a}, dedup)' >'t{b} t{c} d/t{a}' : dedup
+}
+
+: find
+:
+{
+ $* <'print $find([names] d/t{a} t{a b}, t{a})' >'true' : basics-true
+ $* <'print $find([names] d/t{a} t{a b}, d/t{b})' >'false' : basics-false
+}
+
+: find_index
+:
+{
+ $* <'print $find_index([names] d/t{a} t{a b}, t{a})' >'1' : basics-true
+ $* <'print $find_index([names] d/t{a} t{a b}, d/t{b})' >'3' : basics-false
+}
diff --git a/tests/function/path/testscript b/tests/function/path/testscript
index ad76513..1ed89ca 100644
--- a/tests/function/path/testscript
+++ b/tests/function/path/testscript
@@ -3,10 +3,83 @@
.include ../../common.testscript
-posix = ($cxx.target.class != 'windows')
+windows = ($cxx.target.class == 'windows')
+posix = (!$windows)
s = ($posix ? '/' : '\')
+: posix-string
+:
+{
+ : relative
+ :
+ {
+ s = ($posix ? '/' : '\\')
+
+ $* <"print \$posix_string\([path] a$(s)b)" >'a/b' : path
+ $* <"print \$posix_string\([paths] a$(s)b a$(s)c$(s))" >'a/b a/c' : paths
+ $* <"print \$posix_string\([dir_path] a$(s)b)" >'a/b' : dir-path
+ $* <"print \$posix_string\([dir_paths] a$(s)b a$(s)c$(s))" >'a/b a/c' : dir-paths
+ $* <"print \$path.posix_string\(a$(s)b a$(s)c$(s))" >'a/b a/c' : untyped
+ }
+
+ : absolute
+ :
+ {
+ if $posix
+ {
+ $* <'print $posix_string([paths] /a/b /a/c/)' >'/a/b /a/c' : paths
+ $* <'print $posix_string([dir_paths] /a/b /a/c/)' >'/a/b /a/c' : dir-paths
+ $* <'print $posix_string([dir_path] /)' >'/' : root-dir
+ $* <'print $path.posix_string(/a/b /a/c/)' >'/a/b /a/c' : untyped
+ }
+ else
+ {
+ $* <'print $posix_string([paths] "c:\\a\\b" "C:\\a\\c\\")' >'c:/a/b C:/a/c' : paths
+ $* <'print $posix_string([dir_paths] "c:\\a\\b" "C:\\a\\c\\")' >'c:/a/b C:/a/c' : dir-paths
+ $* <'print $posix_string([dir_paths] "c:\\" "C:")' >'c:/ C:/' : root-dir
+ $* <'print $path.posix_string("c:\\a\\b" "C:\\a\\c\\")' >'c:/a/b C:/a/c' : untyped
+ $* <'print $path.posix_string("c:\\" "C:")' >'c:/ C:/' : untyped-root
+ }
+ }
+}
+
+: posix-representation
+:
+{
+ : relative
+ :
+ {
+ s = ($posix ? '/' : '\\')
+
+ $* <"print \$posix_representation\([path] a$(s)b)" >'a/b' : path
+ $* <"print \$posix_representation\([paths] a$(s)b a$(s)c$(s))" >'a/b a/c/' : paths
+ $* <"print \$posix_representation\([dir_path] a$(s)b)" >'a/b/' : dir-path
+ $* <"print \$posix_representation\([dir_paths] a$(s)b a$(s)c$(s))" >'a/b/ a/c/' : dir-paths
+ $* <"print \$path.posix_representation\(a$(s)b a$(s)c$(s))" >'a/b a/c/' : untyped
+ }
+
+ : absolute
+ :
+ {
+ if $posix
+ {
+ $* <'print $posix_representation([paths] /a/b /a/c/)' >'/a/b /a/c/' : paths
+ $* <'print $posix_representation([dir_paths] /a/b /a/c/)' >'/a/b/ /a/c/' : dir-paths
+ $* <'print $posix_representation([dir_path] /)' >'/' : root-dir
+ $* <'print $path.posix_representation(/a/b /a/c/)' >'/a/b /a/c/' : untyped
+ }
+ else
+ {
+ $* <'print $posix_representation([paths] "c:\\a\\b" "C:\\a\\c\\")' >'c:/a/b C:/a/c/' : paths
+ $* <'print $posix_representation([dir_paths] "c:\\a\\b" "C:\\a\\c\\")' >'c:/a/b/ C:/a/c/' : dir-paths
+ $* <'print $posix_representation([dir_paths] "c:\\" "C:")' >'c:/ C:/' : root-dir
+ $* <'print $path.posix_representation("c:\\a\\b" "C:\\a\\c\\")' >'c:/a/b C:/a/c/' : untyped
+ $* <'print $path.posix_representation("c:\\" "C:")' >'c:/ C:/' : untyped-root
+ }
+ }
+}
+
: canonicalize
:
{
@@ -48,6 +121,28 @@ if! $posix
$* <'print $path.directory(a/b c/d/)' >"a/ c/" : dir-names
}
+: root_directory
+:
+{
+ : posix
+ :
+ if $posix
+ {
+ $* <'print $root_directory([path] /a/b)' >'/' : basics
+ $* <'print $root_directory([path] /)' >'/' : root
+ }
+
+ : windows
+ :
+ if $windows
+ {
+ $* <'print $root_directory([path] "c:\\a\\b")' >'c:\' : basics
+ $* <'print $root_directory([path] "c:")' >'c:\' : root
+ }
+
+ $* <'print $root_directory([path] a/b)' >'' : relative
+}
+
: base
:
{
@@ -78,6 +173,12 @@ if! $posix
EOE
}
+: relative
+:
+{
+ $* <'print $relative([path] a/b/c, [dir_path] a/x/y)' >"..$s..$(s)b/c" : basics
+}
+
: extension
:
{
@@ -104,6 +205,45 @@ if! $posix
EOO
}
+: sort
+:
+{
+ $* <'print $sort([paths] a c b a)' >'a a b c' : basics
+ $* <'print $sort([paths] a c b a, dedup)' >'a b c' : dedup
+
+ : icase
+ :
+ if $windows
+ {
+ $* <'print $sort([paths] a C B a)' >'a a B C'
+ }
+}
+
+: size
+:
+{
+ $* <'print $size([path] abc)' >'3' : basics
+ $* <'print $size([path] )' >'0' : zero
+
+ $* <'print $size([dir_path] abc)' >'3' : dir-basics
+ $* <'print $size([dir_path] abc/)' >'3' : dir-separator
+ $* <'print $size([dir_path] )' >'0' : dir-zero
+}
+
+: find
+:
+{
+ $* <'print $find([paths] x y z, y)' >'true' : basics-true
+ $* <'print $find([paths] x y z, a)' >'false' : basics-false
+}
+
+: find_index
+:
+{
+ $* <'print $find_index([dir_paths] x y z, y)' >'1' : basics-true
+ $* <'print $find_index([dir_paths] x y z, a)' >'3' : basics-false
+}
+
: invalid-path
:
p = ($posix ? /../foo : 'c:/../foo');
diff --git a/tests/function/regex/testscript b/tests/function/regex/testscript
index 5167390..538bdab 100644
--- a/tests/function/regex/testscript
+++ b/tests/function/regex/testscript
@@ -478,6 +478,64 @@
}
}
+: filter-match
+:
+{
+ : match
+ :
+ {
+ : string
+ :
+ $* <<EOI >'-O2 -O3'
+ print $regex.filter_match(-g -O2 -O3, [string] '-O[23]')
+ EOI
+
+ : untyped
+ :
+ $* <<EOI >'-O2 -O3'
+ print $regex.filter_match(-g -O2 -O3, '-O[23]')
+ EOI
+
+ : strings
+ :
+ $* <<EOI >'-O2 -O3'
+ print $regex.filter_match([strings] -g -O2 -O3, '-O[23]')
+ EOI
+
+ : nomatch
+ :
+ $* <<EOI >''
+ print $regex.filter_match(-g -O1, '-O[23]')
+ EOI
+ }
+
+ : filter-out
+ :
+ {
+ : untyped
+ :
+ $* <<EOI >'-g'
+ print $regex.filter_out_match(-g -O2 -O3, '-O[23]')
+ EOI
+
+ : all-match
+ :
+ $* <<EOI >''
+ print $regex.filter_out_match(-O2 -O3, '-O[23]')
+ EOI
+ }
+
+ : flags
+ :
+ {
+ : icase
+ :
+ $* <<EOI >'Foo.cxx'
+ print $regex.filter_match(Foo.cxx, 'f[^.]+.*', icase)
+ EOI
+ }
+}
+
: find-search
:
{
@@ -520,6 +578,64 @@
}
}
+: filter-search
+:
+{
+ : match
+ :
+ {
+ : string
+ :
+ $* <<EOI >'-O2 -O3'
+ print $regex.filter_search(-g -O2 -O3, [string] '-O')
+ EOI
+
+ : untyped
+ :
+ $* <<EOI >'-O2 -O3'
+ print $regex.filter_search(-g -O2 -O3, '-O')
+ EOI
+
+ : strings
+ :
+ $* <<EOI >'-O2 -O3'
+ print $regex.filter_search([strings] -g -O2 -O3, '-O')
+ EOI
+
+ : nomatch
+ :
+ $* <<EOI >''
+ print $regex.filter_search(-g, '-O')
+ EOI
+ }
+
+ : filter-out
+ :
+ {
+ : untyped
+ :
+ $* <<EOI >'-g'
+ print $regex.filter_out_search(-g -O2 -O3, '-O')
+ EOI
+
+ : all-match
+ :
+ $* <<EOI >''
+ print $regex.filter_out_search(-O2 -O3, '-O')
+ EOI
+ }
+
+ : flags
+ :
+ {
+ : icase
+ :
+ $* <<EOI >'Foo.cxx'
+ print $regex.filter_search(Foo.cxx, 'f', icase)
+ EOI
+ }
+}
+
: merge
:
{
diff --git a/tests/function/string/testscript b/tests/function/string/testscript
index 9275fe5..244ace8 100644
--- a/tests/function/string/testscript
+++ b/tests/function/string/testscript
@@ -25,9 +25,92 @@
}
}
+: 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'