MCPcopy Index your code
hub / github.com/bytebase/bytebase / TestOffsetForPosition

Function TestOffsetForPosition

backend/api/lsp/utils_test.go:10–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestOffsetForPosition(t *testing.T) {
11 testCases := []struct {
12 content []byte
13 position lsp.Position
14 expected int
15 valid bool
16 }{
17 {
18 content: []byte("Hello, World!"),
19 position: lsp.Position{Line: 0, Character: 0},
20 expected: 0,
21 valid: true,
22 },
23 {
24 content: []byte("Hello, World!"),
25 position: lsp.Position{Line: 0, Character: 7},
26 expected: 7,
27 valid: true,
28 },
29 {
30 content: []byte("Hello, 世界!"),
31 position: lsp.Position{Line: 0, Character: 7}, // Before '世'
32 expected: 7,
33 valid: true,
34 },
35 {
36 content: []byte("Hello, 世界!"),
37 position: lsp.Position{Line: 0, Character: 8}, // After '世'
38 expected: 10,
39 valid: true,
40 },
41 {
42 content: []byte("Hello,\nWorld!"),
43 position: lsp.Position{Line: 1, Character: 0}, // Start of line 2
44 expected: 7,
45 valid: true,
46 },
47 {
48 content: []byte("Hello,\nWorld!"),
49 position: lsp.Position{Line: 1, Character: 5}, // 'World'
50 expected: 12,
51 valid: true,
52 },
53 {
54 content: []byte("Hello,\nWorld!"),
55 position: lsp.Position{Line: 1, Character: 10}, // Beyond line boundary
56 valid: false,
57 },
58 {
59 content: []byte("Hello, 𐍈!"), // '𐍈' is a Unicode character requiring surrogate pairs in UTF-16
60 position: lsp.Position{Line: 0, Character: 7},
61 expected: 7,
62 valid: true,
63 },
64 {
65 content: []byte("Hello, 𐍈!"),
66 position: lsp.Position{Line: 0, Character: 9}, // After surrogate pairs in UTF-16
67 expected: 11,

Callers

nothing calls this directly

Calls 2

offsetForPositionFunction · 0.85
EqualMethod · 0.65

Tested by

no test coverage detected