mirror of
https://github.com/vlang/v.git
synced 2025-09-14 15:02:33 +03:00
builtin: implement array.pop()
This commit is contained in:
parent
de0b96f52c
commit
cf7d03bda6
4 changed files with 50 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue