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