arrays: add generic copy fn (#13677)

This commit is contained in:
Nick Treleaven 2022-03-08 07:44:04 +00:00 committed by GitHub
parent beb1b8ce1b
commit 17fcc788f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 2 deletions

View file

@ -264,3 +264,20 @@ fn test_rotate_left_string() {
rotate_left(mut x, 2)
assert x == ['x3', 'x4', 'x5', 'x6', 'x1', 'x2']
}
fn test_copy() {
mut a := [1, 2, 3]
mut b := [4, 5, 6]
assert copy(b, a) == 3
assert b == [1, 2, 3]
// check independent copies
b[0] = 99
assert a[0] == 1
// check longer src
b << 7
assert copy(a, b) == 3
assert a == [99, 2, 3]
// check longer dst
assert copy(b, [8, 9]) == 2
assert b == [8, 9, 3, 7]
}