Project

Profile

Help

Bug #6485 ยป test.xq

Michael Kay, 2024-07-19 13:40

 
xquery version "4.0";

(: This file is generated automatically by the
qtspecs build process. Any changes you
make to this file will be lost on the next build. Have a nice day. :)

declare namespace array="http://dummy/array";

declare function array:size (
$array as array(*)
) {


count(array:members($array))
};

declare function array:empty (
$array as array(*)
) {


array:size($array) eq 0
};

declare function array:get (
$array as array(*),
$position as xs:integer,
$fallback as fn(xs:integer) as item()*
) {


if ($position = (1 to array:size($array)))
then array:members($array)[$position]?value
else $fallback($position)
};

declare function array:put (
$array as array(*),
$position as xs:integer,
$member as item()*
) {


$array
=> array:remove($position)
=> array:insert-before($position, $member)
};

declare function array:replace (
$array as array(*),
$position as xs:integer,
$action as fn(item()*) as item()*
) {


$array
=> array:remove($position)
=> array:insert-before($position, $action($array($position)))
};

declare function array:append (
$array as array(*),
$member as item()*
) {


array:of-members((array:members($array), { 'value': $member }))
};

declare function array:join (
$arrays as array(*)*
) {


array:of-members($arrays ! array:members(.))
};

declare function array:subarray (
$array as array(*),
$start as xs:integer,
$length as xs:integer?
) {


$array
=> array:members()
=> fn:subsequence($start, $length)
=> array:of-members()
};

declare function array:index-of (
$array as array(*),
$target as item()*,
$collation as xs:string?
) {


array:index-where($array, fn:deep-equal(?, $target, $collation))
};

declare function array:index-where (
$array as array(*),
$predicate as fn(item()*, xs:integer) as xs:boolean?
) {


for member $m at $pos in $array
return $pos[$predicate($m, $pos)]
};

declare function array:slice (
$array as array(*),
$start as xs:integer?,
$end as xs:integer?,
$step as xs:integer?
) {


$array
=> array:members()
=> fn:slice($start, $end, $step)
=> array:of-members()
};

declare function array:remove (
$array as array(*),
$positions as xs:integer*
) {


$array => array:members() => fn:remove($positions) => array:of-members()
};

declare function array:insert-before (
$array as array(*),
$position as xs:integer,
$member as item()*
) {


$array
=> array:members()
=> fn:insert-before($position, { 'value': $member })
=> array:of-members()
};

declare function array:head (
$array as array(*)
) {


array:get($array, 1)
};

declare function array:foot (
$array as array(*)
) {


array:get($array, array:size($array))
};

declare function array:tail (
$array as array(*)
) {


array:remove($array, 1)
};

declare function array:trunk (
$array as array(*)
) {


array:remove($array, array:size($array))
};

declare function array:reverse (
$array as array(*)
) {


$array
=> array:members()
=> fn:reverse()
=> array:of-members()
};

declare function array:for-each (
$array as array(*),
$action as fn(item()*, xs:integer) as item()*
) {


array:of-members(
for member $member at $pos in $array
return map { 'value': $action($member, $pos) }
)
};

declare function array:filter (
$array as array(*),
$predicate as fn(item()*, xs:integer) as xs:boolean?
) {


array:of-members(
for member $member at $pos in $array
where $predicate($member, $pos)
return map{ 'value': $member }
)
};

declare function array:fold-left (
$array as array(*),
$zero as item()*,
$action as fn(item()*, item()*, xs:integer) as item()*
) {


fold-left(
array:members($array),
$zero,
fn($result, $member, $pos) { $action($member?value, $result, $pos) }
)
};

declare function array:fold-right (
$array as array(*),
$zero as item()*,
$action as fn(item()*, item()*, xs:integer) as item()*
) {


fold-right(
array:members($array),
$zero,
fn($member, $result, $pos) { $action($member?value, $result, $pos) }
)
};

declare function array:for-each-pair (
$array1 as array(*),
$array2 as array(*),
$action as fn(item()*, item()*, xs:integer) as item()*
) {


array:of-members(
for $pos in 1 to min(array:size($array1), array:size($array2))
return map { 'value': $action($array1($pos), $array2($pos), $pos) }
)
};

