47 lines
1.8 KiB
Go
47 lines
1.8 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package atspi
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestDocumentLinesAreTokens(t *testing.T) {
|
|
for _, test := range []struct {
|
|
name, text string
|
|
lines []TextRange
|
|
want bool
|
|
}{
|
|
{"words", "What's on your mind?", []TextRange{{Start: 0, End: 7, Text: "What's "}, {Start: 7, End: 10, Text: "on "}, {Start: 10, End: 15, Text: "your "}, {Start: 15, End: 20, Text: "mind?"}}, true},
|
|
{"unicode characters", "é 文", []TextRange{{Start: 0, End: 1, Text: "é"}, {Start: 1, End: 2, Text: " "}, {Start: 2, End: 3, Text: "文"}}, true},
|
|
{"ordinary lines", "First line\nSecond line", []TextRange{{Start: 0, End: 11, Text: "First line\n"}, {Start: 11, End: 22, Text: "Second line"}}, false},
|
|
{"one word", "autocomplete", []TextRange{{Start: 0, End: 12, Text: "autocomplete"}}, false},
|
|
{"embedded objects", "\ufffc\ufffc\ufffc hello", nil, false},
|
|
{"non advancing provider", "one two", []TextRange{{Start: 0, End: 0, Text: "one"}}, false},
|
|
} {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
source := fakeReviewText{lines: make(map[int]TextRange)}
|
|
for _, line := range test.lines {
|
|
source.lines[line.Start] = line
|
|
}
|
|
got, err := documentLinesAreTokens(context.Background(), source, test.text)
|
|
if err != nil || got != test.want {
|
|
t.Fatalf("repair = %v, %v; want %v", got, err, test.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDocumentLinesProbeHonorsCancellation(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
source := fakeReviewText{cancel: cancel, lines: map[int]TextRange{0: {Start: 0, End: 2, Text: "a "}, 2: {Start: 2, End: 3, Text: "b"}}}
|
|
_, err := documentLinesAreTokens(ctx, source, "a b")
|
|
if !errors.Is(err, context.Canceled) {
|
|
t.Fatalf("probe error = %v", err)
|
|
}
|
|
}
|