OILS / spec / ysh-user-feedback.test.sh View on Github | oilshell.org

141 lines, 71 significant
1## our_shell: ysh
2
3#### !== operator
4var a = 'bar'
5
6if (a !== 'foo') {
7 echo 'not equal'
8}
9
10if (a !== 'bar') {
11 echo 'should not get here'
12}
13
14# NOTE: a !== foo is idiomatic)
15if ("$a" !== 'bar') {
16 echo 'should not get here'
17}
18
19## STDOUT:
20not equal
21## END
22
23
24#### elif bug
25if (true) {
26 echo A
27} elif (true) {
28 echo B
29} elif (true) {
30 echo C
31} else {
32 echo else
33}
34## STDOUT:
35A
36## END
37
38#### global vars
39builtin set -u
40
41main() {
42 source $REPO_ROOT/spec/testdata/global-lib.sh
43}
44
45main
46test_func
47
48## status: 1
49## STDOUT:
50## END
51
52#### Julia port
53
54$SH $REPO_ROOT/spec/testdata/ysh-user-feedback.sh
55
56## STDOUT:
57git
58branch
59-D
60foo
61baz
62___
63foo
64baz
65## END
66
67#### readonly in loop: explains why const doesn't work
68
69# TODO: Might want to change const in Oil...
70# bash actually prevents assignment and prints a warning, DOH.
71
72seq 3 | while read -r line; do
73 readonly stripped=${line//1/x}
74 #declare stripped=${line//1/x}
75 echo $stripped
76done
77## status: 1
78## STDOUT:
79x
80## END
81
82
83#### Eggex bug in a loop
84
85# https://oilshell.zulipchat.com/#narrow/stream/121540-oil-discuss/topic/A.20list.20of.20feedback
86for 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:
94yes
95yes
96## END
97
98
99#### Append object onto Array
100var 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
106for 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
115json write (e)
116
117## STDOUT:
118[
119 {
120 "1": "Test 1"
121 },
122 {
123 "2": "Test 2"
124 }
125]
126## END
127
128#### Invalid op on string
129shopt -s oil:all
130
131var clients = {'email': 'foo', 'e2': 'bar'}
132for 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:
140email
141## END