1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/builtin/bare/.checks/structs/structs.v
Delyan Angelov b7c477cc18 freestanding: ptr_str, string concat, struct declaration
* compiler: extract c_common_macros from c_headers, and use it in bare_c_headers too. Support for ptr_str and string concatenation in -freestanding mode.

* Add tests for structs and string concatenation in -freestanding mode .

* Move check_string_add_works to string/string.v .
2019-12-16 19:05:33 +03:00

43 lines
1000 B
V

module main
import forkedtest
struct SimpleEmptyStruct{
}
struct NonEmptyStruct{
x int
y int
z int
}
fn check_simple_empty_struct(){
s := SimpleEmptyStruct{}
addr_s := &s
str_addr_s := ptr_str( addr_s )
assert !isnil(addr_s)
assert str_addr_s.len > 3
println(str_addr_s)
}
fn check_non_empty_struct(){
a := NonEmptyStruct{1,2,3}
b := NonEmptyStruct{4,5,6}
assert sizeof(NonEmptyStruct) > 0
assert sizeof(SimpleEmptyStruct) < sizeof(NonEmptyStruct)
assert a.x == 1
assert a.y == 2
assert a.z == 3
assert b.x + b.y + b.z == 15
assert ptr_str(&a) != ptr_str(&b)
println('sizeof SimpleEmptyStruct:' + i64_str( sizeof(SimpleEmptyStruct) , 10 ))
println('sizeof NonEmptyStruct:' + i64_str( sizeof(NonEmptyStruct) , 10 ))
}
fn main(){
mut fails := 0
fails += forkedtest.normal_run(check_simple_empty_struct, "check_simple_empty_struct")
fails += forkedtest.normal_run(check_non_empty_struct, "check_non_empty_struct")
assert fails == 0
sys_exit(0)
}