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

97 lines, 48 significant
1## our_shell: ysh
2## oils_failures_allowed: 0
3
4#### basic array
5var x = :| 1 2 3 |
6write len=$[len(x)]
7## STDOUT:
8len=3
9## END
10
11#### string array with command sub, varsub, etc.
12shopt -s ysh:all
13
14var x = 1
15var a = :| $x $(write hi) 'sq' "dq $x" |
16write len=$[len(a)]
17write @a
18## STDOUT:
19len=4
201
21hi
22sq
23dq 1
24## END
25
26#### Can print type of List with pp
27
28var b = :|true| # this is a string
29pp line (b)
30
31# = b
32
33var empty = :||
34pp line (empty)
35
36# = empty
37
38## STDOUT:
39(List) ["true"]
40(List) []
41## END
42
43#### splice and stringify array
44
45shopt -s parse_at
46
47var x = :| 'a b' c |
48
49declare -a array=( @x )
50
51argv.py "${array[@]}" # should work
52
53echo -$array- # fails because of strict_arraywith type error
54
55echo -$x- # fails with type error
56
57## status: 1
58## STDOUT:
59['a b', 'c']
60## END
61
62#### List->extend()
63var l = list(1..3)
64echo $[len(l)]
65call l->extend(list(3..6))
66echo $[len(l)]
67## STDOUT:
682
695
70## END
71
72#### List append()/extend() should return null
73shopt -s ysh:all
74var l = list(1..3)
75
76var result = l->extend(list(3..6))
77assert [null === result]
78
79setvar result = l->append(6)
80assert [null === result]
81
82echo pass
83## STDOUT:
84pass
85## END
86
87#### List pop()
88shopt -s ysh:all
89var l = list(1..5)
90assert [4 === l->pop()]
91assert [3 === l->pop()]
92assert [2 === l->pop()]
93assert [1 === l->pop()]
94echo pass
95## STDOUT:
96pass
97## END