OILS / spec / ysh-TODO-deprecate.test.sh View on Github | oils.pub

184 lines, 89 significant
1# TODO-deprecate: Code we want to get rid of!
2
3
4#### oil:upgrade as alias for ysh:upgrade
5
6shopt -p | grep simple_word
7shopt --set oil:upgrade
8shopt -p | grep simple_word
9
10shopt --unset ysh:upgrade
11shopt -p | grep simple_word
12
13## STDOUT:
14shopt -u simple_word_eval
15shopt -s simple_word_eval
16shopt -u simple_word_eval
17## END
18
19
20#### %() array literal
21
22shopt --set parse_at
23
24var x = %(one two)
25echo @x
26
27## STDOUT:
28one two
29## END
30
31#### _match() instead of _group()
32
33shopt --set ysh:upgrade
34
35if ('foo42' ~ / <capture d+> /) {
36 echo $[_match(0)]
37 echo $[_group(0)]
38}
39
40## STDOUT:
4142
4242
43## END
44
45#### _status instead of _error.code
46
47shopt --set ysh:upgrade
48
49f() {
50 return 42
51}
52
53try {
54 f
55}
56echo status=$_status
57
58## STDOUT:
59status=42
60## END
61
62
63#### source ///osh/two.sh rather than source --builtin osh/two.sh
64
65source --builtin osh/two.sh
66echo status=$?
67
68## STDOUT:
69status=0
70## END
71
72#### OILS_VERSION, not OIL_VERSION
73
74if test -n "$OIL_VERSION"; then
75 echo OIL
76fi
77
78## STDOUT:
79OIL
80## END
81
82#### s.upper(), not s => upper() (might keep this)
83
84shopt --set parse_subexpr_shorthand
85
86echo $['foo' => upper()]
87
88## STDOUT:
89FOO
90## END
91
92#### fopen can be spelled redir
93shopt --set ysh:upgrade
94
95fopen >out {
96 echo 1
97 echo 2
98}
99
100tac out
101
102## STDOUT:
1032
1041
105## END
106
107
108#### Dict => keys()
109var en2fr = {}
110setvar en2fr["hello"] = "bonjour"
111setvar en2fr["friend"] = "ami"
112setvar en2fr["cat"] = "chat"
113pp test_ (en2fr => keys())
114## status: 0
115## STDOUT:
116(List) ["hello","friend","cat"]
117## END
118
119
120#### Obj API
121shopt --set ysh:upgrade
122
123try {
124 var obj = Object(null, {x: 4})
125 pp test_ (obj)
126}
127echo $[_error.code]
128
129try {
130 pp test_ (propView(obj))
131}
132echo $[_error.code]
133
134try {
135 pp test_ (prototype(obj))
136}
137echo $[_error.code]
138
139## STDOUT:
140(Obj) ("x":4)
1410
142(Dict) {"x":4}
1430
144(Null) null
1450
146## END
147
148#### evalInFrame() and evalToDict()
149
150var cmd = ^(echo hi)
151
152call io->evalInFrame(cmd, vm.getFrame(-1))
153
154var d = io->evalToDict(cmd)
155pp test_ (d)
156
157## STDOUT:
158hi
159hi
160(Dict) {}
161## END
162
163#### YSH case requires ''/dir/*.py workaround
164
165shopt --set ysh:all
166
167case ('/usr/bin/') {
168 ''/usr/* { echo yes }
169 (else) { echo no }
170}
171## STDOUT:
172yes
173## END
174
175#### \x7e was the legacy syntax for \y7e
176
177pp test_ ('~' ~ / [\x7e] /) # should be INVALID
178
179pp test_ ('~' ~ / [\y7e] /)
180
181## STDOUT:
182(Bool) true
183(Bool) true
184## END