diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-06-09 09:33:50 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-06-09 10:14:20 -0400 |
| commit | 46ca826ae4379ef3f2a61639bceee5a2390d6914 (patch) | |
| tree | 00df2b3688b7f7dc10d2305f965b30d828cbccab /tests | |
| parent | c4dfd07a0537041556d7c074ebea60987ffc3d2b (diff) | |
Improve reference handling for variables part of selector expr
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/references_test.odin | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/references_test.odin b/tests/references_test.odin index 8c7c422..1d0fbde 100644 --- a/tests/references_test.odin +++ b/tests/references_test.odin @@ -3,6 +3,8 @@ package tests import "core:fmt" import "core:testing" +import "src:common" + import test "src:testing" @(test) @@ -217,3 +219,57 @@ reference_struct_field :: proc(t: ^testing.T) { }, ) } + +@(test) +ast_reference_variable_declaration_with_selector_expr :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + + Bar :: struct { + foo: int, + } + + main :: proc() { + bar: [2]Bar + bar[0].foo = 5 + b{*}ar[1].foo = 6 + } + `, + packages = {}, + } + + locations := []common.Location{ + {range = { start = {line = 7, character = 3}, end = {line = 7, character = 6}}}, + {range = { start = {line = 8, character = 3}, end = {line = 8, character = 6}}}, + {range = { start = {line = 9, character = 3}, end = {line = 9, character = 6}}}, + } + + test.expect_reference_locations(t, &source, locations[:]) +} + +@(test) +ast_reference_variable_declaration_field_with_selector_expr :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + + Bar :: struct { + foo: int, + } + + main :: proc() { + bar: [2]Bar + bar[0].foo = 5 + bar[1].f{*}oo = 6 + } + `, + packages = {}, + } + + locations := []common.Location{ + {range = { start = {line = 3, character = 3}, end = {line = 3, character = 6}}}, + {range = { start = {line = 8, character = 10}, end = {line = 8, character = 13}}}, + {range = { start = {line = 9, character = 10}, end = {line = 9, character = 13}}}, + } + + test.expect_reference_locations(t, &source, locations[:]) +} |