OILS / spec / ysh-func-builtin.test.sh View on Github | oilshell.org

103 lines, 53 significant
1## oils_failures_allowed: 1
2## our_shell: ysh
3
4#### shSplit() respects IFS
5
6var s = ' aa a bb b '
7
8argv.py @[shSplit(s)]
9
10setvar IFS = 'a'
11
12argv.py @[shSplit(s)]
13
14setvar IFS = 'b'
15
16argv.py @[shSplit(s)]
17
18## STDOUT:
19['aa', 'a', 'bb', 'b']
20[' ', '', ' ', ' bb b ']
21[' aa a ', '', ' ', ' ']
22## END
23
24
25#### getVar() gets global or local vars
26
27# compare with shvarGet(), which does dynamic scope
28
29proc my-proc {
30 var mylocal = 43
31
32 echo g=$[getVar('g')]
33 echo mylocal=$[getVar('mylocal')]
34
35 # the whole purpose is dynamic variable names / dynamic binding
36 var prefix = 'my'
37 echo mylocal=$[getVar(prefix ++ 'local')]
38
39 echo not_global_or_local=$[getVar('not_global_or_local')]
40}
41
42proc main {
43 var not_global_or_local = 42
44 my-proc
45}
46
47var g = 'global'
48
49main
50
51## STDOUT:
52g=global
53mylocal=43
54mylocal=43
55not_global_or_local=null
56## END
57
58#### ASCII upper() lower()
59
60var x = 'abc-'
61var y = 'XYZ!'
62
63echo $x
64echo $y
65echo
66
67echo $[x => upper()]
68echo $[x => lower()]
69echo $[y => upper()]
70echo $[y => lower()]
71
72## STDOUT:
73abc-
74XYZ!
75
76ABC-
77abc-
78XYZ!
79xyz!
80## END
81
82#### Unicode upper() lower()
83
84# Adapted from spec/var-op-bash
85
86# https://www.utf8-chartable.de/unicode-utf8-table.pl
87
88var x = u'\u{C0}\u{C8}' # upper grave
89var y = u'\u{E1}\u{E9}' # lower acute
90
91echo $x
92echo $y
93echo
94
95echo $[x => upper()]
96echo $[x => lower()]
97echo $[y => upper()]
98echo $[y => lower()]
99
100## STDOUT:
101ÀÈ
102áé
103## END