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