-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
is_array.bats
154 lines (128 loc) · 2.58 KB
/
is_array.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bats
setup_fixture
@test "l.is_array array" {
local -a y=(a h)
run l.is_array y
assert_success
assert_output ''
local y2=(a h)
run l.is_array y2
assert_success
assert_output ''
}
@test "l.is_array export array" {
local -a yyy1=(a h)
export yyy1
run l.is_array yyy1
assert_success
assert_output ''
local yyy2=(a h)
export yyy2
run l.is_array yyy2
assert_success
assert_output ''
local -A yyy3=([a]=1)
export yyy3
run l.is_array yyy3
assert_success
assert_output ''
# Skip testing uninitialized variable for bash 4.3
if [[ ! $BASH_VERSION =~ ^'4.3' ]]; then
local -a yyy11
export yyy11
run l.is_array yyy11
assert_success
assert_output ''
local yyy22
export yyy22
run l.is_array yyy22
assert_failure
assert_output ''
local -A yyy33
export yyy33
run l.is_array yyy33
assert_success
assert_output ''
fi
}
@test "l.is_array variable which has many attributes" {
declare -ilrtux yy11=1
run l.is_array yy11
assert_failure
assert_output ''
declare -ailrtux yy22=()
run l.is_array yy22
assert_success
assert_output ''
declare -Ailrtux yy33=()
run l.is_array yy33
assert_success
assert_output ''
# Skip testing uninitialized variable for bash 4.3
if [[ ! $BASH_VERSION =~ ^'4.3' ]]; then
declare -ilrtux yy1
run l.is_array yy1
assert_failure
assert_output ''
declare -ailrtux yy2
run l.is_array yy2
assert_success
assert_output ''
declare -Ailrtux yy3
run l.is_array yy3
assert_success
assert_output ''
fi
}
@test "l.is_array associative array" {
local -A A=([a]=1)
run l.is_array A
assert_success
assert_output ''
}
@test "l.is_array uninitialized array" {
if [[ $BASH_VERSION =~ ^'4.3' ]]; then skip; fi
local -a a
run l.is_array a
assert_success
assert_output ''
local -A A
run l.is_array A
assert_success
assert_output ''
local b
run l.is_array b
assert_failure
assert_output ''
}
@test "l.is_array number" {
local -i y=1
run l.is_array y
assert_failure
assert_output ''
local y2=2
run l.is_array y2
assert_failure
assert_output ''
}
@test "l.is_array string" {
local y=string
run l.is_array y
assert_failure
assert_output ''
}
@test "l.is_array ''" {
run l.is_array ''
assert_failure
assert_output ''
}
@test "l.is_array" {
run l.is_array
assert_failure
assert_output ''
}
@test "l.is_array undefined variable" {
run l.is_array kkkkkkkkkkkkkkkkkk # A long name in case of exported variable from outside
assert_failure
assert_output ''
}