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

145 lines, 65 significant
1## oils_failures_allowed: 1
2
3#### Splice in array
4shopt -s oil: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 oil:upgrade
34var mystr = 'abc'
35argv.py @mystr
36## status: 3
37## stdout-json: ""
38
39#### Can't splice undefined
40shopt -s oil:upgrade
41argv.py @undefined
42echo done
43## status: 3
44## stdout-json: ""
45
46#### echo $[f(x)] for various types
47shopt -s oil:upgrade
48
49source --builtin funcs.ysh
50source $LIB_YSH/math.ysh
51
52echo bool $[identity(true)]
53echo int $[len(['a', 'b'])]
54echo float $[abs(-3.14)] # FIXME: this causes issues with float vs. int comparison
55echo str $[identity('identity')]
56
57echo ---
58echo bool expr $[true]
59echo bool splice @[identity([true])]
60
61## STDOUT:
62bool true
63int 2
64float 3.14
65str identity
66---
67bool expr true
68bool splice true
69## END
70
71#### echo $f (x) with space is runtime error
72shopt -s oil:upgrade
73
74source --builtin funcs.ysh
75
76echo $identity (true)
77## status: 3
78## STDOUT:
79## END
80
81#### echo @f (x) with space is runtime error
82shopt -s oil:upgrade
83
84source --builtin funcs.ysh
85
86echo @identity (['foo', 'bar'])
87## status: 3
88## STDOUT:
89## END
90
91#### echo $x for various types
92const mybool = true
93const myint = 42
94const myfloat = 3.14
95
96echo $mybool
97echo $myint
98echo $myfloat
99
100## STDOUT:
101true
10242
1033.14
104## END
105
106#### Wrong sigil with $range() is runtime error
107shopt -s oil:upgrade
108echo $[10 .. 15]
109echo 'should not get here'
110## status: 3
111## STDOUT:
112## END
113
114#### Serializing type in a list
115shopt -s oil:upgrade
116
117# If you can serialize the above, then why this?
118var mylist = [3, true]
119
120write -- @mylist
121
122write -- ___
123
124var list2 = [List]
125write -- @list2
126
127## status: 3
128## STDOUT:
1293
130true
131___
132## END
133
134#### Wrong sigil @[max(3, 4)]
135shopt -s oil:upgrade
136
137source $LIB_YSH/math.ysh
138
139write @[max(3, 4)]
140echo 'should not get here'
141## status: 3
142## STDOUT:
143## END
144
145