diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-06-11 21:59:11 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-06-11 21:59:11 +0200 |
| commit | a7bb78679028f2ade9c0975c4ec895db3fd62d9e (patch) | |
| tree | bf57262f2fbfb696d353fc21bdac7282935706c4 /tests | |
| parent | b88ec3cd61dddb43f2434e270835ba341ba31b3f (diff) | |
Add more stability to prevent crashes + more tests with renaming
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/definition_test.odin | 33 | ||||
| -rw-r--r-- | tests/references_test.odin | 62 |
2 files changed, 83 insertions, 12 deletions
diff --git a/tests/definition_test.odin b/tests/definition_test.odin index 677736a..cd32628 100644 --- a/tests/definition_test.odin +++ b/tests/definition_test.odin @@ -231,6 +231,39 @@ ast_goto_shadowed_value_decls :: proc(t: ^testing.T) { ) } +@(test) +ast_goto_implicit_super_enum_infer_from_assignment :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + Sub_Enum1 :: enum { + ONE, + } + Sub_Enum2 :: enum { + TWO, + } + + Super_Enum :: union { + Sub_Enum1, + Sub_Enum2, + } + + main :: proc() { + my_enum: Super_Enum + my_enum = .ON{*}E + } + `, + packages = {}, + } + + location := common.Location { + range = { + start = {line = 2, character = 3}, + end = {line = 2, character = 6}, + }, + } + + test.expect_definition_locations(t, &source, {location}) +} @(test) ast_goto_implicit_enum_infer_from_assignment :: proc(t: ^testing.T) { diff --git a/tests/references_test.odin b/tests/references_test.odin index 61c9cd0..c07e8cf 100644 --- a/tests/references_test.odin +++ b/tests/references_test.odin @@ -8,14 +8,13 @@ import test "src:testing" @(test) reference_variables_in_function :: proc(t: ^testing.T) { source := test.Source { - main = `package test + main = `package test my_function :: proc() { a := 2 b := a c := 2 + b{*} } `, - packages = {}, } test.expect_reference_locations( @@ -41,12 +40,11 @@ reference_variables_in_function :: proc(t: ^testing.T) { @(test) reference_variables_in_function_parameters :: proc(t: ^testing.T) { source := test.Source { - main = `package test + main = `package test my_function :: proc(a: int) { b := a{*} } `, - packages = {}, } test.expect_reference_locations( @@ -66,7 +64,7 @@ reference_variables_in_function_parameters :: proc(t: ^testing.T) { @(test) reference_selectors_in_function :: proc(t: ^testing.T) { source := test.Source { - main = `package test + main = `package test My_Struct :: struct { a: int, } @@ -76,7 +74,6 @@ reference_selectors_in_function :: proc(t: ^testing.T) { my.a{*} = 2 } `, - packages = {}, } test.expect_reference_locations( @@ -103,7 +100,7 @@ reference_selectors_in_function :: proc(t: ^testing.T) { @(test) reference_field_comp_lit :: proc(t: ^testing.T) { source := test.Source { - main = `package test + main = `package test Foo :: struct { soo_many_cases: int, } @@ -118,7 +115,6 @@ reference_field_comp_lit :: proc(t: ^testing.T) { } } `, - packages = {}, } test.expect_reference_locations( @@ -144,7 +140,7 @@ reference_field_comp_lit :: proc(t: ^testing.T) { @(test) reference_field_comp_lit_infer_from_function :: proc(t: ^testing.T) { source := test.Source { - main = `package test + main = `package test Foo :: struct { soo_many_cases: int, } @@ -157,7 +153,6 @@ reference_field_comp_lit_infer_from_function :: proc(t: ^testing.T) { my_function({foo = {soo_many_cases{*} = 2}}) } `, - packages = {}, } test.expect_reference_locations( @@ -183,7 +178,7 @@ reference_field_comp_lit_infer_from_function :: proc(t: ^testing.T) { @(test) reference_field_comp_lit_infer_from_return :: proc(t: ^testing.T) { source := test.Source { - main = `package test + main = `package test Foo :: struct { soo_many_cases: int, } @@ -196,7 +191,6 @@ reference_field_comp_lit_infer_from_return :: proc(t: ^testing.T) { return {foo = {soo_many_cases{*} = 2}} } `, - packages = {}, } test.expect_reference_locations( @@ -218,3 +212,47 @@ reference_field_comp_lit_infer_from_return :: proc(t: ^testing.T) { }, ) } + + +@(test) +reference_enum_field_infer_from_assignment :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + Sub_Enum1 :: enum { + ONE, + } + Sub_Enum2 :: enum { + TWO, + } + + Super_Enum :: union { + Sub_Enum1, + Sub_Enum2, + } + + main :: proc() { + my_enum: Super_Enum + my_enum = .ON{*}E + } + `, + } + + test.expect_reference_locations( + t, + &source, + { + { + range = { + start = {line = 2, character = 3}, + end = {line = 2, character = 6}, + }, + }, + { + range = { + start = {line = 15, character = 14}, + end = {line = 15, character = 17}, + }, + }, + }, + ) +} |