aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.odin
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing.odin')
-rw-r--r--src/testing/testing.odin73
1 files changed, 53 insertions, 20 deletions
diff --git a/src/testing/testing.odin b/src/testing/testing.odin
index fed1510..66ed992 100644
--- a/src/testing/testing.odin
+++ b/src/testing/testing.odin
@@ -537,16 +537,19 @@ expect_inlay_hints :: proc(t: ^testing.T, src: ^Source) {
src_builder := strings.builder_make(context.temp_allocator)
expected_hints := make([dynamic]server.InlayHint, context.temp_allocator)
+ HINT_OPEN :: "[["
+ HINT_CLOSE :: "]]"
+
{
last, line, col: int
saw_brackets: bool
for i:= 0; i < len(src.main); i += 1 {
if saw_brackets {
- if i+1 < len(src.main) && src.main[i:i+2] == "]]" {
+ if i+1 < len(src.main) && src.main[i:][:len(HINT_CLOSE)] == HINT_CLOSE {
saw_brackets = false
hint_str := src.main[last:i]
- last = i+2
- i += 1
+ last = i+len(HINT_CLOSE)
+ i = last-1
append(&expected_hints, server.InlayHint{
position = {line, col},
label = hint_str,
@@ -554,11 +557,11 @@ expect_inlay_hints :: proc(t: ^testing.T, src: ^Source) {
})
}
} else {
- if i+1 < len(src.main) && src.main[i:i+2] == "[[" {
+ if i+1 < len(src.main) && src.main[i:][:len(HINT_OPEN)] == HINT_OPEN {
strings.write_string(&src_builder, src.main[last:i])
saw_brackets = true
- last = i+2
- i += 1
+ last = i+len(HINT_OPEN)
+ i = last-1
} else if src.main[i] == '\n' {
line += 1
col = 0
@@ -584,29 +587,59 @@ expect_inlay_hints :: proc(t: ^testing.T, src: ^Source) {
resolve_flag: server.ResolveReferenceFlag
symbols_and_nodes := server.resolve_entire_file(src.document, resolve_flag, )
- hints, ok := server.get_inlay_hints(src.document, symbols_and_nodes, &src.config)
- if !ok {
+ hints, hints_ok := server.get_inlay_hints(src.document, symbols_and_nodes, &src.config)
+ if !hints_ok {
log.error("Failed get_inlay_hints")
return
}
- if len(expected_hints) == 0 && len(hints) > 0 {
- log.errorf("Expected empty inlay hints, but received %v", hints)
- return
- }
-
- testing.expectf(
- t,
+ testing.expectf(t,
len(expected_hints) == len(hints),
- "\nExpected %d inlay hints, but received %d",
+ "Expected %d inlay hints, but received %d",
len(expected_hints),
len(hints),
)
- for i in 0 ..< min(len(expected_hints), len(hints)) {
- e, a := expected_hints[i], hints[i]
- if e != a {
- log.errorf("[%d]: Expected inlay hint\n%v, but received\n%v", i, e, a)
+ lines := strings.split_lines(src.main, context.temp_allocator)
+
+ get_source_line_with_hint :: proc(lines: []string, hint: server.InlayHint) -> string {
+ line := lines[hint.position.line] if hint.position.line >= 0 && hint.position.line < len(lines) else ""
+ if hint.position.character >= 0 && hint.position.character <= len(line) {
+ builder := strings.builder_make(context.temp_allocator)
+ strings.write_string(&builder, line[:hint.position.character])
+ strings.write_string(&builder, HINT_OPEN)
+ strings.write_string(&builder, hint.label)
+ strings.write_string(&builder, HINT_CLOSE)
+ strings.write_string(&builder, line[hint.position.character:])
+ return strings.to_string(builder)
+ }
+ return ""
+ }
+
+ for i in 0 ..< max(len(expected_hints), len(hints)) {
+ expected_text := "---"
+ actual_text := "---"
+
+ if i < len(expected_hints) {
+ expected := expected_hints[i]
+ expected_line := get_source_line_with_hint(lines, expected)
+ expected_text = fmt.tprintf("\"%s\" at (%d, %d): \"%s\"",
+ expected.label, expected.position.line, expected.position.character, expected_line)
+ }
+
+ if i < len(hints) {
+ actual := hints[i]
+ actual_line := get_source_line_with_hint(lines, actual)
+ actual_text = fmt.tprintf("\"%s\" at (%d, %d): \"%s\"",
+ actual.label, actual.position.line, actual.position.character, actual_line)
+ }
+
+ if i >= len(expected_hints) {
+ log.errorf("[%d]: Unexpected inlay hint\nExpected: %s\nActual: %s", i, expected_text, actual_text)
+ } else if i >= len(hints) {
+ log.errorf("[%d]: Missing inlay hint\nExpected: %s\nActual: %s", i, expected_text, actual_text)
+ } else if expected_hints[i] != hints[i] {
+ log.errorf("[%d]: Inlay hint mismatch\nExpected: %s\nActual: %s", i, expected_text, actual_text)
}
}
}