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

160 lines, 108 significant
1# spec/ysh-stdlib
2
3## our_shell: ysh
4
5#### identity
6source --builtin funcs.ysh
7
8for x in (['a', 1, null, { foo: 'bar' }, [40, 2]]) {
9 json write (identity(x))
10}
11
12## STDOUT:
13"a"
141
15null
16{
17 "foo": "bar"
18}
19[
20 40,
21 2
22]
23## END
24
25#### max
26source --builtin math.ysh
27
28json write (max(1, 2))
29json write (max([1, 2, 3]))
30
31try { call max([]) }
32echo status=$_status
33
34try { call max(1, 2) }
35echo status=$_status
36
37try { call max(1, 2, 3) }
38echo status=$_status
39
40try { call max() }
41echo status=$_status
42
43## STDOUT:
442
453
46status=3
47status=0
48status=3
49status=3
50## END
51
52#### min
53source --builtin math.ysh
54
55json write (min(2, 3))
56json write (min([1, 2, 3]))
57
58try { call min([]) }
59echo status=$_status
60
61try { call min(2, 3) }
62echo status=$_status
63
64try { call min(1, 2, 3) }
65echo status=$_status
66
67try { call min() }
68echo status=$_status
69
70## STDOUT:
712
721
73status=3
74status=0
75status=3
76status=3
77## END
78
79#### abs
80source --builtin math.ysh
81
82json write (abs(-1))
83json write (abs(0))
84json write (abs(1))
85json write (abs(42))
86json write (abs(-42))
87
88try { call abs(-42) }
89echo status=$_status
90
91## STDOUT:
921
930
941
9542
9642
97status=0
98## END
99
100#### any
101source --builtin list.ysh
102
103json write (any([]))
104json write (any([true]))
105json write (any([false]))
106json write (any([true, false]))
107json write (any([false, true]))
108json write (any([false, false]))
109json write (any([false, true, false]))
110json write (any([false, false, null, ""])) # null and "" are falsey
111json write (any(["foo"])) # "foo" is truthy
112## STDOUT:
113false
114true
115false
116true
117true
118false
119true
120false
121true
122## END
123
124#### all
125source --builtin list.ysh
126
127json write (all([]))
128json write (all([true]))
129json write (all([false]))
130json write (all([true, true]))
131json write (all([true, false]))
132json write (all([false, true]))
133json write (all([false, false]))
134json write (all([false, true, false]))
135json write (all(["foo"]))
136json write (all([""]))
137## STDOUT:
138true
139true
140false
141true
142false
143false
144false
145false
146true
147false
148## END
149
150#### sum
151source --builtin list.ysh
152
153json write (sum([]))
154json write (sum([0]))
155json write (sum([1, 2, 3]))
156## STDOUT:
1570
1580
1596
160## END