builtin: implement array.pop()

This commit is contained in:
Delyan Angelov 2020-07-14 19:55:44 +03:00
parent de0b96f52c
commit cf7d03bda6
4 changed files with 50 additions and 4 deletions

View file

@ -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
}