MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestPosition_AdvanceN

Function TestPosition_AdvanceN

pkg/sql/tokenizer/coverage_enhancement_test.go:223–276  ·  view source on GitHub ↗

TestPosition_AdvanceN tests the Position.AdvanceN method.

(t *testing.T)

Source from the content-addressed store, hash-verified

221
222// TestPosition_AdvanceN tests the Position.AdvanceN method.
223func TestPosition_AdvanceN(t *testing.T) {
224 t.Run("AdvanceN advances position by N characters", func(t *testing.T) {
225 pos := NewPosition(1, 0) // Line 1, index 0
226 lineStarts := []int{0, 6, 12} // Line boundaries
227
228 // Advance by 3 characters on first line
229 pos.AdvanceN(3, lineStarts)
230 if pos.Index != 3 {
231 t.Errorf("AdvanceN(3) Index = %d, want 3", pos.Index)
232 }
233 if pos.Line != 1 {
234 t.Errorf("AdvanceN(3) Line = %d, want 1", pos.Line)
235 }
236
237 // Advance to cross first newline (from index 3 to 7)
238 pos.AdvanceN(4, lineStarts)
239 if pos.Index != 7 {
240 t.Errorf("AdvanceN(4) Index = %d, want 7", pos.Index)
241 }
242 if pos.Line != 2 {
243 t.Errorf("AdvanceN crossing newline, Line = %d, want 2", pos.Line)
244 }
245 })
246
247 t.Run("AdvanceN with zero does nothing", func(t *testing.T) {
248 pos := NewPosition(1, 5)
249 lineStarts := []int{0}
250
251 originalIndex := pos.Index
252 originalLine := pos.Line
253
254 pos.AdvanceN(0, lineStarts)
255
256 if pos.Index != originalIndex {
257 t.Errorf("AdvanceN(0) changed Index from %d to %d", originalIndex, pos.Index)
258 }
259 if pos.Line != originalLine {
260 t.Errorf("AdvanceN(0) changed Line from %d to %d", originalLine, pos.Line)
261 }
262 })
263
264 t.Run("AdvanceN with negative does nothing", func(t *testing.T) {
265 pos := NewPosition(1, 5)
266 lineStarts := []int{0}
267
268 originalIndex := pos.Index
269
270 pos.AdvanceN(-5, lineStarts)
271
272 if pos.Index != originalIndex {
273 t.Errorf("AdvanceN(-5) changed Index from %d to %d", originalIndex, pos.Index)
274 }
275 })
276}
277
278// TestTokenizer_NewWithKeywords tests initialization with custom keywords.
279func TestTokenizer_NewWithKeywords(t *testing.T) {

Callers

nothing calls this directly

Calls 4

AdvanceNMethod · 0.95
NewPositionFunction · 0.85
RunMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected