| 1 | // Test data file for goto_def_test.v |
| 2 | module main |
| 3 | |
| 4 | import v.tests.vls.sample_mod1 as s |
| 5 | |
| 6 | struct LocalStruct { |
| 7 | value int |
| 8 | } |
| 9 | |
| 10 | fn (ls LocalStruct) my_method() string { |
| 11 | return 'method' |
| 12 | } |
| 13 | |
| 14 | fn test_local_struct() { |
| 15 | mut obj := LocalStruct{value: 42} |
| 16 | |
| 17 | msg := obj.my_method() |
| 18 | println(msg) |
| 19 | |
| 20 | another := LocalStruct{} |
| 21 | println(another.value) |
| 22 | |
| 23 | yet_another := obj |
| 24 | println(yet_another) |
| 25 | |
| 26 | val := obj.value |
| 27 | println(val) |
| 28 | |
| 29 | result := obj.my_method() |
| 30 | println(result) |
| 31 | |
| 32 | ret_type := obj.my_method() |
| 33 | println(ret_type) |
| 34 | } |
| 35 | |
| 36 | struct DeepStruct { |
| 37 | LocalStruct |
| 38 | st struct { |
| 39 | sstt struct { |
| 40 | l2 int |
| 41 | } |
| 42 | l1 int |
| 43 | } |
| 44 | l0 int |
| 45 | } |
| 46 | |
| 47 | fn test_deep_struct() { |
| 48 | deep := DeepStruct{} |
| 49 | nested_val := deep.st.sstt.l2 |
| 50 | println(nested_val) |
| 51 | |
| 52 | embedded_val := deep.LocalStruct |
| 53 | println(embedded_val) |
| 54 | |
| 55 | deep_2 := DeepStruct { |
| 56 | st: struct { |
| 57 | sstt: struct { |
| 58 | l2: deep.st.sstt.l2 |
| 59 | } |
| 60 | l1: deep.st.l1 |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | enum LocalEnum { |
| 66 | first |
| 67 | second |
| 68 | third |
| 69 | } |
| 70 | |
| 71 | fn test_local_enum() { |
| 72 | e1 := LocalEnum.first |
| 73 | |
| 74 | match e1 { |
| 75 | .second { println('second') } |
| 76 | else {} |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | type LocalAlias = string |
| 81 | |
| 82 | fn test_local_alias() { |
| 83 | casted := LocalAlias('test') |
| 84 | } |
| 85 | |
| 86 | type LocalSum = int | string |
| 87 | |
| 88 | struct TypeA { |
| 89 | a int |
| 90 | } |
| 91 | |
| 92 | struct TypeB { |
| 93 | b string |
| 94 | } |
| 95 | |
| 96 | type UserSum = TypeA | TypeB |
| 97 | |
| 98 | fn test_local_sum() { |
| 99 | sum_val := LocalSum(42) |
| 100 | println(sum_val) |
| 101 | |
| 102 | user_sum := UserSum(TypeA{a: 10}) |
| 103 | println(user_sum) |
| 104 | } |
| 105 | |
| 106 | enum Method { |
| 107 | completion |
| 108 | signature_help |
| 109 | definition |
| 110 | } |
| 111 | |
| 112 | fn test_match_enum() { |
| 113 | method := Method.completion |
| 114 | line_info := match method { |
| 115 | .completion { |
| 116 | 'completion_info' |
| 117 | } |
| 118 | .signature_help { |
| 119 | 'signature_info' |
| 120 | } |
| 121 | .definition { |
| 122 | 'definition_info' |
| 123 | } |
| 124 | } |
| 125 | println(line_info) |
| 126 | } |
| 127 | |
| 128 | fn test_imported_enum() { |
| 129 | imported_e := s.PublicEnum1.a |
| 130 | println(imported_e) |
| 131 | } |
| 132 | |
| 133 | struct OpStruct { |
| 134 | val int |
| 135 | } |
| 136 | |
| 137 | fn (a OpStruct) + (b OpStruct) OpStruct { |
| 138 | return OpStruct{val: a.val + b.val} |
| 139 | } |
| 140 | |
| 141 | fn takes_struct(param OpStruct) string { |
| 142 | return param.str() |
| 143 | } |
| 144 | |
| 145 | struct ArrayElemStruct { |
| 146 | value int |
| 147 | } |
| 148 | |
| 149 | struct ContainerStruct { |
| 150 | items []ArrayElemStruct |
| 151 | fixed_items [5]ArrayElemStruct |
| 152 | } |
| 153 | |