aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/function/filesystem/testscript48
-rw-r--r--tests/function/path/testscript82
-rw-r--r--tests/function/regex/testscript81
-rw-r--r--tests/function/string/testscript74
-rw-r--r--tests/test/script/runner/for.testscript13
5 files changed, 275 insertions, 23 deletions
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/path/testscript b/tests/function/path/testscript
index 1ed89ca..6321b3d 100644
--- a/tests/function/path/testscript
+++ b/tests/function/path/testscript
@@ -80,36 +80,35 @@ s = ($posix ? '/' : '\')
}
}
-: canonicalize
+: absolute
:
{
- $* <'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
+ $* <'print $absolute($src_root)' >"true" : true
+ $* <'print $path.absolute(a/b)' >"false" : false
}
-: normalize
+: simple
:
{
- $* <'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
+ $* <'print $simple([path] a)' >"true" : true
+ $* <'print $path.simple(a/b)' >"false" : false
}
-: actualize
+: sub_path
:
-if! $posix
{
- mkdir Foo;
- $* <'print $path.actualize($out_base/foo)' >~'/.+\\Foo/'
+ $* <'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
:
@@ -205,6 +204,53 @@ 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
:
{
diff --git a/tests/function/regex/testscript b/tests/function/regex/testscript
index 538bdab..7fbcc8e 100644
--- a/tests/function/regex/testscript
+++ b/tests/function/regex/testscript
@@ -366,6 +366,33 @@
EOI
}
}
+
+ : empty-substring
+ :
+ : Note that regex_search() ignores the match_not_null flag for older
+ : versions of libstdc++ and libc++.
+ :
+ if (($cxx.id != 'gcc' || $cxx.version.major >= 7) && \
+ ($cxx.id != 'clang' || $cxx.version.major >= 6))
+ {
+ : empty
+ :
+ $* <<EOI >'true'
+ print $regex.search('', '.*')
+ EOI
+
+ : match
+ :
+ $* <<EOI >'true'
+ print $regex.search('a', 'a*')
+ EOI
+
+ : no-match
+ :
+ $* <<EOI >'false'
+ print $regex.search('aa', 'b*')
+ EOI
+ }
}
: split
@@ -576,6 +603,33 @@
print $regex.find_search(Foo.cxx, 'f', icase)
EOI
}
+
+ : empty-substring
+ :
+ : Note that regex_search() ignores the match_not_null flag for older
+ : versions of libstdc++ and libc++.
+ :
+ if (($cxx.id != 'gcc' || $cxx.version.major >= 7) && \
+ ($cxx.id != 'clang' || $cxx.version.major >= 6))
+ {
+ : empty
+ :
+ $* <<EOI >'true'
+ print $regex.find_search('', '.*')
+ EOI
+
+ : match
+ :
+ $* <<EOI >'true'
+ print $regex.find_search('a', 'a*')
+ EOI
+
+ : no-match
+ :
+ $* <<EOI >'false'
+ print $regex.find_search('aa', 'b*')
+ EOI
+ }
}
: filter-search
@@ -607,6 +661,33 @@
$* <<EOI >''
print $regex.filter_search(-g, '-O')
EOI
+
+ : empty-substring
+ :
+ : Note that regex_search() ignores the match_not_null flag for older
+ : versions of libstdc++ and libc++.
+ :
+ if (($cxx.id != 'gcc' || $cxx.version.major >= 7) && \
+ ($cxx.id != 'clang' || $cxx.version.major >= 6))
+ {
+ : empty
+ :
+ $* <<EOI >'{}'
+ print $regex.filter_search('', '.*')
+ EOI
+
+ : match
+ :
+ $* <<EOI >'a'
+ print $regex.filter_search('a', 'a*')
+ EOI
+
+ : no-match
+ :
+ $* <<EOI >''
+ print $regex.filter_search('aa', 'b*')
+ EOI
+ }
}
: filter-out
diff --git a/tests/function/string/testscript b/tests/function/string/testscript
index 244ace8..57f30e2 100644
--- a/tests/function/string/testscript
+++ b/tests/function/string/testscript
@@ -25,17 +25,81 @@
}
}
+: 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 $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
diff --git a/tests/test/script/runner/for.testscript b/tests/test/script/runner/for.testscript
index f43fcc2..0ca67c3 100644
--- a/tests/test/script/runner/for.testscript
+++ b/tests/test/script/runner/for.testscript
@@ -30,6 +30,19 @@
%.+ -b%
EOO
+ : custom-iteration
+ :
+ $c <<EOI && $b >>EOO
+ j = $json.parse('[1, 2, 3]')
+ for e: $j
+ echo $e >|
+ end
+ EOI
+ 1
+ 2
+ 3
+ EOO
+
: special-var
:
$c <<EOI && $b 2>>EOE != 0