1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: [direct_array_access] tag (#6203)

This commit is contained in:
Maciej Obarski
2020-08-24 09:04:50 +02:00
committed by GitHub
parent 6a0cb3e552
commit e8e0d9fa42
5 changed files with 144 additions and 65 deletions

View File

@@ -1001,3 +1001,34 @@ fn test_array_string_pop() {
assert a.len == 0
assert a.cap == 3
}
[direct_array_access]
fn test_direct_array_access() {
mut a := [11,22,33,44]
assert a[0] == 11
assert a[2] == 33
x := a[0]
a[0] = 21
a[1] += 2
a[2] = x + 3
a[3] -= a[1]
assert a == [21, 24, 14, 20]
}
[direct_array_access]
fn test_direct_array_access_via_ptr() {
mut b := [11,22,33,44]
unsafe {
mut a := &b
assert a[0] == 11
assert a[2] == 33
x := a[0]
a[0] = 21
a[1] += 2
a[2] = x + 3
a[3] -= a[1]
assert a == [21, 24, 14, 20]
}
}