mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: implement array.pop()
This commit is contained in:
@@ -946,3 +946,29 @@ fn test_reverse_in_place() {
|
||||
c.reverse_in_place()
|
||||
assert c == [[5, 6], [3, 4], [1, 2]]
|
||||
}
|
||||
|
||||
fn test_array_int_pop() {
|
||||
mut a := [1,2,3,4,5]
|
||||
assert a.len == 5
|
||||
x := a.last()
|
||||
y := a.pop()
|
||||
assert x == y
|
||||
assert a.len == 4
|
||||
z := a.pop()
|
||||
assert a.len == 3
|
||||
assert z == 4
|
||||
a.pop()
|
||||
a.pop()
|
||||
final := a.pop()
|
||||
assert final == 1
|
||||
}
|
||||
|
||||
fn test_array_string_pop() {
|
||||
mut a := ['abc', 'def', 'xyz']
|
||||
assert a.len == 3
|
||||
assert a.pop() == 'xyz'
|
||||
assert a.pop() == 'def'
|
||||
assert a.pop() == 'abc'
|
||||
assert a.len == 0
|
||||
assert a.cap == 3
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user