OILS / spec / ysh-printing.test.sh View on Github | oilshell.org

128 lines, 40 significant
1# Pretty printing tests
2
3#### Int
4= -123
5## stdout: (Int) -123
6
7#### Float
8= -0.00
9## stdout: (Float) -0.0
10
11#### Null
12= null
13## stdout: (Null) null
14
15#### Bool
16= true
17= false
18## STDOUT:
19(Bool) true
20(Bool) false
21## END
22
23#### String
24= "double quoted"
25= 'single quoted'
26## STDOUT:
27(Str) "double quoted"
28(Str) "single quoted"
29## END
30
31#### Range
32var x = 1..100
33= x
34## stdout: (Range) 1 .. 100
35
36#### Bash Array
37declare -a array_0=()
38declare -a array_1=(hello)
39declare -a array_3
40array_3[0]="world"
41array_3[2]=*.py
42declare array_long=(Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
43do eiusmod.)
44= array_0
45= array_1
46= array_3
47= array_long
48## STDOUT:
49(BashArray) (BashArray)
50(BashArray) (BashArray 'hello')
51(BashArray) (BashArray 'world' null '*.py')
52(BashArray)
53(BashArray
54 'Lorem' 'ipsum' 'dolor' 'sit' 'amet,'
55 'consectetur' 'adipiscing' 'elit,' 'sed' 'do'
56 'eiusmod.'
57)
58## END
59
60#### Bash Assoc: string formatting
61declare -A assoc=(['k']=$'foo \x01\u03bc')
62= assoc
63## stdout: (BashAssoc) (BashAssoc ['k']=$'foo \u0001μ')
64
65#### Bash Assoc
66declare -A assoc_0=()
67declare -A assoc_1=([1]=one)
68declare assoc_3=([1]=one [two]=2 [3]=three)
69declare assoc_long=([Lorem]=ipsum [dolor]="sit amet," ['consectetur adipiscing']="elit, sed" [do]="eiusmod.")
70= assoc_0
71= assoc_1
72= assoc_3
73= assoc_long
74## STDOUT:
75(BashAssoc) (BashAssoc)
76(BashAssoc) (BashAssoc ['1']='one')
77(BashAssoc) (BashAssoc ['1']='one' ['two']='2' ['3']='three')
78(BashAssoc)
79(BashAssoc
80 ['Lorem']='ipsum'
81 ['dolor']='sit amet,'
82 ['consectetur adipiscing']='elit, sed'
83 ['do']='eiusmod.'
84)
85## END
86
87#### Simple Cycles
88var cyclic_array = ["one", "two", "three"]
89setvar cyclic_array[2] = cyclic_array
90var cyclic_dict = {"dead_end": null}
91setvar cyclic_dict["live_end"] = cyclic_dict
92= cyclic_array
93= cyclic_dict
94## STDOUT:
95(List) ["one", "two", [...]]
96(Dict) {dead_end: null, live_end: {...}}
97## END
98
99#### Complex Cycles
100var dict = {}
101setvar dict["nothing"] = null
102var simple_cycle = [["dummy"]]
103setvar simple_cycle[0][0] = simple_cycle
104setvar dict["simple_cycle"] = simple_cycle
105var tricky_cycle = ["dummy"]
106setvar tricky_cycle[0] = dict
107setvar dict["tricky_cycle"] = tricky_cycle
108var dag = [1, 2, "dummy"]
109setvar dag[2] = dag
110setvar dict["dag"] = [dag, dag]
111var alpha = {}
112var omega = {}
113setvar alpha["omega"] = omega
114setvar omega["alpha"] = alpha
115setvar dict["key_alpha"] = alpha
116setvar dict["key_omega"] = omega
117= dict
118## STDOUT:
119(Dict)
120{
121 nothing: null,
122 simple_cycle: [[[...]]],
123 tricky_cycle: [{...}],
124 dag: [[1, 2, [...]], [1, 2, [...]]],
125 key_alpha: {omega: {alpha: {...}}},
126 key_omega: {alpha: {omega: {...}}}
127}
128## END