-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhover_test.go
More file actions
163 lines (146 loc) · 3.8 KB
/
Copy pathhover_test.go
File metadata and controls
163 lines (146 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"testing"
"github.com/stretchr/testify/assert"
protocol "github.com/tliron/glsp/protocol_3_16"
)
func TestPositionInRange(t *testing.T) {
rng := protocol.Range{
Start: protocol.Position{Line: 5, Character: 10},
End: protocol.Position{Line: 5, Character: 30},
}
tests := []struct {
name string
position protocol.Position
expected bool
}{
{
name: "position before range",
position: protocol.Position{Line: 5, Character: 5},
expected: false,
},
{
name: "position at start",
position: protocol.Position{Line: 5, Character: 10},
expected: true,
},
{
name: "position in middle",
position: protocol.Position{Line: 5, Character: 20},
expected: true,
},
{
name: "position at end",
position: protocol.Position{Line: 5, Character: 30},
expected: true,
},
{
name: "position after range",
position: protocol.Position{Line: 5, Character: 35},
expected: false,
},
{
name: "position on different line before",
position: protocol.Position{Line: 4, Character: 20},
expected: false,
},
{
name: "position on different line after",
position: protocol.Position{Line: 6, Character: 20},
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := positionInRange(tt.position, rng)
assert.Equal(t, tt.expected, result)
})
}
}
func TestPositionInRange_MultiLine(t *testing.T) {
rng := protocol.Range{
Start: protocol.Position{Line: 5, Character: 10},
End: protocol.Position{Line: 7, Character: 20},
}
tests := []struct {
name string
position protocol.Position
expected bool
}{
{
name: "on first line",
position: protocol.Position{Line: 5, Character: 15},
expected: true,
},
{
name: "on middle line",
position: protocol.Position{Line: 6, Character: 0},
expected: true,
},
{
name: "on last line",
position: protocol.Position{Line: 7, Character: 10},
expected: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := positionInRange(tt.position, rng)
assert.Equal(t, tt.expected, result)
})
}
}
func TestFormatHoverContent(t *testing.T) {
finding := Finding{
RuleID: "aws-access-token",
Description: "AWS Access Key detected",
Match: "AKIATESTKEYEXAMPLE7A",
Secret: "AKIATESTKEYEXAMPLE7A",
StartLine: 10,
StartColumn: 15,
EndColumn: 35,
Entropy: 3.5,
Fingerprint: "abc123def456",
}
content := formatHoverContent(finding)
// Verify key sections are present
assert.Contains(t, content, "# 🔐 Secret Detected")
assert.Contains(t, content, "aws-access-token")
assert.Contains(t, content, "AWS Access Key detected")
assert.Contains(t, content, "Line 10")
assert.Contains(t, content, "Entropy")
assert.Contains(t, content, "3.50")
assert.Contains(t, content, "abc123def456")
assert.Contains(t, content, "AKIATESTKEYEXAMPLE7A")
assert.Contains(t, content, "gitleaks:allow")
assert.Contains(t, content, "Recommendations")
}
func TestFormatHoverContent_NoEntropy(t *testing.T) {
finding := Finding{
RuleID: "test-rule",
Description: "Test pattern",
Match: "test-secret",
StartLine: 1,
StartColumn: 0,
EndColumn: 10,
Entropy: 0, // No entropy
Fingerprint: "xyz789",
}
content := formatHoverContent(finding)
// Should not mention entropy when it's 0
assert.NotContains(t, content, "Entropy:")
}
func TestFormatHoverContent_LongMatch(t *testing.T) {
finding := Finding{
RuleID: "long-secret",
Description: "Very long secret",
Match: string(make([]byte, 200)), // 200 byte match
StartLine: 1,
StartColumn: 0,
EndColumn: 200,
Fingerprint: "long123",
}
content := formatHoverContent(finding)
// Should truncate long matches
assert.Contains(t, content, "...")
}