-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
seq.bats
116 lines (93 loc) · 2.21 KB
/
seq.bats
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bats
setup_fixture
@test "l.seq fn 1 5" {
local expect=( 1 2 3 4 5 )
fn() { echo "$1"; }
run l.seq fn 1 5
assert_success
assert_equal "${#lines[@]}" "${#expect[@]}"
local i
for (( i = 0; i < ${#expect[@]}; i++ )); do
assert_line -n "$i" "${expect[$i]}"
done
}
@test "l.seq fn 0 7 3" {
local expect=( 0 3 6 )
fn() { echo "$1"; }
run l.seq fn 0 7 3
assert_success
assert_equal "${#lines[@]}" "${#expect[@]}"
local i
for (( i = 0; i < ${#expect[@]}; i++ )); do
assert_line -n "$i" "${expect[$i]}"
done
}
@test "l.seq fn 5 1" {
local expect=( 5 4 3 2 1 )
fn() { echo "$1"; }
run l.seq fn 5 1
assert_success
assert_equal "${#lines[@]}" "${#expect[@]}"
local i
for (( i = 0; i < ${#expect[@]}; i++ )); do
assert_line -n "$i" "${expect[$i]}"
done
}
@test "l.seq fn 5 1 3" {
local expect=( 5 2 )
fn() { echo "$1"; }
run l.seq fn 5 1 3
assert_success
assert_equal "${#lines[@]}" "${#expect[@]}"
local i
for (( i = 0; i < ${#expect[@]}; i++ )); do
assert_line -n "$i" "${expect[$i]}"
done
}
@test "l.seq fn 1 1" {
local expect=( 1 )
fn() { echo "$1"; }
run l.seq fn 1 1
assert_success
assert_equal "${#lines[@]}" "${#expect[@]}"
local i
for (( i = 0; i < ${#expect[@]}; i++ )); do
assert_line -n "$i" "${expect[$i]}"
done
}
@test "l.seq fn 01 10 2" {
local expect=( 01 03 05 07 09 )
fn() { echo "$1"; }
run l.seq fn 01 10 2
assert_success
assert_equal "${#lines[@]}" "${#expect[@]}"
local i
for (( i = 0; i < ${#expect[@]}; i++ )); do
assert_line -n "$i" "${expect[$i]}"
done
}
@test "l.seq fn 10 1 4" {
local expect=( 10 6 2 )
fn() { echo "$1"; }
run l.seq fn 10 1 4
assert_success
assert_equal "${#lines[@]}" "${#expect[@]}"
local i
for (( i = 0; i < ${#expect[@]}; i++ )); do
assert_line -n "$i" "${expect[$i]}"
done
}
@test "l.seq fn 10 01 4" {
if [[ ${BASH_VERSINFO[0]} == 4 ]] && [[ ${BASH_VERSINFO[1]} == 0 ]]; then
skip 'BASH 4.0 has bug'
fi
local expect=( 10 06 02 )
fn() { echo "$1"; }
run l.seq fn 10 01 4
assert_success
assert_equal "${#lines[@]}" "${#expect[@]}"
local i
for (( i = 0; i < ${#expect[@]}; i++ )); do
assert_line -n "$i" "${expect[$i]}"
done
}