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