diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-06-09 12:55:24 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-06-09 12:55:24 +0200 |
| commit | 33b5b66a53fef0ea3fd9ccec4841290050cd95f4 (patch) | |
| tree | 3e656887b76fed9b1cc1b59bf0addd04f7596f74 /tests | |
| parent | ada14e0c911a11129daafbd486386e761661f40b (diff) | |
Improve reference testing
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/references_test.odin | 116 |
1 files changed, 90 insertions, 26 deletions
diff --git a/tests/references_test.odin b/tests/references_test.odin index aa2579b..cadaff4 100644 --- a/tests/references_test.odin +++ b/tests/references_test.odin @@ -12,56 +12,46 @@ reference_variables_in_function :: proc(t: ^testing.T) { my_function :: proc() { a := 2 b := a - c := 2 + b + c := 2 + b{*} } `, packages = {}, } - test.expect_symbol_location( + test.expect_reference_locations( t, &source, - .Identifier, { { range = { - start = {line = 2, character = 3}, - end = {line = 2, character = 4}, - }, - }, - { - range = { start = {line = 3, character = 3}, end = {line = 3, character = 4}, }, }, { range = { - start = {line = 4, character = 3}, - end = {line = 4, character = 4}, + start = {line = 4, character = 12}, + end = {line = 4, character = 13}, }, }, }, ) } - @(test) reference_variables_in_function_parameters :: proc(t: ^testing.T) { source := test.Source { main = `package test my_function :: proc(a: int) { - b := a - c := 2 + b + b := a{*} } `, packages = {}, } - test.expect_symbol_location( + test.expect_reference_locations( t, &source, - .Identifier, { { range = { @@ -69,6 +59,30 @@ reference_variables_in_function_parameters :: proc(t: ^testing.T) { end = {line = 1, character = 23}, }, }, + }, + ) +} + +@(test) +reference_selectors_in_function :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + My_Struct :: struct { + a: int, + } + + my_function :: proc() { + my: My_Struct + my.a{*} = 2 + } + `, + packages = {}, + } + + test.expect_reference_locations( + t, + &source, + { { range = { start = {line = 2, character = 3}, @@ -77,39 +91,89 @@ reference_variables_in_function_parameters :: proc(t: ^testing.T) { }, { range = { - start = {line = 3, character = 3}, - end = {line = 3, character = 4}, + start = {line = 7, character = 6}, + end = {line = 7, character = 7}, }, }, }, ) } + @(test) -reference_selectors_in_function :: proc(t: ^testing.T) { +reference_field_comp_lit :: proc(t: ^testing.T) { source := test.Source { main = `package test + Foo :: struct { + soo_many_cases: int, + } + My_Struct :: struct { - a: int, + foo: Foo, } - my_function :: proc() { - my: My_Struct - my.a = 2 + my_function :: proc(my_struct: My_Struct) { + my := My_Struct { + foo = {soo_many_cases{*} = 2}, + } } `, packages = {}, } - test.expect_symbol_location( + test.expect_reference_locations( t, &source, - .Field, { { range = { start = {line = 2, character = 3}, - end = {line = 2, character = 4}, + end = {line = 2, character = 17}, + }, + }, + { + range = { + start = {line = 11, character = 11}, + end = {line = 11, character = 25}, + }, + }, + }, + ) +} + +@(test) +reference_field_comp_lit_infer_from_function :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + Foo :: struct { + soo_many_cases: int, + } + + My_Struct :: struct { + foo: Foo, + } + + my_function :: proc(my_struct: My_Struct) { + my_function({foo = {soo_many_cases{*} = 2}}) + } + `, + packages = {}, + } + + test.expect_reference_locations( + t, + &source, + { + { + range = { + start = {line = 2, character = 3}, + end = {line = 2, character = 17}, + }, + }, + { + range = { + start = {line = 10, character = 23}, + end = {line = 10, character = 37}, }, }, }, |