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

129 lines, 58 significant
1## oils_failures_allowed: 1
2
3#### pp asdl
4
5shopt -s ysh:upgrade
6
7fopen >out.txt {
8 x=42
9 setvar y = {foo: x}
10
11 pp asdl (x)
12 pp asdl (y)
13
14 # TODO, this might be nice?
15 # pp asdl (x, y)
16}
17
18# Two lines with value.Str
19grep -n -o value.Str out.txt
20
21# Dict should have an address
22#grep -n -o 'Dict 0x' out.txt
23
24#cat out.txt
25
26## STDOUT:
271:value.Str
282:value.Str
29## END
30
31#### pp asdl can handle an object cycle
32
33shopt -s ysh:upgrade
34
35var d = {}
36setvar d.cycle = d
37
38pp line (d) | fgrep -o '{"cycle":'
39
40pp asdl (d) | fgrep -o 'cycle ...'
41
42## STDOUT:
43{"cycle":
44cycle ...
45## END
46
47#### pp line supports BashArray, BashAssoc
48
49declare -a array=(a b c)
50pp line (array)
51
52array[5]=z
53pp line (array)
54
55declare -A assoc=([k]=v [k2]=v2)
56pp line (assoc)
57
58# I think assoc arrays can never null / unset
59
60assoc['k3']=
61pp line (assoc)
62
63## STDOUT:
64(BashArray) ["a","b","c"]
65(BashArray) ["a","b","c",null,null,"z"]
66(BashAssoc) {"k":"v","k2":"v2"}
67(BashAssoc) {"k":"v","k2":"v2","k3":""}
68## END
69
70
71#### pp gc-stats
72
73pp gc-stats
74
75## STDOUT:
76## END
77
78
79#### pp cell
80x=42
81
82pp cell x
83echo status=$?
84
85pp -- cell :x
86echo status=$?
87
88pp cell nonexistent
89echo status=$?
90## STDOUT:
91x = (Cell exported:F readonly:F nameref:F val:(value.Str s:42))
92status=0
93x = (Cell exported:F readonly:F nameref:F val:(value.Str s:42))
94status=0
95status=1
96## END
97
98#### pp cell on indexed array with hole
99declare -a array
100array[3]=42
101pp cell array
102## STDOUT:
103array = (Cell exported:F readonly:F nameref:F val:(value.BashArray strs:[_ _ _ 42]))
104## END
105
106
107#### pp proc
108shopt --set ysh:upgrade
109
110# This has to be a separate file because sh_spec.py strips comments!
111. $REPO_ROOT/spec/testdata/doc-comments.sh
112
113pp proc
114echo ---
115
116# print one
117pp proc f
118
119## STDOUT:
120proc_name doc_comment
121f "doc ' comment with \" quotes"
122g ""
123myproc "YSH-style proc"
124"true" "Special quoting rule"
125---
126proc_name doc_comment
127f "doc ' comment with \" quotes"
128## END
129