1 |
## our_shell: ysh
|
2 |
|
3 |
|
4 |
var a = 'bar'
|
5 |
|
6 |
if (a !== 'foo') {
|
7 |
echo 'not equal'
|
8 |
}
|
9 |
|
10 |
if (a !== 'bar') {
|
11 |
echo 'should not get here'
|
12 |
}
|
13 |
|
14 |
# NOTE: a !== foo is idiomatic)
|
15 |
if ("$a" !== 'bar') {
|
16 |
echo 'should not get here'
|
17 |
}
|
18 |
|
19 |
## STDOUT:
|
20 |
not equal
|
21 |
## END
|
22 |
|
23 |
|
24 |
|
25 |
if (true) {
|
26 |
echo A
|
27 |
} elif (true) {
|
28 |
echo B
|
29 |
} elif (true) {
|
30 |
echo C
|
31 |
} else {
|
32 |
echo else
|
33 |
}
|
34 |
## STDOUT:
|
35 |
A
|
36 |
## END
|
37 |
|
38 |
|
39 |
builtin set -u
|
40 |
|
41 |
main() {
|
42 |
source $[ENV.REPO_ROOT]/spec/testdata/global-lib.sh
|
43 |
}
|
44 |
|
45 |
main
|
46 |
test_func
|
47 |
|
48 |
## status: 1
|
49 |
## STDOUT:
|
50 |
## END
|
51 |
|
52 |
|
53 |
|
54 |
$[ENV.SH] $[ENV.REPO_ROOT]/spec/testdata/ysh-user-feedback.sh
|
55 |
|
56 |
## STDOUT:
|
57 |
git
|
58 |
branch
|
59 |
-D
|
60 |
foo
|
61 |
baz
|
62 |
___
|
63 |
foo
|
64 |
baz
|
65 |
## END
|
66 |
|
67 |
|
68 |
|
69 |
# TODO: Might want to change const in Oil...
|
70 |
# bash actually prevents assignment and prints a warning, DOH.
|
71 |
|
72 |
seq 3 | while read -r line; do
|
73 |
readonly stripped=${line//1/x}
|
74 |
#declare stripped=${line//1/x}
|
75 |
echo $stripped
|
76 |
done
|
77 |
## status: 1
|
78 |
## STDOUT:
|
79 |
x
|
80 |
## END
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
# https://oilshell.zulipchat.com/#narrow/stream/121540-oil-discuss/topic/A.20list.20of.20feedback
|
86 |
for i in @(seq 2) {
|
87 |
# BUG: This crashes here, but NOT when extracted! Bad.
|
88 |
var pat = / 'test' word+ /
|
89 |
if ("test$i" ~ pat) {
|
90 |
echo yes
|
91 |
}
|
92 |
}
|
93 |
## STDOUT:
|
94 |
yes
|
95 |
yes
|
96 |
## END
|
97 |
|
98 |
|
99 |
|
100 |
var e = []
|
101 |
|
102 |
# %() is also acceptable, but we prefer Python-like [] for objects.
|
103 |
# %() is more for an array of strings
|
104 |
# var e = %()
|
105 |
|
106 |
for i in @(seq 2) {
|
107 |
var o = {}
|
108 |
setvar o[i] = "Test $i"
|
109 |
|
110 |
# push builtin is only for strings
|
111 |
|
112 |
call e->append(o)
|
113 |
}
|
114 |
|
115 |
json write (e)
|
116 |
|
117 |
## STDOUT:
|
118 |
[
|
119 |
{
|
120 |
"1": "Test 1"
|
121 |
},
|
122 |
{
|
123 |
"2": "Test 2"
|
124 |
}
|
125 |
]
|
126 |
## END
|
127 |
|
128 |
|
129 |
shopt -s oil:all
|
130 |
|
131 |
var clients = {'email': 'foo', 'e2': 'bar'}
|
132 |
for c in (clients) {
|
133 |
echo $c
|
134 |
# A user tickled this. I think this should make the whole 'const' line fail
|
135 |
# with code 1 or 2?
|
136 |
const e = c.email
|
137 |
}
|
138 |
## status: 3
|
139 |
## STDOUT:
|
140 |
email
|
141 |
## END
|