diff options
Diffstat (limited to 'tests/function')
-rw-r--r-- | tests/function/builtin/testscript | 32 | ||||
-rw-r--r-- | tests/function/filesystem/testscript | 48 | ||||
-rw-r--r-- | tests/function/install/testscript | 1 | ||||
-rw-r--r-- | tests/function/integer/buildfile | 4 | ||||
-rw-r--r-- | tests/function/integer/testscript | 41 | ||||
-rw-r--r-- | tests/function/json/buildfile | 4 | ||||
-rw-r--r-- | tests/function/json/testscript | 257 | ||||
-rw-r--r-- | tests/function/name/buildfile | 4 | ||||
-rw-r--r-- | tests/function/name/testscript | 68 | ||||
-rw-r--r-- | tests/function/path/testscript | 224 | ||||
-rw-r--r-- | tests/function/regex/testscript | 116 | ||||
-rw-r--r-- | tests/function/string/testscript | 147 |
12 files changed, 925 insertions, 21 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/filesystem/testscript b/tests/function/filesystem/testscript index cf93b8b..c7c08f1 100644 --- a/tests/function/filesystem/testscript +++ b/tests/function/filesystem/testscript @@ -73,3 +73,51 @@ EOE } } + +: file_exists +: +{ + : file + : + touch f; + $* <'print $file_exists(f)' >'true' + + : symlink + : + touch f && ln -s f s; + $* <'print $file_exists([path] s)' >'true' + + : directory + : + mkdir d; + $* <'print $file_exists([dir_path] d)' >'false' + + : testscript + : + touch f; + echo $file_exists(f) >'true' +} + +: directory_exists +: +{ + : directory + : + mkdir d; + $* <'print $directory_exists(d)' >'true' + + : symlink + : + mkdir d && ln -s d s; + $* <'print $directory_exists([dir_path] d)' >'true' + + : file + : + touch f; + $* <'print $directory_exists([path] f)' >'false' + + : testscript + : + mkdir d; + echo $directory_exists(d) >'true' +} diff --git a/tests/function/install/testscript b/tests/function/install/testscript index 12cd506..2c70871 100644 --- a/tests/function/install/testscript +++ b/tests/function/install/testscript @@ -28,6 +28,7 @@ EOI $* <'print $install.resolve([dir_path] foo/a)' 2>>EOE != 0 error: unknown installation directory name 'foo' info: did you forget to specify config.install.foo? + info: specify !config.install.foo=... if installing from multiple projects <stdin>:1:8: info: while calling install.resolve(dir_path) EOE } 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..6321b3d 100644 --- a/tests/function/path/testscript +++ b/tests/function/path/testscript @@ -3,40 +3,112 @@ .include ../../common.testscript -posix = ($cxx.target.class != 'windows') +windows = ($cxx.target.class == 'windows') +posix = (!$windows) s = ($posix ? '/' : '\') -: canonicalize +: posix-string : { - $* <'print $canonicalize([path] a/b)' >"a$(s)b" : path - $* <'print $canonicalize([paths] a/b a/c)' >"a$(s)b a$(s)c" : paths - $* <'print $canonicalize([dir_path] a/b)' >"a$(s)b$s" : dir-path - $* <'print $canonicalize([dir_paths] a/b a/c/)' >"a$(s)b$s a$(s)c$s" : dir-paths - $* <'print $path.canonicalize(a/b)' >"a$(s)b" : untyped - $* <'print $path.canonicalize(a/b/ a/c)' >"a$(s)b$s a$(s)c" : mixed + : 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 + } + } } -: normalize +: posix-representation : { - $* <'print $normalize([path] a/../b)' >"b" : path - $* <'print $normalize([paths] a/../b a/../c)' >"b c" : paths - $* <'print $normalize([dir_path] a/../b)' >"b$s" : dir-path - $* <'print $normalize([dir_paths] a/../b a/../c/)' >"b$s c$s" : dir-paths - $* <'print $path.normalize(a/../b)' >"b" : untyped - $* <'print $path.normalize(a/../b/ a/../c)' >"b$s c" : mixed + : 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 + } + } } -: actualize +: absolute : -if! $posix { - mkdir Foo; - $* <'print $path.actualize($out_base/foo)' >~'/.+\\Foo/' + $* <'print $absolute($src_root)' >"true" : true + $* <'print $path.absolute(a/b)' >"false" : false +} + +: simple +: +{ + $* <'print $simple([path] a)' >"true" : true + $* <'print $path.simple(a/b)' >"false" : false +} + +: sub_path +: +{ + $* <'print $sub_path($src_base, $src_root)' >"true" : true-absolute + $* <'print $path.sub_path(a/b/c, a/b)' >"true" : true-relative + $* <'print $path.sub_path(a/b/c, a/d)' >"false" : false } +: super_path +: +{ + $* <'print $super_path($src_base, true-absolute)' >"true" : true-absolute + $* <'print $path.super_path(a/b/c, b/c)' >"true" : true-relative + $* <'print $path.super_path(a/b/c, c/a)' >"false" : false +} : directory : @@ -48,6 +120,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 +172,12 @@ if! $posix EOE } +: relative +: +{ + $* <'print $relative([path] a/b/c, [dir_path] a/x/y)' >"..$s..$(s)b/c" : basics +} + : extension : { @@ -104,6 +204,92 @@ if! $posix EOO } +: complete +: +{ + $* <'print $complete([path] a)' >"$~$(s)a" : path + $* <'print $complete([dir_path] a)' >"$~$(s)a$(s)" : dir-path + $* <'print $path.complete(a)' >"$~$(s)a" : untyped + + echo $path.complete(a) > "$~$(s)a" : testscript +} + +: canonicalize +: +{ + $* <'print $canonicalize([path] a/b)' >"a$(s)b" : path + $* <'print $canonicalize([paths] a/b a/c)' >"a$(s)b a$(s)c" : paths + $* <'print $canonicalize([dir_path] a/b)' >"a$(s)b$s" : dir-path + $* <'print $canonicalize([dir_paths] a/b a/c/)' >"a$(s)b$s a$(s)c$s" : dir-paths + $* <'print $path.canonicalize(a/b)' >"a$(s)b" : untyped + $* <'print $path.canonicalize(a/b/ a/c)' >"a$(s)b$s a$(s)c" : mixed +} + +: normalize +: +{ + $* <'print $normalize([path] a/../b)' >"b" : path + $* <'print $normalize([paths] a/../b a/../c)' >"b c" : paths + $* <'print $normalize([dir_path] a/../b)' >"b$s" : dir-path + $* <'print $normalize([dir_paths] a/../b a/../c/)' >"b$s c$s" : dir-paths + $* <'print $path.normalize(a/../b)' >"b" : untyped + $* <'print $path.normalize(a/../b/ a/../c)' >"b$s c" : mixed +} + +: try_normalize +: +{ + $* <'print $try_normalize([path] a/../b)' >"b" : valid + $* <'print $path.try_normalize($root_directory($src_root)/..)' >"[null]" : invalid +} + +: actualize +: +if! $posix +{ + mkdir Foo; + $* <'print $path.actualize($out_base/foo)' >~'/.+\\Foo/' +} + +: 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..57f30e2 100644 --- a/tests/function/string/testscript +++ b/tests/function/string/testscript @@ -25,9 +25,156 @@ } } +: contains +: +{ + : basics + : + { + $* <'print $string.contains( abcd, bc)' >'true' : true + $* <'print $string.contains( abcd, ac)' >'false' : false + $* <'print $contains([string] abcd, cd)' >'true' : typed + } + + : icase + : + { + $* <'print $string.contains(aBcD, bC, icase)' >'true' : true + } + + : once + : + { + $* <'print $string.contains(abcdabcd, da, once)' >'true' : true + $* <'print $string.contains(abcdabcd, bc, once)' >'false' : false + $* <'print $string.contains(abcdefgh, ab, once)' >'true' : true-begin + } +} + +: starts_with +: +{ + : basics + : + { + $* <'print $string.starts_with( abcd, ab)' >'true' : true + $* <'print $string.starts_with( abcd, bc)' >'false' : false + $* <'print $starts_with([string] abcd, abcd)' >'true' : typed + } + + : icase + : + { + $* <'print $string.starts_with(aBcD, Ab, icase)' >'true' : true + } +} + +: ends_with +: +{ + : basics + : + { + $* <'print $string.ends_with( abcd, cd)' >'true' : true + $* <'print $string.ends_with( abcd, bc)' >'false' : false + $* <'print $string.ends_with( abcd, xxxx)' >'false' : false-equal-size + $* <'print $ends_with([string] abcd, abcd)' >'true' : typed + } + + : icase + : + { + $* <'print $string.ends_with(aBcD, Cd, icase)' >'true' : true + } +} + +: 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 + $* <'print $replace([string] bb, b, Bb)' >'BbBb' : no-recursion + } + + : 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' |