aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-09-29 13:12:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-09-29 14:14:51 +0200
commit785087aa43cf962855724b8fa5da393022204a14 (patch)
tree4a24ca94679d72cf160d2ef528bba2c8dac45cb4 /tests
parentd7cb460833e6dde3e3b958b993eee3eee4ae3bf0 (diff)
Add $find(<sequence>, <value>), $find_index(<sequence>, <value>) functions
The $find() function returns true if the sequence contains the specified value. The $find_index() function returns the index of the first element in the sequence that is equal to the specified value or $size(<sequence>) if none is found. For string sequences, it's possible to request case- insensitive comparison with a flag.
Diffstat (limited to 'tests')
-rw-r--r--tests/function/builtin/testscript14
-rw-r--r--tests/function/name/testscript18
-rw-r--r--tests/function/path/testscript14
-rw-r--r--tests/function/string/testscript16
4 files changed, 60 insertions, 2 deletions
diff --git a/tests/function/builtin/testscript b/tests/function/builtin/testscript
index bbfd4e5..3c430d7 100644
--- a/tests/function/builtin/testscript
+++ b/tests/function/builtin/testscript
@@ -100,6 +100,20 @@
$* <'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
+}
+
: getenv
:
{
diff --git a/tests/function/name/testscript b/tests/function/name/testscript
index 6222167..4588e1d 100644
--- a/tests/function/name/testscript
+++ b/tests/function/name/testscript
@@ -49,6 +49,20 @@
: 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
+ $* <'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 6219f3c..c58bbf8 100644
--- a/tests/function/path/testscript
+++ b/tests/function/path/testscript
@@ -158,6 +158,20 @@ if! $posix
$* <'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/string/testscript b/tests/function/string/testscript
index 00835ce..364ce42 100644
--- a/tests/function/string/testscript
+++ b/tests/function/string/testscript
@@ -46,3 +46,19 @@
$* <'print $size([string] abc)' >'3' : basics
$* <'print $size([string] )' >'0' : zero
}
+
+: 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
+}