Add List.extend and List.to_list, plus some more tests
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
51
tests/list.npp
Normal file
51
tests/list.npp
Normal file
@@ -0,0 +1,51 @@
|
||||
# List type operator and function tests
|
||||
|
||||
a = []
|
||||
|
||||
println("to_str")
|
||||
println(a.to_str())
|
||||
println([1, 2, 3])
|
||||
println(["a", "b", "c"])
|
||||
println(["a\nb\nc"])
|
||||
|
||||
println("push and pop")
|
||||
a.push(1234)
|
||||
a.push(56)
|
||||
println(a)
|
||||
println(a.pop())
|
||||
println(a)
|
||||
a.push(99)
|
||||
a.push(100)
|
||||
println(a)
|
||||
a.pop()
|
||||
a.pop()
|
||||
a.push('99')
|
||||
a.push('100')
|
||||
println(a)
|
||||
|
||||
println("len")
|
||||
println(a.len())
|
||||
a.pop()
|
||||
println(a.len())
|
||||
a.pop()
|
||||
println(a.len())
|
||||
a.pop()
|
||||
println(a.len())
|
||||
|
||||
println("extend")
|
||||
a.extend([1, 2, 3])
|
||||
println(a)
|
||||
a.extend([1, 2, 3])
|
||||
println(a)
|
||||
a.extend(['a', 's', 'd', 'f'])
|
||||
println(a)
|
||||
|
||||
println("constructor")
|
||||
println(List("asdf"))
|
||||
println(List([1, 2, 3]))
|
||||
# ensure that creating a new list actually clones it
|
||||
b = [1, 2, 3]
|
||||
c = List(b)
|
||||
c.pop()
|
||||
println(b)
|
||||
println(c)
|
||||
25
tests/list.npp.expect
Normal file
25
tests/list.npp.expect
Normal file
@@ -0,0 +1,25 @@
|
||||
to_str
|
||||
[]
|
||||
[1, 2, 3]
|
||||
['a', 'b', 'c']
|
||||
['a\nb\nc']
|
||||
push and pop
|
||||
[1234, 56]
|
||||
56
|
||||
[1234]
|
||||
[1234, 99, 100]
|
||||
[1234, '99', '100']
|
||||
len
|
||||
3
|
||||
2
|
||||
1
|
||||
0
|
||||
extend
|
||||
[1, 2, 3]
|
||||
[1, 2, 3, 1, 2, 3]
|
||||
[1, 2, 3, 1, 2, 3, 'a', 's', 'd', 'f']
|
||||
constructor
|
||||
['a', 's', 'd', 'f']
|
||||
[1, 2, 3]
|
||||
[1, 2, 3]
|
||||
[1, 2]
|
||||
Reference in New Issue
Block a user