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

144 lines, 64 significant
1## oils_failures_allowed: 1
2
3#### Splice in array
4shopt -s ysh:upgrade
5var a = %(one two three)
6argv.py @a
7## STDOUT:
8['one', 'two', 'three']
9## END
10
11#### Assoc array can't be spliced directly
12
13shopt -s ysh:upgrade
14declare -A A=(['foo']=bar ['spam']=eggs)
15
16# Bash behavior is to splice values
17write -- "${A[@]}"
18
19write -- @A
20echo 'should not get here'
21
22# These should eventually work
23#write -- @[A->keys()]
24#write -- @[A->values()]
25
26## status: 3
27## STDOUT:
28bar
29eggs
30## END
31
32#### Can't splice string
33shopt -s ysh:upgrade
34var mystr = 'abc'
35argv.py @mystr
36## status: 3
37## stdout-json: ""
38
39#### Can't splice undefined
40shopt -s ysh:upgrade
41argv.py @undefined
42echo done
43## status: 3
44## stdout-json: ""
45
46#### echo $[f(x)] for various types
47shopt --set ysh:upgrade
48
49source $LIB_YSH/math.ysh
50
51echo bool $[identity(true)]
52echo int $[len(['a', 'b'])]
53echo float $[abs(-3.14)] # FIXME: this causes issues with float vs. int comparison
54echo str $[identity('identity')]
55
56echo ---
57echo bool expr $[true]
58echo bool splice @[identity([true])]
59
60## STDOUT:
61bool true
62int 2
63float 3.14
64str identity
65---
66bool expr true
67bool splice true
68## END
69
70#### echo $f (x) with space is runtime error
71shopt -s ysh:upgrade
72
73source $LIB_YSH/math.ysh
74
75echo $identity (true)
76## status: 3
77## STDOUT:
78## END
79
80#### echo @f (x) with space is runtime error
81shopt -s ysh:upgrade
82
83source $LIB_YSH/math.ysh
84
85echo @identity (['foo', 'bar'])
86## status: 3
87## STDOUT:
88## END
89
90#### echo $x for various types
91const mybool = true
92const myint = 42
93const myfloat = 3.14
94
95echo $mybool
96echo $myint
97echo $myfloat
98
99## STDOUT:
100true
10142
1023.14
103## END
104
105#### Wrong sigil with $range() is runtime error
106shopt -s ysh:upgrade
107echo $[10 ..< 15]
108echo 'should not get here'
109## status: 3
110## STDOUT:
111## END
112
113#### Serializing type in a list
114shopt -s ysh:upgrade
115
116# If you can serialize the above, then why this?
117var mylist = [3, true]
118
119write -- @mylist
120
121write -- ___
122
123var list2 = [List]
124write -- @list2
125
126## status: 3
127## STDOUT:
1283
129true
130___
131## END
132
133#### Wrong sigil @[max(3, 4)]
134shopt -s ysh:upgrade
135
136source $LIB_YSH/math.ysh
137
138write @[max(3, 4)]
139echo 'should not get here'
140## status: 3
141## STDOUT:
142## END
143
144