diff options
Diffstat (limited to 'tests/function/string')
-rw-r--r-- | tests/function/string/testscript | 134 |
1 files changed, 132 insertions, 2 deletions
diff --git a/tests/function/string/testscript b/tests/function/string/testscript index 00835ce..8eb5760 100644 --- a/tests/function/string/testscript +++ b/tests/function/string/testscript @@ -25,6 +25,113 @@ } } +: 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 + } +} + +: 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 $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 : { @@ -43,6 +150,29 @@ : size : { - $* <'print $size([string] abc)' >'3' : basics - $* <'print $size([string] )' >'0' : zero + $* <'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' |