tests: split unsafe.v to vlib/v/tests/unsafe_test.v and a checker output .vv&.out test
parent
60997b3052
commit
fb4c3ff31a
|
@ -0,0 +1,34 @@
|
||||||
|
vlib/v/checker/tests/pointer_arithmetic_should_be_checked.v:4:6: error: pointer arithmetic is only allowed in `unsafe` blocks
|
||||||
|
2 | v := 5
|
||||||
|
3 | mut p := &v
|
||||||
|
4 | p++
|
||||||
|
| ~~
|
||||||
|
5 | p += 2
|
||||||
|
6 | _ := v
|
||||||
|
vlib/v/checker/tests/pointer_arithmetic_should_be_checked.v:5:7: error: pointer arithmetic is only allowed in `unsafe` blocks
|
||||||
|
3 | mut p := &v
|
||||||
|
4 | p++
|
||||||
|
5 | p += 2
|
||||||
|
| ~~
|
||||||
|
6 | _ := v
|
||||||
|
7 | }
|
||||||
|
vlib/v/checker/tests/pointer_arithmetic_should_be_checked.v:11:14: error: pointer arithmetic is only allowed in `unsafe` blocks
|
||||||
|
9 | fn test_ptr_infix() {
|
||||||
|
10 | v := 4
|
||||||
|
11 | mut q := &v - 1
|
||||||
|
| ^
|
||||||
|
12 | q = q + 3
|
||||||
|
13 | _ := q
|
||||||
|
vlib/v/checker/tests/pointer_arithmetic_should_be_checked.v:12:9: error: pointer arithmetic is only allowed in `unsafe` blocks
|
||||||
|
10 | v := 4
|
||||||
|
11 | mut q := &v - 1
|
||||||
|
12 | q = q + 3
|
||||||
|
| ^
|
||||||
|
13 | _ := q
|
||||||
|
14 | _ := v
|
||||||
|
vlib/v/checker/tests/pointer_arithmetic_should_be_checked.v:24:7: error: method `S1.f` must be called from an `unsafe` block
|
||||||
|
22 | fn test_funcs() {
|
||||||
|
23 | s := S1{}
|
||||||
|
24 | s.f()
|
||||||
|
| ~~~
|
||||||
|
25 | }
|
|
@ -1,34 +0,0 @@
|
||||||
unsafe.v:4:6: warning: pointer arithmetic is only allowed in `unsafe` blocks
|
|
||||||
2 | v := 5
|
|
||||||
3 | mut p := &v
|
|
||||||
4 | p++
|
|
||||||
| ~~
|
|
||||||
5 | p += 2
|
|
||||||
6 | _ := v
|
|
||||||
unsafe.v:5:7: warning: pointer arithmetic is only allowed in `unsafe` blocks
|
|
||||||
3 | mut p := &v
|
|
||||||
4 | p++
|
|
||||||
5 | p += 2
|
|
||||||
| ~~
|
|
||||||
6 | _ := v
|
|
||||||
7 | }
|
|
||||||
unsafe.v:11:14: warning: pointer arithmetic is only allowed in `unsafe` blocks
|
|
||||||
9 | fn test_ptr_infix() {
|
|
||||||
10 | v := 4
|
|
||||||
11 | mut q := &v - 1
|
|
||||||
| ^
|
|
||||||
12 | q = q + 3
|
|
||||||
13 | _ := q
|
|
||||||
unsafe.v:12:9: warning: pointer arithmetic is only allowed in `unsafe` blocks
|
|
||||||
10 | v := 4
|
|
||||||
11 | mut q := &v - 1
|
|
||||||
12 | q = q + 3
|
|
||||||
| ^
|
|
||||||
13 | _ := q
|
|
||||||
14 | _ := v
|
|
||||||
unsafe.v:24:7: warning: method `S1.f` must be called from an `unsafe` block
|
|
||||||
22 | fn test_funcs() {
|
|
||||||
23 | s := S1{}
|
|
||||||
24 | s.f()
|
|
||||||
| ~~~
|
|
||||||
25 | }
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
fn test_ptr_assign() {
|
||||||
|
v := [int(5), 6, 77, 1]
|
||||||
|
mut p := &v[0]
|
||||||
|
unsafe { (*p)++ }
|
||||||
|
unsafe { p++ } // p now points to v[1]
|
||||||
|
unsafe { (*p) += 2 }
|
||||||
|
unsafe { p += 2 } // p now points to v[3]
|
||||||
|
unsafe { *p = 31 }
|
||||||
|
assert v[0] == 6
|
||||||
|
assert v[1] == 8
|
||||||
|
assert v[2] == 77
|
||||||
|
assert v[3] == 31
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_ptr_infix() {
|
||||||
|
v := 4
|
||||||
|
mut q := unsafe{ &v - 1 }
|
||||||
|
q = unsafe {q + 3}
|
||||||
|
_ := q
|
||||||
|
_ := v
|
||||||
|
}
|
||||||
|
|
||||||
|
struct S1 {}
|
||||||
|
|
||||||
|
[unsafe_fn]
|
||||||
|
fn (s S1) f(){}
|
||||||
|
|
||||||
|
fn test_funcs() {
|
||||||
|
s := S1{}
|
||||||
|
unsafe { s.f() }
|
||||||
|
}
|
Loading…
Reference in New Issue