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

138 lines, 44 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#### Eggex (reference type)
37var pat = /d+/
38pp (pat) | sed 's/0x[0-9a-f]\+/0x---/'
39
40# TODO: change this
41
42## STDOUT:
43(Eggex) <Eggex 0x--->
44## END
45
46#### Bash Array
47declare -a array_0=()
48declare -a array_1=(hello)
49declare -a array_3
50array_3[0]="world"
51array_3[2]=*.py
52declare array_long=(Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
53do eiusmod.)
54= array_0
55= array_1
56= array_3
57= array_long
58## STDOUT:
59(BashArray) (BashArray)
60(BashArray) (BashArray 'hello')
61(BashArray) (BashArray 'world' null '*.py')
62(BashArray)
63(BashArray
64 'Lorem' 'ipsum' 'dolor' 'sit' 'amet,'
65 'consectetur' 'adipiscing' 'elit,' 'sed' 'do'
66 'eiusmod.'
67)
68## END
69
70#### Bash Assoc: string formatting
71declare -A assoc=(['k']=$'foo \x01\u03bc')
72= assoc
73## stdout: (BashAssoc) (BashAssoc ['k']=$'foo \u0001μ')
74
75#### Bash Assoc
76declare -A assoc_0=()
77declare -A assoc_1=([1]=one)
78declare assoc_3=([1]=one [two]=2 [3]=three)
79declare assoc_long=([Lorem]=ipsum [dolor]="sit amet," ['consectetur adipiscing']="elit, sed" [do]="eiusmod.")
80= assoc_0
81= assoc_1
82= assoc_3
83= assoc_long
84## STDOUT:
85(BashAssoc) (BashAssoc)
86(BashAssoc) (BashAssoc ['1']='one')
87(BashAssoc) (BashAssoc ['1']='one' ['two']='2' ['3']='three')
88(BashAssoc)
89(BashAssoc
90 ['Lorem']='ipsum'
91 ['dolor']='sit amet,'
92 ['consectetur adipiscing']='elit, sed'
93 ['do']='eiusmod.'
94)
95## END
96
97#### Simple Cycles
98var cyclic_array = ["one", "two", "three"]
99setvar cyclic_array[2] = cyclic_array
100var cyclic_dict = {"dead_end": null}
101setvar cyclic_dict["live_end"] = cyclic_dict
102= cyclic_array
103= cyclic_dict
104## STDOUT:
105(List) ['one', 'two', [...]]
106(Dict) {dead_end: null, live_end: {...}}
107## END
108
109#### Complex Cycles
110var dict = {}
111setvar dict["nothing"] = null
112var simple_cycle = [["dummy"]]
113setvar simple_cycle[0][0] = simple_cycle
114setvar dict["simple_cycle"] = simple_cycle
115var tricky_cycle = ["dummy"]
116setvar tricky_cycle[0] = dict
117setvar dict["tricky_cycle"] = tricky_cycle
118var dag = [1, 2, "dummy"]
119setvar dag[2] = dag
120setvar dict["dag"] = [dag, dag]
121var alpha = {}
122var omega = {}
123setvar alpha["omega"] = omega
124setvar omega["alpha"] = alpha
125setvar dict["key_alpha"] = alpha
126setvar dict["key_omega"] = omega
127= dict
128## STDOUT:
129(Dict)
130{
131 nothing: null,
132 simple_cycle: [[[...]]],
133 tricky_cycle: [{...}],
134 dag: [[1, 2, [...]], [1, 2, [...]]],
135 key_alpha: {omega: {alpha: {...}}},
136 key_omega: {alpha: {omega: {...}}}
137}
138## END