diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-07-11 21:19:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-11 21:19:49 +0200 |
| commit | f206288b0072a57e2dd2dda6a12a748a756ffbd7 (patch) | |
| tree | 9b6df186dc71d8e2ce66bf68169c22760b2d3f88 /src/testing | |
| parent | 905716a76f4c46afd76305b207f80b7f7e0c2911 (diff) | |
| parent | 26858c758ddb9868c02a3cf6db1b3b646abf577d (diff) | |
Merge pull request #398 from DanielGavin/rename
Working on adding support for renaming
Diffstat (limited to 'src/testing')
| -rw-r--r-- | src/testing/testing.odin | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/src/testing/testing.odin b/src/testing/testing.odin index fb8c034..0d9c028 100644 --- a/src/testing/testing.odin +++ b/src/testing/testing.odin @@ -62,7 +62,8 @@ setup :: proc(src: ^Source) { } else if current == '\n' { current_line += 1 current_character = 0 - } else if src.main[current_index:current_index + 3] == "{*}" { + } else if len(src.main) > current_index + 3 && + src.main[current_index:current_index + 3] == "{*}" { dst_slice := transmute([]u8)src.main[current_index:] src_slice := transmute([]u8)src.main[current_index + 3:] copy(dst_slice, src_slice) @@ -382,3 +383,67 @@ expect_definition_locations :: proc( } } } + +expect_reference_locations :: proc( + t: ^testing.T, + src: ^Source, + expect_locations: []common.Location, +) { + setup(src) + defer teardown(src) + + locations, ok := server.get_references(src.document, src.position) + + for expect_location in expect_locations { + match := false + for location in locations { + if location.range == expect_location.range { + match = true + } + } + if !match { + ok = false + log.errorf("Failed to match with location: %v", expect_location) + } + } + + if !ok { + log.error("Received:") + for location in locations { + log.errorf("%v \n", location) + } + } +} + +expect_semantic_tokens :: proc( + t: ^testing.T, + src: ^Source, + expected: []server.SemanticToken, +) { + setup(src) + defer teardown(src) + + + resolve_flag: server.ResolveReferenceFlag + symbols_and_nodes := server.resolve_entire_file( + src.document, + resolve_flag, + context.temp_allocator, + ) + + range := common.Range{end = {line = 9000000}} //should be enough + tokens := server.get_semantic_tokens(src.document, range, symbols_and_nodes) + + testing.expectf(t, len(expected) == len(tokens), "\nExpected %d tokens, but received %d", len(expected), len(tokens)) + + for i in 0..<min(len(expected), len(tokens)) { + e, a := expected[i], tokens[i] + testing.expectf(t, + e == a, + "\n[%d]: Expected \n(%d, %d, %d, %v, %w)\nbut received\n(%d, %d, %d, %v, %w)", + i, + e.delta_line, e.delta_char, e.len, e.type, e.modifiers, + a.delta_line, a.delta_char, a.len, a.type, a.modifiers, + ) + } +} |