nesto/tests/types.test.sh

160 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
verbose=yes
source ./types.sh
echo '--Assoc--'
sAss="([ert]= [dd]=\"toto\" [blo]=true)"
Map obj=(
[ert]=
[dd]="toto"
[blo]=true
)
Map ass=$sAss
debug obj ass
echo '--Array--'
sArr="(a b c d e f)"
Array arr1=(a b c d e f)
Array arr2=$sArr
arrA=(a b c d e f)
arrB=(
a
b c
d
e
f
)
debug arr1 arr2 arrA arrB
sss=sss
debug sss
echo '--String--'
sss=sss
debug sss
ss1=ss1
ss2="ss2"
sStr="\"str\""
String ss3="ss3"
String ss3b=ss3b
String ss4b=$sStr
String ss4="$sStr"
debug ss1 ss2 ss3 ss3b ss4 ss4b
echo '--Objects--'
Map toto=( [id]= [velo]= [9]=9 )
Map vm=( [id]=111 [name]=dig-docker [status]=running )
aze=(toto titi tata)
declare -p aze
debug aze
echo 'laaa'
Object hyb ${aze[@]}
Array list=(aze qsd wxc)
debug list toto vm
echo '--Function arguments--'
my-func()
{
echo "brut($#): $@"
echo "brut: $1"
echo "brut: $2"
Object arg1=$1
declare -p arg1
arg1+=([rrr]=R [ttt]=T [yyy]=Y)
declare -p arg1
arg1+=([name]=NAME)
declare -p arg1
for a in "${!arg1[@]}"; do echo "elem: ${arg1[$a]}"; done
Array arg2=$2
declare -p arg2
arg2+=(rrr ttt yyy)
declare -p arg2
for a in "${!arg2[@]}"; do echo "elem: ${arg2[$a]}"; done
}
my-func "`exp vm`" "`exp aze`"
#if [ -t 1 ] ; then echo terminal; else echo "not a terminal"; fi
#returns "terminal", because the output is sent to your terminal, whereas
#(if [ -t 1 ] ; then echo terminal; else echo "not a terminal"; fi) | cat
[[ -t 1 ]] && is_piped="" || is_piped="yes"
#[[ -n $piped ]] && echo "will be piped"
#[[ -z $piped ]] && echo "will be printed directly"
array2map "(num* name status type)" "(111 dig-docker running KVM)"
model=(key* value)
array2map "`exp model`" "(active true)"
#alias VM='declare -A '
#VM vm_temp= "(111 dig-docker running KVM)"
sVM="111 dig-docker running KVM"
_VM 111 dig-docker running KVM
_VM $sVM
Map vm1=`_VM $sVM`
debug vm1
Object test=([key]=aze [value]=fooo)
#declare -A test=([key]=aze [value]=fooo)
debug test
echo looollo
sTest=`declare -p test`
list=(aze qsd "${sTest#*=}" wxc)
exp list
exp list[0]
exp list[2]
exp list[2].value
echo ho ho ho
toString()
{
printf "1) %s\n2) %s\n" $1 $2
local aze=(); local foo=(coucou monde)
echo "${foo[@]} !"
}
Map obj=(
[num]=1
[name]=bob
[status]=chill
[type]=KVN
[toString]='obj_toString()
{
Object this=$1
'"`declare -f toString | awk 'NR>1{print}'`;
obj_toString "
)
debug obj
#obj[arrmap]='{ Object this=$1; '"${obj[arrmap]#{};"'obj_arrmap '
echo "${obj[toString]}"
${obj[toString]}
echo "${obj[toString]} '([name]=toto)'"
eval "${obj[toString]} '([name]=toto)'"