@@ -2110,41 +2110,192 @@ fi
21102110
21112111if __begin_test_block --name=' __slice' ; then
21122112 function slice_tests {
2113- local arr
2113+ local arr target
2114+
2115+ __print_lines ' start, no indices, no-op:'
2116+ arr=(a b c d)
2117+ __slice {arr}
2118+ echo-verbose --no-color -- " ${arr[@]} "
2119+
2120+ __print_lines ' start, empty indices, failure:'
2121+ __slice {arr} ' ' || __print_lines " status: $? "
2122+
2123+ __print_lines ' start, out of bounds:'
2124+ arr=(a b c d)
2125+ __slice {arr} 10
2126+ echo-verbose --no-color -- " ${arr[@]} "
2127+
2128+ __print_lines ' start, negative, out of bounds:'
2129+ arr=(a b c d)
2130+ __slice {arr} -10
2131+ echo-verbose -- " ${arr[@]} "
2132+
2133+ __print_lines ' start:'
21142134 arr=(a b c d)
21152135 __slice {arr} 1
21162136 echo-verbose -- " ${arr[@]} "
21172137
2118- __print_line
2138+ __print_lines ' start, negative:'
2139+ arr=(a b c d)
2140+ __slice {arr} -2
2141+ echo-verbose -- " ${arr[@]} "
2142+
2143+ __print_lines ' start, finish:'
21192144 arr=(a b c d)
21202145 __slice {arr} 1 2
21212146 echo-verbose -- " ${arr[@]} "
21222147
2123- __print_line
2148+ __print_lines ' start, finish, negatives:'
2149+ arr=(a b c d)
2150+ __slice {arr} -3 -1
2151+ echo-verbose -- " ${arr[@]} "
2152+
2153+ __print_lines ' start, finish, start:'
21242154 arr=(a b c d)
21252155 __slice {arr} 0 1 2
21262156 echo-verbose -- " ${arr[@]} "
21272157
2128- __print_line
2158+ __print_lines ' start, finish, start, negatives:'
2159+ arr=(a b c d)
2160+ __slice {arr} -4 -3 -1
2161+ echo-verbose -- " ${arr[@]} "
2162+
2163+ __print_lines ' start, finish, start, finish:'
21292164 arr=(a b c d)
21302165 __slice {arr} 0 1 2 3
21312166 echo-verbose -- " ${arr[@]} "
2167+
2168+ __print_lines ' start, finish, start, finish, negatives:'
2169+ arr=(a b c d)
2170+ __slice {arr} -4 -3 -1 -0
2171+ echo-verbose -- " ${arr[@]} "
2172+
2173+ __print_lines ' target var with inputs:'
2174+ __slice {target} 0 1 2 3 -- a b c d
2175+ echo-verbose -- " ${target[@]} "
2176+
2177+ __print_lines ' target var with inputs, append:'
2178+ __slice {target} --append -1 -- y x z
2179+ echo-verbose -- " ${target[@]} "
2180+
2181+ __print_lines ' input var, target var:'
2182+ arr=(a b c d)
2183+ __slice {arr} {target} 0 1 2 3
2184+ echo-verbose -- " ${arr[@]} "
2185+ echo-verbose -- " ${target[@]} "
2186+
2187+ __print_lines ' input var, target var, append:'
2188+ __slice {arr} {target} --append -2
2189+ echo-verbose -- " ${arr[@]} "
2190+ echo-verbose -- " ${target[@]} "
2191+
2192+ __print_lines ' inputs, two target vars:'
2193+ __slice {arr} {target} -1 -- y x z
2194+ echo-verbose -- " ${arr[@]} "
2195+ echo-verbose -- " ${target[@]} "
2196+
2197+ __print_lines ' input var, target var, no indices, append:'
2198+ __slice {arr} {target} --append
2199+ echo-verbose -- " ${arr[@]} "
2200+ echo-verbose -- " ${target[@]} "
2201+
2202+ __print_lines ' inputs, two target vars:'
2203+ __slice --append {arr} {target} -2 -- x y z
2204+ echo-verbose -- " ${arr[@]} "
2205+ echo-verbose -- " ${target[@]} "
2206+
2207+ __print_lines ' input var, target var, no indices:'
2208+ __slice {arr} {target}
2209+ echo-verbose -- " ${arr[@]} "
2210+ echo-verbose -- " ${target[@]} "
21322211 }
21332212 slice_results=" $( slice_tests) "
21342213 __end_test_block ' slice_results' " $(
21352214 cat << -EOF
2215+ start, no indices, no-op:
2216+ [0] = [a]
2217+ [1] = [b]
2218+ [2] = [c]
2219+ [3] = [d]
2220+ start, empty indices, failure:
2221+ status: 22
2222+ start, out of bounds:
2223+ [ nothing provided ]
2224+ start, negative, out of bounds:
2225+ [0] = [a]
2226+ [1] = [b]
2227+ [2] = [c]
2228+ [3] = [d]
2229+ start:
21362230 [0] = [b]
21372231 [1] = [c]
21382232 [2] = [d]
2139-
2233+ start, negative:
2234+ [0] = [c]
2235+ [1] = [d]
2236+ start, finish:
21402237 [0] = [b]
2141-
2238+ start, finish, negatives:
2239+ [0] = [b]
2240+ [1] = [c]
2241+ start, finish, start:
21422242 [0] = [a]
21432243 [1] = [c]
21442244 [2] = [d]
2145-
2245+ start, finish, start, negatives:
2246+ [0] = [a]
2247+ [1] = [d]
2248+ start, finish, start, finish:
21462249 [0] = [a]
21472250 [1] = [c]
2251+ start, finish, start, finish, negatives:
2252+ [0] = [a]
2253+ [1] = [d]
2254+ target var with inputs:
2255+ [0] = [a]
2256+ [1] = [c]
2257+ target var with inputs, append:
2258+ [0] = [a]
2259+ [1] = [c]
2260+ [2] = [z]
2261+ input var, target var:
2262+ [0] = [a]
2263+ [1] = [b]
2264+ [2] = [c]
2265+ [3] = [d]
2266+ [0] = [a]
2267+ [1] = [c]
2268+ input var, target var, append:
2269+ [0] = [a]
2270+ [1] = [b]
2271+ [2] = [c]
2272+ [3] = [d]
2273+ [0] = [a]
2274+ [1] = [c]
2275+ [2] = [c]
2276+ [3] = [d]
2277+ inputs, two target vars:
2278+ [0] = [z]
2279+ [0] = [z]
2280+ input var, target var, no indices, append:
2281+ [0] = [z]
2282+ [0] = [z]
2283+ [1] = [z]
2284+ inputs, two target vars:
2285+ [0] = [z]
2286+ [1] = [y]
2287+ [2] = [z]
2288+ [0] = [z]
2289+ [1] = [z]
2290+ [2] = [y]
2291+ [3] = [z]
2292+ input var, target var, no indices:
2293+ [0] = [z]
2294+ [1] = [y]
2295+ [2] = [z]
2296+ [0] = [z]
2297+ [1] = [y]
2298+ [2] = [z]
21482299 EOF
21492300 ) "
21502301fi
@@ -2560,9 +2711,7 @@ if __begin_test_block --name='try throws_outer throws_inner' \
25602711 __print_lines " FAIL: [$? ] SHOULD NOT SEE THIS (3/3)"
25612712 return 126
25622713 }
2563- # __enable_debugging
25642714 __try {caught_test_status} -- throws_outer
2565- # __disable_debugging
25662715 __end_test_block ' caught_test_status' 123
25672716fi
25682717
@@ -2654,9 +2803,7 @@ if __begin_test_block --name='try throws_outer[subshell] throws_inner[subshell]'
26542803 __print_lines " FAIL: [$? ] SHOULD NOT SEE THIS (3/3)"
26552804 return 126
26562805 )
2657- # __enable_debugging
26582806 __try {caught_test_status} -- throws_outer
2659- # __disable_debugging
26602807 __end_test_block ' caught_test_status' 123
26612808fi
26622809
0 commit comments