-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
test-util.sh
1978 lines (1792 loc) · 68.7 KB
/
test-util.sh
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# source script for ble.sh interactive sessions -*- mode: sh; mode: sh-bash -*-
ble-import lib/core-test
ble/test/start-section 'ble/util' 1226
# bleopt
(
# 定義・設定・出力
ble/test 'bleopt a=1' \
exit=2
ble/test 'bleopt a' \
stdout= exit=2
ble/test 'bleopt a:=2'
ble/test 'bleopt a' \
stdout="bleopt a=2"
ble/test '[[ $bleopt_a == 2 ]]'
ble/test "bleopt | grep 'bleopt a='" \
stdout="bleopt a=2"
ble/test 'bleopt a=3'
ble/test 'bleopt a' \
stdout="bleopt a=3"
# setter
function bleopt/check:a { value=123; }
ble/test 'bleopt a=4 && bleopt a'
stdout="bleopt a=123"
function bleopt/check:a { false; }
ble/test 'bleopt a=5' \
exit=1
ble/test 'bleopt a' \
stdout="bleopt a=123"
# 複数引数
ble/test bleopt f:=10 g:=11
ble/test bleopt f g \
stdout="bleopt f=10${_ble_term_nl}bleopt g=11"
ble/test bleopt f=12 g=13
ble/test bleopt f g \
stdout="bleopt f=12${_ble_term_nl}bleopt g=13"
# bleopt/declare
ble/test bleopt/declare -v b 6
ble/test bleopt b stdout="bleopt b=6"
ble/test bleopt/declare -n c 7
ble/test bleopt c stdout="bleopt c=7"
ble/test bleopt d:= e:=
ble/test bleopt/declare -v d 8
ble/test bleopt/declare -n e 9
ble/test bleopt d stdout="bleopt d="
ble/test bleopt e stdout="bleopt e=9"
)
# ble/test
ble/test ble/util/setexit 0 exit=0
ble/test ble/util/setexit 1 exit=1
ble/test ble/util/setexit 9 exit=9
ble/test ble/util/setexit 128 exit=128
ble/test ble/util/setexit 255 exit=255
# ble/unlocal
(
a=1
function f1 {
echo g:$a
local a=2
echo l:$a
ble/util/unlocal a
echo g:$a
a=3
}
ble/test 'f1; echo g:$a' \
stdout=g:1 \
stdout=l:2 \
stdout=g:1 \
stdout=g:3
function f2 {
echo f1:$a@f2
local a=3
echo f2:$a@f2
ble/util/unlocal a
echo f1:$a@f2
a=$a+
}
function f1 {
echo g:$a@f1
local a=2
echo f1:$a@f1
f2
echo f1:$a@f1
ble/util/unlocal a
echo g:$a@f1
a=$a+
}
ble/test 'a=1; f1; echo g:$a@g' \
stdout=g:1@f1 \
stdout=f1:2@f1 \
stdout=f1:2@f2 \
stdout=f2:3@f2 \
stdout=f1:2@f2 \
stdout=f1:2+@f1 \
stdout=g:1@f1 \
stdout=g:1+@g
)
# ble/util/upvar, ble/util/uparr (Freddy Vulto's trick)
(
function f1 {
local a=1 b=2
local result=$((a+b))
local "$1" && ble/util/upvar "$1" "$result"
}
ble/test 'f1 x; ret=$x' ret=3
ble/test 'f1 a; ret=$a' ret=3
ble/test 'f1 result; ret=$result' ret=3
function f2 {
local a=1
local -a b=(2)
local -a result; result=("$((a+b[0]))" y z)
local "$1" && ble/util/uparr "$1" "${result[@]}"
}
ble/test 'f2 x; ret="(${x[*]})"' ret='(3 y z)'
ble/test 'f2 a; ret="(${a[*]})"' ret='(3 y z)'
ble/test 'f2 b; ret="(${b[*]})"' ret='(3 y z)'
ble/test 'f2 result; ret="(${result[*]})"' ret='(3 y z)'
)
# ble/util/save-vars, restore-vars
(
VARNAMES=(name x y count data)
function print-status {
echo "name=$name x=$x y=$y count=$count data=(${data[*]})"
}
function f1 {
local "${VARNAMES[@]/%/=}" # WA #D1570 checked
name=1 x=2 y=3 count=4 data=(aa bb cc dd)
print-status
ble/util/save-vars save1_ "${VARNAMES[@]}"
name=one x= y=A count=1 data=(Q)
print-status
ble/util/save-vars save2_ "${VARNAMES[@]}"
ble/util/restore-vars save1_ "${VARNAMES[@]}"
print-status
ble/util/restore-vars save2_ "${VARNAMES[@]}"
print-status
}
ble/test f1 \
stdout='name=1 x=2 y=3 count=4 data=(aa bb cc dd)' \
stdout='name=one x= y=A count=1 data=(Q)' \
stdout='name=1 x=2 y=3 count=4 data=(aa bb cc dd)' \
stdout='name=one x= y=A count=1 data=(Q)'
)
# ble/variable#get-attr
(
declare v=1
declare -i i=1
export x=2
readonly r=3
declare -a a=()
if ((_ble_bash>=40000)); then
declare -A A=()
declare -u u=a
declare -l l=B
declare -c c=c
fi
if ((_ble_bash>=40300)); then
declare -n n=r
fi
ble/test 'ble/variable#get-attr v; ret=$attr' ret=
ble/test 'ble/variable#get-attr i; ret=$attr' ret=i
ble/test 'ble/variable#get-attr x; ret=$attr' ret=x
ble/test 'ble/variable#get-attr r; ret=$attr' ret=r
ble/test 'ble/variable#get-attr a; ret=$attr' ret=a
if ((_ble_bash>=40000)); then
ble/test 'ble/variable#get-attr u; ret=$attr' ret=u
ble/test 'ble/variable#get-attr l; ret=$attr' ret=l
ble/test 'ble/variable#get-attr c; ret=$attr' ret=c
ble/test 'ble/variable#get-attr A; ret=$attr' ret=A
fi
# ((_ble_bash>=40300)) &&
# ble/test 'ble/variable#get-attr n; ret=$attr' ret=n
ble/test 'ble/variable#has-attr i i'
ble/test 'ble/variable#has-attr x x'
ble/test 'ble/variable#has-attr r r'
ble/test 'ble/variable#has-attr a a'
ble/test 'ble/variable#has-attr v i' exit=1
ble/test 'ble/variable#has-attr v x' exit=1
ble/test 'ble/variable#has-attr v r' exit=1
ble/test 'ble/variable#has-attr v a' exit=1
if ((_ble_bash>=40000)); then
ble/test 'ble/variable#has-attr u u'
ble/test 'ble/variable#has-attr l l'
ble/test 'ble/variable#has-attr c c'
ble/test 'ble/variable#has-attr A A'
ble/test 'ble/variable#has-attr v u' exit=1
ble/test 'ble/variable#has-attr v l' exit=1
ble/test 'ble/variable#has-attr v c' exit=1
ble/test 'ble/variable#has-attr v A' exit=1
fi
# if ((_ble_bash>=40300)); then
# ble/test 'ble/variable#has-attr n n'
# ble/test 'ble/variable#has-attr v n' exit=1
# fi
ble/test 'ble/is-inttype i'
ble/test 'ble/is-inttype v' exit=1
ble/test 'ble/is-readonly r'
ble/test 'ble/is-readonly v' exit=1
if ((_ble_bash>=40000)); then
ble/test 'ble/is-transformed u'
ble/test 'ble/is-transformed l'
ble/test 'ble/is-transformed c'
ble/test 'ble/is-transformed v' exit=1
fi
)
# ble/variable#is-global
function is-global() (readonly "$1"; ! local "$1" 2>/dev/null)
(
v1=1 v2=2
((_ble_bash>=40200)) &&
declare -g v1u v2u
function f1 {
local v2=22 v3=33
local v2u v3u
f2
}
function f2 {
local v4=444 v4u
ble/test 'is-global v0'
ble/test 'is-global v1'
ble/test 'is-global v2' exit=1
ble/test 'is-global v3' exit=1
ble/test 'is-global v4' exit=1
ble/test 'ble/variable#is-global v0'
ble/test 'ble/variable#is-global v1'
ble/test 'ble/variable#is-global v2' exit=1
ble/test 'ble/variable#is-global v3' exit=1
ble/test 'ble/variable#is-global v4' exit=1
ble/test 'ble/variable#is-global v0u'
if ((_ble_bash>=40200)); then
ble/test 'ble/variable#is-global v1u'
ble/test 'ble/variable#is-global v2u' exit=1
fi
ble/test 'ble/variable#is-global v3u' exit=1
ble/test 'ble/variable#is-global v4u' exit=1
}
f1
)
# _ble_array_prototype
(
_ble_array_prototype=()
ble/test 'echo "${#_ble_array_prototype[@]}"' stdout=0
ble/array#reserve-prototype 10
ble/test 'echo "${#_ble_array_prototype[@]}"' stdout=10
ble/test 'x=("${_ble_array_prototype[@]::10}"); echo "${#x[@]}"' stdout=10
ble/array#reserve-prototype 3
ble/test 'echo "${#_ble_array_prototype[@]}"' stdout=10
ble/test 'x=("${_ble_array_prototype[@]::3}"); echo "${#x[@]}"' stdout=3
)
# ble/is-{array,assoc}
(
declare -a a=()
declare b=
ble/test 'ble/is-array a'
ble/test 'ble/is-array b' exit=1
ble/test 'ble/is-array c' exit=1
if ((_ble_bash>=40000)); then
declare -A A=()
ble/test 'ble/is-array A' exit=1
ble/test 'ble/is-assoc a' exit=1
ble/test 'ble/is-assoc A'
ble/test 'ble/is-assoc b' exit=1
ble/test 'ble/is-assoc c' exit=1
fi
)
# ble/array#set
(
ble/test 'ble/array#set a; echo "${#a[@]}:(${a[*]})"' stdout='0:()'
ble/test 'ble/array#set a Q; echo "${#a[@]}:(${a[*]})"' stdout='1:(Q)'
ble/test 'ble/array#set a 1 2 3; echo "${#a[@]}:(${a[*]})"' stdout='3:(1 2 3)'
ble/test 'ble/array#set a; echo "${#a[@]}:(${a[*]})"' stdout='0:()'
)
# ble/array#push
(
declare -a a=()
ble/array#push a
ble/test 'echo "${#a[@]}:(${a[*]})"' stdout='0:()'
ble/array#push a A
ble/test 'echo "${#a[@]}:(${a[*]})"' stdout='1:(A)'
ble/array#push a B C
ble/test 'echo "${#a[@]}:(${a[*]})"' stdout='3:(A B C)'
ble/array#push a
ble/test 'echo "${#a[@]}:(${a[*]})"' stdout='3:(A B C)'
)
# ble/array#pop
(
function result { echo "$ret:${#arr[*]}:(${arr[*]})"; }
ble/test 'arr=() ; ble/array#pop arr; result' stdout=':0:()'
ble/test 'arr=(1) ; ble/array#pop arr; result' stdout='1:0:()'
ble/test 'arr=(1 2) ; ble/array#pop arr; result' stdout='2:1:(1)'
ble/test 'arr=(0 0 0); ble/array#pop arr; result' stdout='0:2:(0 0)'
ble/test 'arr=(1 2 3); ble/array#pop arr; result' stdout='3:2:(1 2)'
ble/test 'arr=(" a a " " b b " " c c "); ble/array#pop arr; result' \
stdout=' c c :2:( a a b b )'
)
# ble/array#unshift
(
function status { echo "${#a[@]}:(${a[*]})"; }
a=()
ble/array#unshift a
ble/test status stdout='0:()'
ble/array#unshift a A
ble/test status stdout='1:(A)'
ble/array#unshift a
ble/test status stdout='1:(A)'
ble/array#unshift a B
ble/test status stdout='2:(B A)'
ble/array#unshift a C D E
ble/test status stdout='5:(C D E B A)'
a=()
ble/array#unshift a A B
ble/test status stdout='2:(A B)'
)
# ble/array#reverse
(
function status { echo "${#a[@]}:(${a[*]})"; }
a=(); ble/array#reverse a
ble/test status stdout='0:()'
a=(1); ble/array#reverse a
ble/test status stdout='1:(1)'
a=(xy zw); ble/array#reverse a
ble/test status stdout='2:(zw xy)'
a=(a 3 x); ble/array#reverse a
ble/test status stdout='3:(x 3 a)'
a=({1..10}) b=({10..1}); ble/array#reverse a
ble/test status stdout="10:(${b[*]})"
a=({1..9}) b=({9..1}); ble/array#reverse a
ble/test status stdout="9:(${b[*]})"
)
# ble/array#insert-at
(
function status { echo "${#a[@]}:(${a[*]})"; }
a=(); ble/array#insert-at a 0 A B C
ble/test status stdout='3:(A B C)'
a=(); ble/array#insert-at a 1 A B C
ble/test status stdout='3:(A B C)'
a=(x y z); ble/array#insert-at a 0 A
ble/test status stdout='4:(A x y z)'
a=(x y z); ble/array#insert-at a 1 A
ble/test status stdout='4:(x A y z)'
a=(x y z); ble/array#insert-at a 3 A
ble/test status stdout='4:(x y z A)'
a=(x y z); ble/array#insert-at a 0 A B C
ble/test status stdout='6:(A B C x y z)'
a=(x y z); ble/array#insert-at a 1 A B C
ble/test status stdout='6:(x A B C y z)'
a=(x y z); ble/array#insert-at a 3 A B C
ble/test status stdout='6:(x y z A B C)'
a=(x y z); ble/array#insert-at a 0
ble/test status stdout='3:(x y z)'
a=(x y z); ble/array#insert-at a 1
ble/test status stdout='3:(x y z)'
a=(x y z); ble/array#insert-at a 3
ble/test status stdout='3:(x y z)'
)
# ble/array#insert-after
(
function status { echo "${#a[@]}:(${a[*]})"; }
a=(hello world hello world)
ble/array#insert-after a hello 1 2 3
ble/test status stdout='7:(hello 1 2 3 world hello world)'
a=(heart world hello world)
ble/array#insert-after a hello 1 2 3
ble/test status stdout='7:(heart world hello 1 2 3 world)'
a=(hello world hello world)
ble/test 'ble/array#insert-after a check 1 2 3' exit=1
ble/test status stdout='4:(hello world hello world)'
)
# ble/array#insert-before
(
function status { echo "${#a[@]}:(${a[*]})"; }
a=(hello world this)
ble/array#insert-before a this with check
ble/test status stdout='5:(hello world with check this)'
a=(hello world this)
ble/test 'ble/array#insert-before a haystack kick check' exit=1
ble/test status stdout='3:(hello world this)'
)
# ble/array#remove
(
function status { echo "${#a[@]}:(${a[*]})"; }
a=(xxx yyy xxx yyy yyy xxx fdsa fdsa)
ble/array#remove a xxx
ble/test status stdout='5:(yyy yyy yyy fdsa fdsa)'
a=(aa aa aa aa aa)
ble/array#remove a bb
ble/test status stdout='5:(aa aa aa aa aa)'
ble/array#remove a aa
ble/test status stdout='0:()'
ble/array#remove a cc
ble/test status stdout='0:()'
)
# ble/array#index
(
a=(hello world this hello world)
ble/test 'ble/array#index a hello' ret=0
a=(world hep this hello world)
ble/test 'ble/array#index a hello' ret=3
a=(hello world this hello world)
ble/test 'ble/array#index a check' ret=-1
)
# ble/array#last-index
(
a=(hello world this hello world)
ble/test 'ble/array#last-index a hello' ret=3
a=(world hep this hello world)
ble/test 'ble/array#last-index a hello' ret=3
a=(hello world this hello world)
ble/test 'ble/array#last-index a check' ret=-1
)
# ble/array#remove-at
(
function status { echo "${#a[@]}:(${a[*]})"; }
a=()
ble/test 'ble/array#remove-at a 0; status' stdout='0:()'
ble/test 'ble/array#remove-at a 10; status' stdout='0:()'
a=(x y z)
ble/test 'ble/array#remove-at a 4; status' stdout='3:(x y z)'
ble/test 'ble/array#remove-at a 3; status' stdout='3:(x y z)'
ble/test 'ble/array#remove-at a 1; status' stdout='2:(x z)'
ble/test 'ble/array#remove-at a 0; status' stdout='1:(z)'
ble/test 'ble/array#remove-at a 0; status' stdout='0:()'
a=({a..z}) a1=({a..y}) a2=({b..y}) a3=({b..h} {j..y})
ble/test 'ble/array#remove-at a 25; status' stdout="25:(${a1[*]})"
ble/test 'ble/array#remove-at a 0; status' stdout="24:(${a2[*]})"
ble/test 'ble/array#remove-at a 7; status' stdout="23:(${a3[*]})"
)
# ble/string#reserve-prototype
(
_ble_string_prototype=' '
ble/test 'echo "${#_ble_string_prototype}"' stdout=8
ble/string#reserve-prototype 10
ble/test 'echo "${#_ble_string_prototype}"' stdout=16
ble/test 'x=${_ble_string_prototype::10}; echo "${#x}"' stdout=10
ble/string#reserve-prototype 3
ble/test 'echo "${#_ble_string_prototype}"' stdout=16
ble/test 'x=${_ble_string_prototype::3}; echo "${#x}"' stdout=3
ble/string#reserve-prototype 77
ble/test 'echo "${#_ble_string_prototype}"' stdout=128
ble/test 'x=${_ble_string_prototype::77}; echo "${#x}"' stdout=77
)
# ble/string#repeat
(
ble/test 'ble/string#repeat' ret=
ble/test 'ble/string#repeat ""' ret=
ble/test 'ble/string#repeat a' ret=
ble/test 'ble/string#repeat abc' ret=
ble/test 'ble/string#repeat "" ""' ret=
ble/test 'ble/string#repeat a ""' ret=
ble/test 'ble/string#repeat abc ""' ret=
ble/test 'ble/string#repeat "" 0' ret=
ble/test 'ble/string#repeat a 0' ret=
ble/test 'ble/string#repeat abc 0' ret=
ble/test 'ble/string#repeat "" 1' ret=
ble/test 'ble/string#repeat "" 10' ret=
ble/test 'ble/string#repeat a 1' ret=a
ble/test 'ble/string#repeat a 2' ret=aa
ble/test 'ble/string#repeat a 5' ret=aaaaa
ble/test 'ble/string#repeat abc 1' ret=abc
ble/test 'ble/string#repeat abc 2' ret=abcabc
ble/test 'ble/string#repeat abc 5' ret=abcabcabcabcabc
ble/test 'ble/string#repeat ";&|<>" 5' ret=';&|<>;&|<>;&|<>;&|<>;&|<>'
)
# ble/string#common-prefix
(
ble/test 'ble/string#common-prefix' ret=
ble/test 'ble/string#common-prefix ""' ret=
ble/test 'ble/string#common-prefix a' ret=
ble/test 'ble/string#common-prefix "" ""' ret=
ble/test 'ble/string#common-prefix a ""' ret=
ble/test 'ble/string#common-prefix a b' ret=
ble/test 'ble/string#common-prefix a a' ret=a
ble/test 'ble/string#common-prefix abc abc' ret=abc
ble/test 'ble/string#common-prefix abc aaa' ret=a
ble/test 'ble/string#common-prefix abc ccc' ret=
ble/test 'ble/string#common-prefix abc xyz' ret=
)
# ble/string#common-suffix
(
ble/test 'ble/string#common-suffix' ret=
ble/test 'ble/string#common-suffix ""' ret=
ble/test 'ble/string#common-suffix a' ret=
ble/test 'ble/string#common-suffix "" ""' ret=
ble/test 'ble/string#common-suffix a ""' ret=
ble/test 'ble/string#common-suffix a b' ret=
ble/test 'ble/string#common-suffix a a' ret=a
ble/test 'ble/string#common-suffix abc abc' ret=abc
ble/test 'ble/string#common-suffix abc aaa' ret=
ble/test 'ble/string#common-suffix abc ccc' ret=c
ble/test 'ble/string#common-suffix abc xyz' ret=
)
# ble/string#split
(
function status { echo "${#a[@]}:(""${a[*]}"")"; }
nl=$'\n'
ble/test 'ble/string#split a , "" ; status' stdout='1:()'
ble/test 'ble/string#split a , "1" ; status' stdout='1:(1)'
ble/test 'ble/string#split a , "," ; status' stdout='2:( )'
ble/test 'ble/string#split a , "1," ; status' stdout='2:(1 )'
ble/test 'ble/string#split a , ",2" ; status' stdout='2:( 2)'
ble/test 'ble/string#split a , "1,,3" ; status' stdout='3:(1 3)'
ble/test 'ble/string#split a , "1,2,3" ; status' stdout='3:(1 2 3)'
ble/test 'ble/string#split a " " "1 2 3"; status' stdout='3:(1 2 3)'
ble/test 'ble/string#split a " " "1 2 3"; status' stdout='1:(1 2 3)'
ble/test 'ble/string#split a " " "1'"$nl"'2'"$nl"'3"; status' stdout="1:(1${nl}2${nl}3)"
)
# ble/string#split-words
(
function status { echo "${#a[@]}:(${a[*]})"; }
nl=$'\n' ht=$'\t'
ble/test 'ble/string#split-words a "" ; status' stdout='0:()'
ble/test 'ble/string#split-words a "1" ; status' stdout='1:(1)'
ble/test 'ble/string#split-words a " " ; status' stdout='0:()'
ble/test 'ble/string#split-words a "1 " ; status' stdout='1:(1)'
ble/test 'ble/string#split-words a " 2" ; status' stdout='1:(2)'
ble/test 'ble/string#split-words a "1 3" ; status' stdout='2:(1 3)'
ble/test 'ble/string#split-words a "1 2 3"; status' stdout='3:(1 2 3)'
ble/test 'ble/string#split-words a " 1'"$ht"'2'"$ht"'3 "; status' stdout='3:(1 2 3)'
ble/test 'ble/string#split-words a " 1'"$nl"'2'"$nl"'3 "; status' stdout='3:(1 2 3)'
)
# ble/string#split-lines
(
function status { echo "${#a[@]}:(""${a[*]}"")"; }
nl=$'\n' ht=$'\t'
ble/test 'ble/string#split-lines a "" ; status' stdout='1:()'
ble/test 'ble/string#split-lines a "1" ; status' stdout='1:(1)'
ble/test 'ble/string#split-lines a "'"$nl"'" ; status' stdout='2:( )'
ble/test 'ble/string#split-lines a "1'"$nl"'" ; status' stdout='2:(1 )'
ble/test 'ble/string#split-lines a "'"$nl"'2" ; status' stdout='2:( 2)'
ble/test 'ble/string#split-lines a "1'"$nl$nl"'3" ; status' stdout='3:(1 3)'
ble/test 'ble/string#split-lines a "1'"$nl"'2'"$nl"'3"; status' stdout='3:(1 2 3)'
ble/test 'ble/string#split-lines a "1'"$ht"'2'"$ht"'3"; status' stdout="1:(1${ht}2${ht}3)"
ble/test 'ble/string#split-lines a "1 2 3"; status' stdout="1:(1 2 3)"
)
# ble/string#count-char
(
#UB: ble/test 'ble/string#count-char hello' ret=5
ble/test 'ble/string#count-char hello a' ret=0
ble/test 'ble/string#count-char hello あ' ret=0
ble/test 'ble/string#count-char hello e' ret=1
ble/test 'ble/string#count-char hello l' ret=2
ble/test 'ble/string#count-char hello olh' ret=4
ble/test 'ble/string#count-char hello hello' ret=5
ble/test 'ble/string#count-char "" a' ret=0
ble/test 'ble/string#count-char "" ab' ret=0
)
# ble/string#count-string
(
ble/test 'ble/string#count-string hello a' ret=0
ble/test 'ble/string#count-string hello あ' ret=0
ble/test 'ble/string#count-string hello ee' ret=0
ble/test 'ble/string#count-string hello e' ret=1
ble/test 'ble/string#count-string hello l' ret=2
ble/test 'ble/string#count-string hello ll' ret=1
ble/test 'ble/string#count-string hello hello' ret=1
ble/test 'ble/string#count-string "" a' ret=0
ble/test 'ble/string#count-string "" ab' ret=0
ble/test 'ble/string#count-string ababababa aba' ret=2
)
# ble/string#index-of
(
ble/test 'ble/string#index-of hello a' ret=-1
ble/test 'ble/string#index-of hello あ' ret=-1
ble/test 'ble/string#index-of hello ee' ret=-1
ble/test 'ble/string#index-of hello e' ret=1
ble/test 'ble/string#index-of hello l' ret=2
ble/test 'ble/string#index-of hello ll' ret=2
ble/test 'ble/string#index-of hello hello' ret=0
ble/test 'ble/string#index-of "" a' ret=-1
ble/test 'ble/string#index-of "" ab' ret=-1
ble/test 'ble/string#index-of ababababa aba' ret=0
)
# ble/string#last-index-of
(
ble/test 'ble/string#last-index-of hello a' ret=-1
ble/test 'ble/string#last-index-of hello あ' ret=-1
ble/test 'ble/string#last-index-of hello ee' ret=-1
ble/test 'ble/string#last-index-of hello e' ret=1
ble/test 'ble/string#last-index-of hello l' ret=3
ble/test 'ble/string#last-index-of hello ll' ret=2
ble/test 'ble/string#last-index-of hello hello' ret=0
ble/test 'ble/string#last-index-of "" a' ret=-1
ble/test 'ble/string#last-index-of "" ab' ret=-1
ble/test 'ble/string#last-index-of ababababa aba' ret=6
)
# ble/string#{toggle-case,tolower,toupper,capitalize}
(
ble/test 'ble/string#toggle-case' ret=
ble/test 'ble/string#tolower ' ret=
ble/test 'ble/string#toupper ' ret=
ble/test 'ble/string#capitalize ' ret=
ble/test 'ble/string#toggle-case ""' ret=
ble/test 'ble/string#tolower ""' ret=
ble/test 'ble/string#toupper ""' ret=
ble/test 'ble/string#capitalize ""' ret=
ble/test 'ble/string#toggle-case a' ret=A
ble/test 'ble/string#tolower a' ret=a
ble/test 'ble/string#toupper a' ret=A
ble/test 'ble/string#capitalize a' ret=A
ble/test 'ble/string#toggle-case あ' ret=あ
ble/test 'ble/string#tolower あ' ret=あ
ble/test 'ble/string#toupper あ' ret=あ
ble/test 'ble/string#capitalize あ' ret=あ
ble/test 'ble/string#toggle-case +' ret=+
ble/test 'ble/string#tolower +' ret=+
ble/test 'ble/string#toupper +' ret=+
ble/test 'ble/string#capitalize +' ret=+
ble/test 'ble/string#toggle-case abc' ret=ABC
ble/test 'ble/string#tolower abc' ret=abc
ble/test 'ble/string#toupper abc' ret=ABC
ble/test 'ble/string#capitalize abc' ret=Abc
ble/test 'ble/string#toggle-case ABC' ret=abc
ble/test 'ble/string#tolower ABC' ret=abc
ble/test 'ble/string#toupper ABC' ret=ABC
ble/test 'ble/string#capitalize ABC' ret=Abc
ble/test 'ble/string#toggle-case aBc' ret=AbC
ble/test 'ble/string#tolower aBc' ret=abc
ble/test 'ble/string#toupper aBc' ret=ABC
ble/test 'ble/string#capitalize aBc' ret=Abc
ble/test 'ble/string#toggle-case +aBc' ret=+AbC
ble/test 'ble/string#tolower +aBc' ret=+abc
ble/test 'ble/string#toupper +aBc' ret=+ABC
ble/test 'ble/string#capitalize +aBc' ret=+Abc
ble/test 'ble/string#capitalize "hello world"' ret='Hello World'
LC_ALL=en_US.utf8
ble/test 'ble/string#toggle-case +aBc' ret=+AbC
ble/test 'ble/string#tolower +aBc' ret=+abc
ble/test 'ble/string#toupper +aBc' ret=+ABC
ble/test 'ble/string#capitalize +aBc' ret=+Abc
ble/test 'ble/string#capitalize "hello world"' ret='Hello World'
)
# ble/string#{trim,ltrim,rtrim}
(
ble/test 'ble/string#trim ' ret=
ble/test 'ble/string#ltrim' ret=
ble/test 'ble/string#rtrim' ret=
ble/test 'ble/string#trim ""' ret=
ble/test 'ble/string#ltrim ""' ret=
ble/test 'ble/string#rtrim ""' ret=
ble/test 'ble/string#trim "a"' ret=a
ble/test 'ble/string#ltrim "a"' ret=a
ble/test 'ble/string#rtrim "a"' ret=a
ble/test 'ble/string#trim " a "' ret=a
ble/test 'ble/string#ltrim " a "' ret='a '
ble/test 'ble/string#rtrim " a "' ret=' a'
ble/test 'ble/string#trim " a b "' ret='a b'
ble/test 'ble/string#ltrim " a b "' ret='a b '
ble/test 'ble/string#rtrim " a b "' ret=' a b'
ble/test 'ble/string#trim "abc"' ret='abc'
ble/test 'ble/string#ltrim "abc"' ret='abc'
ble/test 'ble/string#rtrim "abc"' ret='abc'
ble/test 'ble/string#trim " abc "' ret='abc'
ble/test 'ble/string#ltrim " abc "' ret='abc '
ble/test 'ble/string#rtrim " abc "' ret=' abc'
for pad in $' \t\n \t\n' $'\t\t\t' $'\n\n\n'; do
ble/test 'ble/string#trim "'"$pad"'abc'"$pad"'"' ret='abc'
ble/test 'ble/string#ltrim "'"$pad"'abc'"$pad"'"' ret="abc${pad}"
ble/test 'ble/string#rtrim "'"$pad"'abc'"$pad"'"' ret="${pad}abc"
done
)
# ble/string#escape-characters
(
ble/test 'ble/string#escape-characters hello' ret=hello
ble/test 'ble/string#escape-characters hello ""' ret=hello
ble/test 'ble/string#escape-characters hello xyz' ret=hello
ble/test 'ble/string#escape-characters hello el' ret='h\e\l\lo'
ble/test 'ble/string#escape-characters hello hl XY' ret='\Xe\Y\Yo'
# regex
ble/test 'ble/string#escape-for-sed-regex "A\.[*?+|^\$(){}/"' \
ret='A\\\.\[\*?+|\^\$(){}\/'
ble/test 'ble/string#escape-for-awk-regex "A\.[*?+|^\$(){}/"' \
ret='A\\\.\[\*\?\+\|\^\$\(\)\{\}\/'
ble/test 'ble/string#escape-for-extended-regex "A\.[*?+|^\$(){}/"' \
ret='A\\\.\[\*\?\+\|\^\$\(\)\{\}/'
# bash
ble/test 'ble/string#escape-for-bash-glob "A\*?[("' ret='A\\\*\?\[\('
ble/test 'ble/string#escape-for-bash-single-quote "A'\''B"' ret="A'\''B"
ble/test 'ble/string#escape-for-bash-double-quote "hello \$ \` \\ ! world"' ret='hello \$ \` \\ "\!" world'
input=A$'\\\a\b\e\f\n\r\t\v'\'B output=A'\\\a\b\e\f\n\r\t\v\'\'B
ble/test 'ble/string#escape-for-bash-escape-string "$input"' ret="$output"
ble/test 'ble/string#escape-for-bash-specialchars "[hello] (world) {this,is} <test>"' \
ret='\[hello\]\ \(world\)\ {this,is}\ \<test\>'
ble/test 'ble/string#escape-for-bash-specialchars "[hello] (world) {this,is} <test>" b' \
ret='\[hello\]\ \(world\)\ \{this\,is\}\ \<test\>'
ble/test 'ble/string#escape-for-bash-specialchars "a=b:c:d" c' \
ret='a\=b\:c\:d'
ble/test $'ble/string#escape-for-bash-specialchars "a\tb\tc"' \
ret=$'a\\\tb\\\tc'
)
# ble/string#quote-command, ble/util/print-quoted-command
(
ble/test 'ble/string#quote-command' ret=
ble/test 'ble/string#quote-command echo' ret='echo'
ble/test 'ble/string#quote-command echo hello world' ret="echo 'hello' 'world'"
ble/test 'ble/string#quote-command echo "hello world"' ret="echo 'hello world'"
ble/test 'ble/string#quote-command echo "'\''test'\''"' ret="echo ''\''test'\'''"
ble/test 'ble/string#quote-command echo "" "" ""' ret="echo '' '' ''"
ble/test 'ble/string#quote-command echo a{1..4}' ret="echo 'a1' 'a2' 'a3' 'a4'"
ble/test 'ble/util/print-quoted-command' stdout=
ble/test 'ble/util/print-quoted-command echo' stdout='echo'
ble/test 'ble/util/print-quoted-command echo hello world' stdout="echo 'hello' 'world'"
ble/test 'ble/util/print-quoted-command echo "hello world"' stdout="echo 'hello world'"
ble/test 'ble/util/print-quoted-command echo "'\''test'\''"' stdout="echo ''\''test'\'''"
ble/test 'ble/util/print-quoted-command echo "" "" ""' stdout="echo '' '' ''"
ble/test 'ble/util/print-quoted-command echo a{1..4}' stdout="echo 'a1' 'a2' 'a3' 'a4'"
)
# ble/string#quote-word
(
ble/test 'ble/string#quote-word' ret=
ble/test 'ble/string#quote-word echo' ret='echo'
ble/test 'ble/string#quote-word "hello world"' ret="'hello world'"
ble/test 'ble/string#quote-word "'\''test'\''"' ret="\'test\'"
ble/test 'ble/string#quote-word "a'\''b'\''c"' ret="a\'b\'c"
)
# ble/string#create-unicode-progress-bar
(
ble/test 'ble/string#create-unicode-progress-bar 0 24 3' ret=' '
ble/test 'ble/string#create-unicode-progress-bar 1 24 3' ret='▏ '
ble/test 'ble/string#create-unicode-progress-bar 2 24 3' ret='▎ '
ble/test 'ble/string#create-unicode-progress-bar 3 24 3' ret='▍ '
ble/test 'ble/string#create-unicode-progress-bar 4 24 3' ret='▌ '
ble/test 'ble/string#create-unicode-progress-bar 5 24 3' ret='▋ '
ble/test 'ble/string#create-unicode-progress-bar 6 24 3' ret='▊ '
ble/test 'ble/string#create-unicode-progress-bar 7 24 3' ret='▉ '
ble/test 'ble/string#create-unicode-progress-bar 8 24 3' ret='█ '
ble/test 'ble/string#create-unicode-progress-bar 9 24 3' ret='█▏ '
ble/test 'ble/string#create-unicode-progress-bar 15 24 3' ret='█▉ '
ble/test 'ble/string#create-unicode-progress-bar 16 24 3' ret='██ '
ble/test 'ble/string#create-unicode-progress-bar 17 24 3' ret='██▏'
ble/test 'ble/string#create-unicode-progress-bar 24 24 3' ret='███'
ble/test 'ble/string#create-unicode-progress-bar 0 24 4 unlimited' ret=$'█ '
ble/test 'ble/string#create-unicode-progress-bar 1 24 4 unlimited' ret=$'\e[7m▏\e[27m▏ '
ble/test 'ble/string#create-unicode-progress-bar 2 24 4 unlimited' ret=$'\e[7m▎\e[27m▎ '
ble/test 'ble/string#create-unicode-progress-bar 3 24 4 unlimited' ret=$'\e[7m▍\e[27m▍ '
ble/test 'ble/string#create-unicode-progress-bar 4 24 4 unlimited' ret=$'\e[7m▌\e[27m▌ '
ble/test 'ble/string#create-unicode-progress-bar 5 24 4 unlimited' ret=$'\e[7m▋\e[27m▋ '
ble/test 'ble/string#create-unicode-progress-bar 6 24 4 unlimited' ret=$'\e[7m▊\e[27m▊ '
ble/test 'ble/string#create-unicode-progress-bar 7 24 4 unlimited' ret=$'\e[7m▉\e[27m▉ '
ble/test 'ble/string#create-unicode-progress-bar 8 24 4 unlimited' ret=$' █ '
ble/test 'ble/string#create-unicode-progress-bar 9 24 4 unlimited' ret=$' \e[7m▏\e[27m▏ '
ble/test 'ble/string#create-unicode-progress-bar 15 24 4 unlimited' ret=$' \e[7m▉\e[27m▉ '
ble/test 'ble/string#create-unicode-progress-bar 16 24 4 unlimited' ret=$' █ '
ble/test 'ble/string#create-unicode-progress-bar 17 24 4 unlimited' ret=$' \e[7m▏\e[27m▏'
ble/test 'ble/string#create-unicode-progress-bar 24 24 4 unlimited' ret=$'█ '
)
# ble/util/strlen
(
ble/test 'ble/util/strlen' ret=0
ble/test 'ble/util/strlen ""' ret=0
ble/test 'ble/util/strlen a' ret=1
ble/test 'ble/util/strlen abc' ret=3
ble/test 'ble/util/strlen α' ret=2
ble/test 'ble/util/strlen αβγ' ret=6
ble/test 'ble/util/strlen あ' ret=3
ble/test 'ble/util/strlen あいう' ret=9
ble/test 'ble/util/strlen aα' ret=3
ble/test 'ble/util/strlen aαあ' ret=6
LC_ALL=en_US.utf8
ble/test 'ble/util/strlen a' ret=1
ble/test 'ble/util/strlen α' ret=2
ble/test 'ble/util/strlen あ' ret=3
)
# ble/util/substr
(
ble/test 'ble/util/substr' ret=
ble/test 'ble/util/substr ""' ret=
ble/test 'ble/util/substr a' ret=
ble/test 'ble/util/substr "" 0' ret=
ble/test 'ble/util/substr "" 1' ret=
ble/test 'ble/util/substr a 0' ret=
ble/test 'ble/util/substr a 1' ret=
ble/test 'ble/util/substr a 2' ret=
ble/test 'ble/util/substr "" 0 0' ret=
ble/test 'ble/util/substr "" 0 1' ret=
ble/test 'ble/util/substr "" 1 1' ret=
ble/test 'ble/util/substr a 0 0' ret=
ble/test 'ble/util/substr a 1 0' ret=
ble/test 'ble/util/substr a 0 1' ret=a
ble/test 'ble/util/substr a 1 1' ret=
ble/test 'ble/util/substr abc 1 0' ret=
ble/test 'ble/util/substr abc 1 1' ret=b
ble/test 'ble/util/substr abc 1 2' ret=bc
ble/test 'ble/util/substr abc 0 0' ret=
ble/test 'ble/util/substr abc 0 1' ret=a
ble/test 'ble/util/substr abc 0 3' ret=abc
ble/test 'ble/util/substr abc 0 4' ret=abc
ble/test 'ble/util/substr abc 3 0' ret=
ble/test 'ble/util/substr abc 3 1' ret=
ble/test 'ble/util/substr abc 4 0' ret=
ble/test 'ble/util/substr abc 4 1' ret=
ble/test 'ble/util/substr あいう 0 3' ret=あ
ble/test 'ble/util/substr あいう 3 6' ret=いう
ble/test 'ble/util/substr あいう 0 1' ret=$'\xe3'
ble/test 'ble/util/substr あいう 1 2' ret=$'\x81\x82'
ble/test 'ble/util/substr あいう 1 4' ret=$'\x81\x82\xe3\x81'
ble/test 'ble/util/substr あいう 7 5' ret=$'\x81\x86'
)
# ble/path#remove{,-glob}
(
for cmd in ble/path#{remove,remove-glob}; do
ble/test code:'ret=; '$cmd' ret' ret=
ble/test code:'ret=; '$cmd' ret ""' ret=
ble/test code:'ret=a; '$cmd' ret ""' ret=a
ble/test code:'ret=a; '$cmd' ret a' ret=
ble/test code:'ret=a; '$cmd' ret b' ret=a
ble/test code:'ret=a:a:a; '$cmd' ret a' ret=
ble/test code:'ret=aa; '$cmd' ret a' ret=aa
ble/test code:'ret=xyz:abc; '$cmd' ret ""' ret=xyz:abc
ble/test code:'ret=xyz:abc; '$cmd' ret xyz' ret=abc
ble/test code:'ret=xyz:abc; '$cmd' ret abc' ret=xyz
ble/test code:'ret=xyz:abc:tuv; '$cmd' ret xyz' ret=abc:tuv
ble/test code:'ret=xyz:abc:tuv; '$cmd' ret abc' ret=xyz:tuv
ble/test code:'ret=xyz:abc:tuv; '$cmd' ret tuv' ret=xyz:abc
ble/test code:'ret=xyz:xyz; '$cmd' ret xyz' ret=
ble/test code:'ret=xyz:abc:xyz; '$cmd' ret xyz' ret=abc
ble/test code:'ret=xyz:abc:xyz; '$cmd' ret abc' ret=xyz:xyz
ble/test code:'ret=xyz:xyz:xyz; '$cmd' ret xyz' ret=
done
ble/test code:'ret=a; ble/path#remove ret \?' ret=a
ble/test code:'ret=aa; ble/path#remove ret \?' ret=aa
ble/test code:'ret=a:b; ble/path#remove ret \?' ret=a:b
ble/test code:'ret=a:b:c; ble/path#remove ret \?' ret=a:b:c
ble/test code:'ret=aa:b:cc; ble/path#remove ret \?' ret=aa:b:cc
ble/test code:'ret=stdX:stdY:usrZ; ble/path#remove ret "std[a-zX-Z]"' ret=stdX:stdY:usrZ
ble/test code:'ret=stdX:usrZ:stdY; ble/path#remove ret "std[a-zX-Z]"' ret=stdX:usrZ:stdY
ble/test code:'ret=usrZ:stdX:stdY; ble/path#remove ret "std[a-zX-Z]"' ret=usrZ:stdX:stdY
ble/test code:'ret=a; ble/path#remove-glob ret \?' ret=
ble/test code:'ret=aa; ble/path#remove-glob ret \?' ret=aa
ble/test code:'ret=a:b; ble/path#remove-glob ret \?' ret=
ble/test code:'ret=a:b:c; ble/path#remove-glob ret \?' ret=
ble/test code:'ret=aa:b:cc; ble/path#remove-glob ret \?' ret=aa:cc
ble/test code:'ret=stdX:stdY:usrZ; ble/path#remove-glob ret "std[a-zX-Z]"' ret=usrZ
ble/test code:'ret=stdX:usrZ:stdY; ble/path#remove-glob ret "std[a-zX-Z]"' ret=usrZ
ble/test code:'ret=usrZ:stdX:stdY; ble/path#remove-glob ret "std[a-zX-Z]"' ret=usrZ
)
# ble/path#{append,prepend,contains}
(
ble/test code:'ret=; ble/path#append ret a' ret=a
ble/test code:'ret=a; ble/path#append ret a' ret=a:a
ble/test code:'ret=a; ble/path#append ret b' ret=a:b
ble/test code:'ret=a:b; ble/path#append ret cd' ret=a:b:cd
ble/test code:'ret=; ble/path#prepend ret a' ret=a
ble/test code:'ret=a; ble/path#prepend ret a' ret=a:a
ble/test code:'ret=a; ble/path#prepend ret b' ret=b:a
ble/test code:'ret=a:b; ble/path#prepend ret cd' ret=cd:a:b
ble/test code:'ret=a:b:c; ble/path#contains ret a'
ble/test code:'ret=a:b:c; ble/path#contains ret b'
ble/test code:'ret=a:b:c; ble/path#contains ret c'
ble/test code:'ret=a:b:c; ! ble/path#contains ret x'
ble/test code:'ret=a:b:c; ! ble/path#contains ret aa'
ble/test code:'ret=a:b:c; ! ble/path#contains ret bb'
ble/test code:'ret=a:b:c; ! ble/path#contains ret cc'
ble/test code:'ret=a:b:c; ! ble/path#contains ret "?"'
ble/test code:'ret=a:b:c; ! ble/path#contains ret "*"'
ble/test code:'ret=abc:def; ble/path#contains ret abc'
ble/test code:'ret=abc:def; ble/path#contains ret def'
ble/test code:'ret=abc:def; ! ble/path#contains ret a'
ble/test code:'ret=abc:def; ! ble/path#contains ret ab'
ble/test code:'ret=abc:def; ! ble/path#contains ret abcdef'
ble/test code:'ret=abc:def; ! ble/path#contains ret "???"'
ble/test code:'ret=xyz; ble/path#contains ret xyz'
ble/test code:'ret=xyz; ! ble/path#contains ret xyz:xyz'
ble/test code:'ret=xyz; ! ble/path#contains ret "???"'
)
# ble/dict#set
(
builtin eval -- "${_ble_util_dict_declare//NAME/dict1}"
builtin eval -- "${_ble_util_gdict_declare//NAME/dict2}"
builtin eval -- "${_ble_util_adict_declare//NAME/dict3}"
index=1
for Dict in ble/{,g,a}dict; do
dict=dict$((index++))
ret=unchanged
ble/test '! '$Dict'#has '$dict' banana' ret=unchanged
ble/test '! '$Dict'#has '$dict' ""' ret=unchanged
$Dict#set $dict apple red
$Dict#set $dict banana yellow
$Dict#set $dict orange orange
$Dict#set $dict melon green
ret=unchanged
ble/test $Dict'#has '$dict' banana' ret=unchanged # 先頭
ble/test $Dict'#has '$dict' apple' ret=unchanged # 中
ble/test $Dict'#has '$dict' melon' ret=unchanged # 末尾
ble/test '! '$Dict'#has '$dict' pear' ret=unchanged # 存在しない項目
ble/test $Dict'#get '$dict' banana' ret=yellow # 先頭
ble/test $Dict'#get '$dict' apple' ret=red # 中
ble/test $Dict'#get '$dict' melon' ret=green # 末尾
ble/test '! '$Dict'#get '$dict' pear' ret= # 存在しない項目
# 空白類
ble/test '! '$Dict'#has '$dict' ""' # 末尾空要素で引けるか
ble/test '! '$Dict'#get '$dict' ""' # 末尾空要素で引けるか
$Dict#set $dict '' transparent
ble/test $Dict'#has '$dict' ""' # 末尾空要素で引けるか
ble/test $Dict'#get '$dict' ""' ret=transparent # 末尾空要素で引けるか
$Dict#set $dict 'alpha beta' pink
ble/test $Dict'#has '$dict' ""' # 中央空要素で引けるか
ble/test $Dict'#has '$dict' "alpha beta"' # 空白を含む見出し
ble/test $Dict'#get '$dict' ""' ret=transparent # 中央空要素で引けるか
ble/test $Dict'#get '$dict' "alpha beta"' ret=pink # 空白を含む見出し
$Dict#set $dict ' apple ' ' red '
ble/test $Dict'#has '$dict' " apple "' # 空白で trim されないか
ble/test $Dict'#has '$dict' apple' # 既存項目を破壊していないか
ble/test $Dict'#get '$dict' " apple "' ret=' red ' # 空白で trim されないか
ble/test $Dict'#get '$dict' apple' ret=red # 既存項目を破壊していないか
# FS, colon
ble/test '! '$Dict'#has '$dict' "${_ble_term_FS}"' # 単一FS
ble/test '! '$Dict'#has '$dict' ":"' # 単一コロン
ble/test '! '$Dict'#has '$dict' "apple${_ble_term_FS}banana"' # FSを含む見出し
ble/test '! '$Dict'#has '$dict' apple:banana' # コロンを含む見出し
ble/test '! '$Dict'#get '$dict' "${_ble_term_FS}"' ret= # 単一FS
ble/test '! '$Dict'#get '$dict' ":"' ret= # 単一コロン
ble/test '! '$Dict'#get '$dict' "apple${_ble_term_FS}banana"' ret= # FSを含む見出し
ble/test '! '$Dict'#get '$dict' apple:banana' ret= # コロンを含む見出し
$Dict#set $dict "${_ble_term_FS}" Empty
$Dict#set $dict ":" Colon
$Dict#set $dict "apple${_ble_term_FS}banana" RedYellow
$Dict#set $dict "apple:banana" __red_yellow__