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