declare function array:build (
$input as item()*,
$action as fn(item(), xs:integer) as item()*
) {


array:of-members(
for $item at $pos in $input
return map { 'value': $action($item, $pos) }
)
};

declare function array:members (
$array as array(*)
) {


for member $member in $array
return map { 'value': $member }
};

declare function array:split (
$array as array(*)
) {


for member $member in $array
return [ $member ]
};

declare function array:sort (
$array as array(*),
$collations as xs:string*,
$keys as (fn(item()*) as xs:anyAtomicType*)*,
$orders as enum('ascending', 'descending')*
) {


$array
=> array:members()
=> sort(
$collations,
for $key in ($keys otherwise data#1)
return fn($member as record(value)) as xs:anyAtomicType* {
$key($member?value)
},
$orders
)
=> array:of-members()
};


declare function array:flatten(
$input as item()*
) as item()* {
for $item in $input
return if ($item instance of array(*))
then array:flatten(array:values($item))
else $item
};

declare function array:values (
$array as array(*)
) {


array:members($array)?value
};

element result {(: array:size :)
if (deep-equal(
array:size([ "a", "b", "c" ]),
(3)))
then 'OK'
else 'fail',

(: array:size :)
if (deep-equal(
array:size([ "a", [ "b", "c" ] ]),
(2)))
then 'OK'
else 'fail',

(: array:size :)
if (deep-equal(
array:size([]),
(0)))
then 'OK'
else 'fail',

(: array:size :)
if (deep-equal(
array:size([ [] ]),
(1)))
then 'OK'
else 'fail',

(: array:empty :)
if (deep-equal(
array:empty([ "a", "b", "c" ]),
(false())))
then 'OK'
else 'fail',

(: array:empty :)
if (deep-equal(
array:empty([]),
(true())))
then 'OK'
else 'fail',

(: array:empty :)
if (deep-equal(
array:empty([ [] ]),
(false())))
then 'OK'
else 'fail',

(: array:empty :)
if (deep-equal(
array:empty([ () ]),
(false())))
then 'OK'
else 'fail',

(: array:get :)
if (deep-equal(
[ "a", "b", "c" ] => array:get(2),
("b")))
then 'OK'
else 'fail',

(: array:get :)
if (deep-equal(
[ "a", [ "b", "c" ] ] => array:get(2),
([ "b", "c" ])))
then 'OK'
else 'fail',

(: array:get :)
if (deep-equal(
[ "a" ] => array:get(1, void#1),
("a")))
then 'OK'
else 'fail',

(: array:get :)
if (deep-equal(
[] => array:get(1, void#1),
(())))
then 'OK'
else 'fail',

(: array:put :)
if (deep-equal(
array:put([ "a", "b", "c" ], 2, "d"),
([ "a", "d", "c" ])))
then 'OK'
else 'fail',

(: array:put :)
if (deep-equal(
array:put([ "a", "b", "c" ], 2, ("d", "e")),
([ "a", ("d", "e"), "c" ])))
then 'OK'
else 'fail',

(: array:put :)
if (deep-equal(
array:put([ "a" ], 1, [ "d", "e" ]),
([ [ "d", "e" ] ])))
then 'OK'
else 'fail',

(: array:replace :)
if (deep-equal(
array:replace(
[ 10, 11, 12 ],
2,
fn { . + 10 }
),
([ 10, 21, 12 ])))
then 'OK'
else 'fail',

(: array:replace :)
if (deep-equal(
array:replace(
[ "a", "b", "c" ],
2,
concat(?, "x")
),
([ "a", "bx", "c" ])))
then 'OK'
else 'fail',

(: array:replace :)
if (deep-equal(
array:replace(
[ ("a", "b"), ("c", "d") ],
2,
reverse#1
),
([ ("a", "b"), ("d", "c") ])))
then 'OK'
else 'fail',

(: array:append :)
if (deep-equal(
array:append([ "a", "b", "c" ], "d"),
([ "a", "b", "c", "d" ])))
then 'OK'
else 'fail',

(: array:append :)
if (deep-equal(
array:append([ "a", "b", "c" ], ("d", "e")),
([ "a", "b", "c", ("d", "e") ])))
then 'OK'
else 'fail',

(: array:append :)
if (deep-equal(
array:append([ "a", "b", "c" ], [ "d", "e" ]),
([ "a", "b", "c", [ "d", "e" ] ])))
then 'OK'
else 'fail',

(: array:join :)
if (deep-equal(
array:join(()),
([])))
then 'OK'
else 'fail',

(: array:join :)
if (deep-equal(
array:join([ 1, 2, 3 ]),
([ 1, 2, 3 ])))
then 'OK'
else 'fail',

(: array:join :)
if (deep-equal(
array:join(([ "a", "b" ], [ "c", "d" ])),
([ "a", "b", "c", "d" ])))
then 'OK'
else 'fail',

(: array:join :)
if (deep-equal(
array:join(([ "a", "b" ], [ "c", "d" ], [])),
([ "a", "b", "c", "d" ])))
then 'OK'
else 'fail',

(: array:join :)
if (deep-equal(
array:join(([ "a", "b" ], [ [ "c", "d" ] ])),
([ "a", "b", [ "c", "d" ] ])))
then 'OK'
else 'fail',

(: array:subarray :)
if (deep-equal(
array:subarray([ "a", "b", "c", "d" ], 2),
([ "b", "c", "d" ])))
then 'OK'
else 'fail',

(: array:subarray :)
if (deep-equal(
array:subarray([ "a", "b", "c", "d" ], 5),
([])))
then 'OK'
else 'fail',

(: array:subarray :)
if (deep-equal(
array:subarray([ "a", "b", "c", "d" ], 2, 0),
([])))
then 'OK'
else 'fail',

(: array:subarray :)
if (deep-equal(
array:subarray([ "a", "b", "c", "d" ], 2, 1),
([ "b" ])))
then 'OK'
else 'fail',

(: array:subarray :)
if (deep-equal(
array:subarray([ "a", "b", "c", "d" ], 2, 2),
([ "b", "c" ])))
then 'OK'
else 'fail',

(: array:subarray :)
if (deep-equal(
array:subarray([ "a", "b", "c", "d" ], 5, 0),
([])))
then 'OK'
else 'fail',

(: array:subarray :)
if (deep-equal(
array:subarray([], 1, 0),
([])))
then 'OK'
else 'fail',

(: array:index-of :)
if (deep-equal(
array:index-of([ 10, 20, 30, 30, 20, 10 ], 20),
((2, 5))))
then 'OK'
else 'fail',

(: array:index-of :)
if (deep-equal(
array:index-of([ (), 1, (5, 6), (6, 7) ], (6, 7)),
(4)))
then 'OK'
else 'fail',

(: array:index-of :)
if (deep-equal(
array:index-of(
[ "a", ("b", "C"), "d" ],
("B", "c"),
"http://www.w3.org/2005/xpath-functions/collation/html-ascii-case-insensitive"
)
,
(2)))
then 'OK'
else 'fail',

(: array:index-of :)
if (deep-equal(
array:index-of(
[ '1', xs:untypedAtomic('1'), 1, current-date() ],
'1'
),
((1, 2))))
then 'OK'
else 'fail',

(: array:index-where :)
if (deep-equal(
array:index-where([], boolean#1),
(())))
then 'OK'
else 'fail',

(: array:index-where :)
if (deep-equal(
array:index-where([ 0, (), 4, 9 ], boolean#1),
((3, 4))))
then 'OK'
else 'fail',

(: array:index-where :)
if (deep-equal(
array:index-where(
array { 1 to 10 },
function { . mod 2 = 0 }
),
((2, 4, 6, 8, 10))))
then 'OK'
else 'fail',

(: array:index-where :)
if (deep-equal(
array:index-where(
[ "January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December" ],
contains(?, "r")
),
((1, 2, 3, 4, 9, 10, 11, 12))))
then 'OK'
else 'fail',

(: array:index-where :)
if (deep-equal(
array:index-where(
[ (1, 2, 3), (4, 5, 6), (7, 8) ],
fn($m) { count($m) = 3 }
),
((1, 2))))
then 'OK'
else 'fail',

(: array:index-where :)
if (deep-equal(
array:index-where(
[ 1, 8, 2, 7, 3 ],
fn($member, $pos) { $member < 5 and $pos > 2 }
),
((3, 5))))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := 2, end := 4),
([ "b", "c", "d" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := 2),
([ "b", "c", "d", "e" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, end := 2),
([ "a", "b" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := 3, end := 3),
([ "c" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := 4, end := 3),
([ "d", "c" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := 2, end := 5, step := 2),
([ "b", "d" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := 5, end := 2, step := -2),
([ "e", "c" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := 2, end := 5, step := -2),
([])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := 5, end := 2, step := 2),
([])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in),
([ "a", "b", "c", "d", "e" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := -1),
([ "e" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := -3),
([ "c", "d", "e" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, end := -2),
([ "a", "b", "c", "d" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := 2, end := -2),
([ "b", "c", "d" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := -2, end := 2),
([ "d", "c", "b" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := -4, end := -2),
([ "b", "c", "d" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := -2, end := -4),
([ "d", "c", "b" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := -4, end := -2, step := 2),
([ "b", "d" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice($in, start := -2, end := -4, step := -2),
([ "d", "b" ])))
then 'OK'
else 'fail',

(: array:slice :)
if (deep-equal(
array:slice([ "a", "b", "c", "d" ], 0),
([ "a", "b", "c", "d" ])))
then 'OK'
else 'fail',

(: array:remove :)
if (deep-equal(
array:remove([ "a", "b", "c", "d" ], 1),
([ "b", "c", "d" ])))
then 'OK'
else 'fail',

(: array:remove :)
if (deep-equal(
array:remove([ "a", "b", "c", "d" ], 2),
([ "a", "c", "d" ])))
then 'OK'
else 'fail',

(: array:remove :)
if (deep-equal(
array:remove([ "a" ], 1),
([])))
then 'OK'
else 'fail',

(: array:remove :)
if (deep-equal(
array:remove([ "a", "b", "c", "d" ], 1 to 3),
([ "d" ])))
then 'OK'
else 'fail',

(: array:remove :)
if (deep-equal(
array:remove([ "a", "b", "c", "d" ], ()),
([ "a", "b", "c", "d" ])))
then 'OK'
else 'fail',

(: array:insert-before :)
if (deep-equal(
array:insert-before(
[ "a", "b", "c", "d" ],
3,
("x", "y")
),
([ "a", "b", ("x", "y"), "c", "d" ])))
then 'OK'
else 'fail',

(: array:insert-before :)
if (deep-equal(
array:insert-before(
[ "a", "b", "c", "d" ],
5,
("x", "y")
),
([ "a", "b", "c", "d", ("x", "y") ])))
then 'OK'
else 'fail',

(: array:insert-before :)
if (deep-equal(
array:insert-before(
[ "a", "b", "c", "d" ],
3,
[ "x", "y" ]
),
([ "a", "b", [ "x", "y" ], "c", "d" ])))
then 'OK'
else 'fail',

(: array:head :)
if (deep-equal(
array:head([ 5, 6, 7, 8 ]),
(5)))
then 'OK'
else 'fail',

(: array:head :)
if (deep-equal(
array:head([ [ "a", "b" ], [ "c", "d" ] ]),
([ "a", "b" ])))
then 'OK'
else 'fail',

(: array:head :)
if (deep-equal(
array:head([ ("a", "b"), ("c", "d") ]),
("a", "b")))
then 'OK'
else 'fail',

(: array:foot :)
if (deep-equal(
array:foot([ 5, 6, 7, 8 ]),
(8)))
then 'OK'
else 'fail',

(: array:foot :)
if (deep-equal(
array:foot([ [ "a", "b" ], [ "c", "d" ] ]),
([ "c", "d" ])))
then 'OK'
else 'fail',

(: array:foot :)
if (deep-equal(
array:foot([ ("a", "b"), ("c", "d") ]),
("c", "d")))
then 'OK'
else 'fail',

(: array:tail :)
if (deep-equal(
array:tail([ 5, 6, 7, 8 ]),
([ 6, 7, 8 ])))
then 'OK'
else 'fail',

(: array:tail :)
if (deep-equal(
array:tail([ 5 ]),
([])))
then 'OK'
else 'fail',

(: array:trunk :)
if (deep-equal(
array:trunk([ 5, 6, 7, 8 ]),
([ 5, 6, 7 ])))
then 'OK'
else 'fail',

(: array:trunk :)
if (deep-equal(
array:trunk([ 5 ]),
([])))
then 'OK'
else 'fail',

(: array:reverse :)
if (deep-equal(
array:reverse([ "a", "b", "c", "d" ]),
([ "d", "c", "b", "a" ])))
then 'OK'
else 'fail',

(: array:reverse :)
if (deep-equal(
array:reverse([ ("a", "b"), ("c", "d") ]),
([ ("c", "d"), ("a", "b") ])))
then 'OK'
else 'fail',

(: array:reverse :)
if (deep-equal(
array:reverse([ 1 to 5 ]),
([ (1, 2, 3, 4, 5) ])))
then 'OK'
else 'fail',

(: array:reverse :)
if (deep-equal(
array:reverse([]),
([])))
then 'OK'
else 'fail',

(: array:for-each :)
if (deep-equal(
array:for-each(
[ "A", "B", 1, 2 ],
fn($z) { $z instance of xs:integer }
),
([false(), false(), true(), true()])))
then 'OK'
else 'fail',

(: array:for-each :)
if (deep-equal(
array:for-each(
[ "the cat", "sat", "on the mat" ],
tokenize#1
),
([ ("the", "cat"), "sat", ("on", "the", "mat") ])))
then 'OK'
else 'fail',

(: array:for-each :)
if (deep-equal(
array:for-each(
[ [ "the", "cat" ], [ "sat" ], [ "on", "the", "mat" ] ],
array:flatten#1
),
([ ("the", "cat"), "sat", ("on", "the", "mat") ])))
then 'OK'
else 'fail',

(: array:for-each :)
if (deep-equal(
array:for-each(
[ 'one', 'two', 'three' ],
fn($member, $pos) { $pos || '. ' || $member }
),
([ "1. one", "2. two", "3. three" ])))
then 'OK'
else 'fail',

(: array:filter :)
if (deep-equal(
array:filter(
[ "A", "B", 1, 2 ],
fn($x) { $x instance of xs:integer }
),
([ 1, 2 ])))
then 'OK'
else 'fail',

(: array:filter :)
if (deep-equal(
array:filter(
[ "the cat", "sat", "on the mat" ],
function { count(tokenize(.)) > 1 }
),
([ "the cat", "on the mat" ])))
then 'OK'
else 'fail',

(: array:filter :)
if (deep-equal(
array:filter([ "A", "B", "", 0, 1 ], boolean#1),
([ "A", "B", 1] )))
then 'OK'
else 'fail',

(: array:filter :)
if (deep-equal(
let $array := [ 1, 1, 2, 3, 4, 4, 5 ]
return array:filter(
$array,
fn($item, $pos) { $pos > 1 and $item = $array($pos - 1) }
),
([ 1, 4 ])))
then 'OK'
else 'fail',

(: array:fold-left :)
if (deep-equal(
array:fold-left(
[ true(), true(), false() ],
true(),
fn($x, $y) { $x and $y }
),
(false())))
then 'OK'
else 'fail',

(: array:fold-left :)
if (deep-equal(
array:fold-left(
[ true(), true(), false() ],
false(),
fn($x, $y) { $x or $y }
),
(true())))
then 'OK'
else 'fail',

(: array:fold-left :)
if (deep-equal(
array:fold-left(
[ 1, 2, 3 ],
[],
fn($x, $y) { [ $x, $y ] }
),
([[[[], 1], 2], 3])))
then 'OK'
else 'fail',

(: array:fold-left :)
if (deep-equal(
let $input := array { 11 to 21, 21 to 31 }
let $target := 21
return array:fold-left($input, (),
fn($result, $curr, $pos) {
$result, if ($curr = $target) { $pos }
}
)
,
((11, 12))))
then 'OK'
else 'fail',

(: array:fold-right :)
if (deep-equal(
array:fold-right(
[ true(), true(), false() ],
true(),
fn($x, $y) { $x and $y }
),
(false())))
then 'OK'
else 'fail',

(: array:fold-right :)
if (deep-equal(
array:fold-right(
[ true(), true(), false() ],
false(),
fn($x, $y) { $x or $y }
),
(true())))
then 'OK'
else 'fail',

(: array:fold-right :)
if (deep-equal(
array:fold-right(
[ 1, 2, 3 ],
[],
fn($x, $y) { [ $x, $y ] }
),
([ 1, [ 2, [ 3, [] ] ] ])))
then 'OK'
else 'fail',

(: array:fold-right :)
if (deep-equal(
let $input := array { 11 to 21, 21 to 31 }
let $target := 21
return array:fold-right(
$input, (),
action := fn($curr, $result, $pos) {
$result, if ($curr = $target) { $pos }
}
),
((12, 11))))
then 'OK'
else 'fail',

(: array:for-each-pair :)
if (deep-equal(
array:for-each-pair(
[ "A", "B", "C" ],
[ 1, 2, 3 ],
fn($x, $y) { array { $x, $y }}
),
([ [ "A", 1 ], [ "B", 2 ], [ "C", 3 ] ])))
then 'OK'
else 'fail',

(: array:for-each-pair :)
if (deep-equal(
let $array := [ "A", "B", "C", "D" ]
return array:for-each-pair(
$array,
array:tail($array),
concat#2
),
([ "AB", "BC", "CD" ])))
then 'OK'
else 'fail',

(: array:for-each-pair :)
if (deep-equal(
array:for-each-pair(
[ 1, 8, 2 ],
[ 3, 4, 3 ],
fn($member1, $member2, $pos) {
$pos || ': ' || max(($member1, $member2))
}
)
,
([ "1: 3", "2: 8", "3: 3" ])))
then 'OK'
else 'fail',

(: array:build :)
if (deep-equal(
array:build(1 to 5),
([ 1, 2, 3, 4, 5 ])))
then 'OK'
else 'fail',

(: array:build :)
if (deep-equal(
array:build(1 to 5, fn { 2 * . }),
([ 2, 4, 6, 8, 10 ])))
then 'OK'
else 'fail',

(: array:build :)
if (deep-equal(
array:build(1 to 5, fn { 1 to . }),
([ 1, (1, 2), (1, 2, 3), (1, 2, 3, 4), (1, 2, 3, 4, 5) ])))
then 'OK'
else 'fail',

(: array:build :)
if (deep-equal(
array:build(("red", "green", "blue"), characters#1),
([ ("r", "e", "d"), ("g", "r", "e", "e", "n"), ("b", "l", "u", "e") ])))
then 'OK'
else 'fail',

(: array:build :)
if (deep-equal(
array:build(1 to 5, fn { array { 1 to . } }),
([ [ 1 ], [ 1, 2 ], [ 1, 2, 3 ], [ 1, 2, 3, 4 ], [ 1, 2, 3, 4, 5 ] ])))
then 'OK'
else 'fail',

(: array:build :)
if (deep-equal(
array:build(
(0x41 to 0x48) ! char(.),
fn($char, $pos) {
if($pos mod 2 = 0) then lower-case($char) else $char
}
)
,
([ "A", "b", "C", "d", "E", "f", "G", "h" ])))
then 'OK'
else 'fail',

(: array:members :)
if (deep-equal(
array:members([]),
(())))
then 'OK'
else 'fail',

(: array:members :)
if (deep-equal(
array:members([ 1 to 5 ])?value,
((1, 2, 3, 4, 5))))
then 'OK'
else 'fail',

(: array:members :)
if (deep-equal(
array:members([ (1, 1), (2, 4), (3, 9), (4, 16), (5, 25) ])
! sum(?value),
((2, 6, 12, 20, 30))))
then 'OK'
else 'fail',

(: array:members :)
if (deep-equal(
let $array := [ "any array" ]
return deep-equal(
$array,
array:of-members(array:members($array))
),
(true())))
then 'OK'
else 'fail',

(: array:split :)
if (deep-equal(
array:split([]),
(())))
then 'OK'
else 'fail',

(: array:split :)
if (deep-equal(
array:split([ () ]),
([ () ])))
then 'OK'
else 'fail',

(: array:split :)
if (deep-equal(
array:split([ 1 to 5 ]),
([ (1, 2, 3, 4, 5) ])))
then 'OK'
else 'fail',

(: array:split :)
if (deep-equal(
array:split(
array { 1 to 5 }
),
([ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ])))
then 'OK'
else 'fail',

(: array:split :)
if (deep-equal(
array:split(
[ (1, 1), (2, 4), (3, 9), (4, 16), (5, 25) ]
) ! sum(.),
(2, 6, 12, 20, 30)))
then 'OK'
else 'fail',

(: array:split :)
if (deep-equal(
let $array := [ "any array" ]
return deep-equal(
$array,
array:join(array:split($array))
),
(true())))
then 'OK'
else 'fail',

(: array:sort :)
if (deep-equal(
array:sort([ 1, 4, 6, 5, 3 ]),
([ 1, 3, 4, 5, 6 ])))
then 'OK'
else 'fail',

(: array:sort :)
if (deep-equal(
array:sort([ 1, 4, 4e0, 6, 5, 3 ], orders := "descending"),
([ 6, 5, 4, 4e0, 3, 1 ])))
then 'OK'
else 'fail',

(: array:sort :)
if (deep-equal(
array:sort([ 1, -2, 5, 10, -10, 10, 8 ], (), abs#1),
([ 1, -2, 5, 8, 10, -10, 10 ])))
then 'OK'
else 'fail',

(: array:sort :)
if (deep-equal(
array:sort([ [ 2, "i" ], [ 1, "e" ], [ 2, "g" ], [ 1, "f" ] ]),
([ [ 1, "e" ], [ 1, "f" ], [ 2, "g" ], [ 2, "i" ] ])))
then 'OK'
else 'fail',

(: array:sort :)
if (deep-equal(
array:sort(
[ [ 2, "i" ], [ 1, "e" ], [ 2, "g" ], [ 1, "f" ] ],
(),
(array:get(?, 1), array:get(?, 2)),
("ascending", "descending")
),
([ [ 1, "f" ], [ 1, "e" ], [ 2, "i" ], [ 2, "g" ]])))
then 'OK'
else 'fail',

(: array:flatten :)
if (deep-equal(
array:flatten([ 1, 4, 6, 5, 3 ]),
((1, 4, 6, 5, 3))))
then 'OK'
else 'fail',

(: array:flatten :)
if (deep-equal(
array:flatten(([ 1, 2 ], [ [ 10, 11 ], 12 ], [], 13)),
((1, 2, 10, 11, 12, 13))))
then 'OK'
else 'fail',

(: array:flatten :)
if (deep-equal(
array:flatten([ (1, 0), (1, 1), (0, 1), (0, 0) ]),
((1, 0, 1, 1, 0, 1, 0, 0))))
then 'OK'
else 'fail',

(: array:values :)
if (deep-equal(
array:values(["one", "two", "three"]),
(("one", "two", "three"))))
then 'OK'
else 'fail',

(: array:values :)
if (deep-equal(
array:values(["one", ("two", "three")]),
(("one", "two", "three"))))
then 'OK'
else 'fail',

(: array:values :)
if (deep-equal(
array:values(["one", ("two", "three"), ()]),
(("one", "two", "three"))))
then 'OK'
else 'fail',

(: array:values :)
if (deep-equal(
array:values(["one", ["two", "three"]]),
(("one", ["two", "three"]))))
then 'OK'
else 'fail',

(: array:values :)
if (deep-equal(
array:values([ (), 1, (2 to 4), [ 5 ] ]),
((1, 2, 3, 4, [ 5 ]))))
then 'OK'
else 'fail',

()}
    (1-1/1)