1 | ## our_shell: ysh
|
2 |
|
3 | #### join()
|
4 | var x = :|a b 'c d'|
|
5 |
|
6 | var y = join(x)
|
7 | argv.py $y
|
8 |
|
9 | var z = join(x, ":")
|
10 | argv.py $z
|
11 | ## STDOUT:
|
12 | ['abc d']
|
13 | ['a:b:c d']
|
14 | ## END
|
15 |
|
16 | #### abs
|
17 |
|
18 | source $LIB_YSH/math.ysh
|
19 |
|
20 | # Also test smooshing
|
21 | write $[abs(-5)]$[abs(-0)]$[abs(5)]
|
22 | write $[abs(-5)] $[abs(-0)] $[abs(5)]
|
23 | ## STDOUT:
|
24 | 505
|
25 | 5
|
26 | 0
|
27 | 5
|
28 | ## END
|
29 |
|
30 | #### any() and all()
|
31 | source $LIB_YSH/list.ysh
|
32 |
|
33 | var a1 = all( :|yes yes| )
|
34 | var a2 = all( :|yes ''| )
|
35 | var a3 = all( :|'' ''| )
|
36 | # This should be true and false or what?
|
37 | write $a1 $a2 $a3
|
38 | write __
|
39 |
|
40 | var x1 = any( :|yes yes| )
|
41 | var x2 = any( :|yes ''| )
|
42 | var x3 = any( :|'' ''| )
|
43 | write $x1 $x2 $x3
|
44 |
|
45 | ## STDOUT:
|
46 | true
|
47 | false
|
48 | false
|
49 | __
|
50 | true
|
51 | true
|
52 | false
|
53 | ## END
|
54 |
|
55 | #### sum()
|
56 | source $LIB_YSH/list.ysh
|
57 |
|
58 | var start = 42
|
59 |
|
60 | write $[sum( 0 .. 3 )]
|
61 | write $[sum( 0 .. 3; start=42)]
|
62 | write $[sum( 0 .. 0, start=42)]
|
63 |
|
64 | ## STDOUT:
|
65 | 3
|
66 | 45
|
67 | 42
|
68 | ## END
|
69 |
|
70 | #### @[split(x)] respects IFS
|
71 | setvar IFS = ":"
|
72 | var x = "one:two:three"
|
73 | argv.py @[split(x)]
|
74 | ## STDOUT:
|
75 | ['one', 'two', 'three']
|
76 | ## END
|
77 |
|
78 | #### @[maybe(x)]
|
79 | setvar empty = ''
|
80 | setvar x = 'X'
|
81 | argv.py a @[maybe(empty)] @[maybe(x)] b
|
82 |
|
83 | setvar n = null
|
84 | argv.py a @[maybe(n)] b
|
85 |
|
86 | ## STDOUT:
|
87 | ['a', 'X', 'b']
|
88 | ['a', 'b']
|
89 | ## END
|
90 |
|
91 | #### maybe() on invalid type is fatal error
|
92 |
|
93 | # not allowed
|
94 | setvar marray = :||
|
95 | argv.py a @[maybe(marray)] b
|
96 | echo done
|
97 | ## status: 3
|
98 | ## STDOUT:
|
99 | ## END
|
100 |
|
101 | #### split() on invalid type is fatal error
|
102 | var myarray = :| --all --long |
|
103 | write -- @[myarray]
|
104 | write -- @[split(myarray)]
|
105 | ## status: 3
|
106 | ## STDOUT:
|
107 | --all
|
108 | --long
|
109 | ## END
|
110 |
|
111 | #### @[glob(x)]
|
112 |
|
113 | # empty glob
|
114 | write -- A @[glob('__nope__')] B
|
115 | echo ___
|
116 |
|
117 | touch -- a.z b.z -.z
|
118 | write -- @[glob('?.z')]
|
119 | echo ___
|
120 |
|
121 | # add it back
|
122 | shopt -s dashglob
|
123 | write -- @[glob('?.z')]
|
124 |
|
125 | ## STDOUT:
|
126 | A
|
127 | B
|
128 | ___
|
129 | a.z
|
130 | b.z
|
131 | ___
|
132 | -.z
|
133 | a.z
|
134 | b.z
|
135 | ## END
|
136 |
|
137 | #### smoke test for two.sh
|
138 |
|
139 | source --builtin osh/two.sh
|
140 |
|
141 | log 'hi'
|
142 |
|
143 | set +o errexit
|
144 | ( die "bad" )
|
145 | echo status=$?
|
146 |
|
147 | ## STDOUT:
|
148 | status=1
|
149 | ## END
|
150 |
|
151 | #### smoke test for stream.ysh and table.ysh
|
152 |
|
153 | shopt --set redefine_proc_func # byo-maybe-main
|
154 |
|
155 | source $LIB_YSH/stream.ysh
|
156 | source $LIB_YSH/table.ysh
|
157 |
|
158 | ## status: 0
|