-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy patheach.bats
More file actions
49 lines (39 loc) · 1.04 KB
/
Copy patheach.bats
File metadata and controls
49 lines (39 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bats
setup_fixture
@test "l.each (a b 1 2) fn" {
# shellcheck disable=2034
local arr=(a b 1 2)
local expect=( '0=a' '1=b' '2=1' '3=2' )
fn() { echo "$2=$1"; }
run l.each arr fn
assert_success
assert_equal "${#lines[@]}" "${#expect[@]}"
local i
for (( i = 0; i < ${#expect[@]}; i++ )); do
assert_line -n "$i" "${expect[$i]}"
done
}
@test "l.each ([hello]=world [foo]=bar) fn" {
# shellcheck disable=2034
local -A a=([hello]=world [foo]=bar)
local expect=( 'foo=bar' 'hello=world' )
fn() { echo "$2=$1"; }
run l.each a fn
assert_success
assert_equal "${#lines[@]}" "${#expect[@]}"
local out=()
readarray -t out < <(printf '%s\n' "${lines[@]}" | sort)
assert_array out expect
}
@test "l.read_array < <(l.each (a b 1 2) fn)" {
load_module read_array
# shellcheck disable=2034
local arr=(a b 1 2)
# shellcheck disable=2034
local out=()
local expect=( '0=a' '1=b' '2=1' '3=2' )
fn() { echo "$2=$1"; }
l.read_array out < <(l.each arr fn)
assert_equal "$?" 0
assert_array out expect
}