| 1 | fn foo() int { |
| 2 | return 1 |
| 3 | } |
| 4 | |
| 5 | fn zoo() int { |
| 6 | return 123 |
| 7 | } |
| 8 | |
| 9 | fn test_dump_of_functions() { |
| 10 | x := dump(foo) |
| 11 | y := dump(zoo) |
| 12 | dump(foo()) |
| 13 | dump(zoo()) |
| 14 | dump(x) |
| 15 | dump(y) |
| 16 | dump(x()) |
| 17 | dump(y()) |
| 18 | assert voidptr(x) != 0 |
| 19 | assert voidptr(y) != 0 |
| 20 | assert foo == x |
| 21 | assert y == zoo |
| 22 | } |
| 23 | |
| 24 | // |
| 25 | |
| 26 | struct StructWithStrMethodTakingReference { |
| 27 | x int |
| 28 | } |
| 29 | |
| 30 | pub fn (t &StructWithStrMethodTakingReference) str() string { |
| 31 | return 'StructWithStrMethodTakingReference{x: ${t.x}}' |
| 32 | } |
| 33 | |
| 34 | fn test_dump_of_type_that_has_custom_str_method_with_reference_parameter() { |
| 35 | s := StructWithStrMethodTakingReference{123} |
| 36 | assert dump(s).x == 123 |
| 37 | ps := &StructWithStrMethodTakingReference{456} |
| 38 | assert dump(ps).x == 456 |
| 39 | } |
| 40 | |
| 41 | // |
| 42 | |
| 43 | struct StructWithNormalStrMethod { |
| 44 | x int |
| 45 | } |
| 46 | |
| 47 | pub fn (t StructWithNormalStrMethod) str() string { |
| 48 | return 'StructWithNormalStrMethod{x: ${t.x}}' |
| 49 | } |
| 50 | |
| 51 | fn test_dump_of_type_that_has_normal_custom_str_method() { |
| 52 | s := StructWithNormalStrMethod{123} |
| 53 | assert dump(s).x == 123 |
| 54 | ps := &StructWithNormalStrMethod{456} |
| 55 | assert dump(ps).x == 456 |
| 56 | } |
| 57 | |
| 58 | // |
| 59 | |
| 60 | struct StructWithoutStrMethod { |
| 61 | x int |
| 62 | } |
| 63 | |
| 64 | fn test_dump_of_type_that_has_no_custom_str_method() { |
| 65 | s := StructWithoutStrMethod{123} |
| 66 | assert dump(s).x == 123 |
| 67 | ps := &StructWithoutStrMethod{456} |
| 68 | assert dump(ps).x == 456 |
| 69 | } |
| 70 | |
| 71 | fn test_nil_values_and_voidptr_values_can_be_dumped_in_the_same_program() { |
| 72 | // Note, that nil is its own type in the main v repo, |
| 73 | // while dump() generates `_v_dump_expr_voidptr` for *both* `nil` and `voidptr` values. |
| 74 | a := unsafe { nil } |
| 75 | b := voidptr(456) |
| 76 | dump(a) |
| 77 | dump(b) |
| 78 | assert true |
| 79 | } |
| 80 | |