MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestApplyTiDBLineTracking

Function TestApplyTiDBLineTracking

backend/plugin/parser/tidb/omni_test.go:328–355  ·  view source on GitHub ↗

TestApplyTiDBLineTracking pins the leading-newline arithmetic directly across the edges the integration tests don't all exercise: no leading whitespace (line 1), single vs multiple leading newlines, CRLF line endings, a non-zero baseLine, and non-newline leading whitespace (BYT-9381).

(t *testing.T)

Source from the content-addressed store, hash-verified

326// (line 1), single vs multiple leading newlines, CRLF line endings, a non-zero
327// baseLine, and non-newline leading whitespace (BYT-9381).
328func TestApplyTiDBLineTracking(t *testing.T) {
329 nodes, err := ParseTiDB("SELECT 1", "", "")
330 require.NoError(t, err)
331 require.Len(t, nodes, 1)
332 node := nodes[0]
333
334 cases := []struct {
335 name string
336 baseLine int
337 text string
338 want int
339 }{
340 {"no leading whitespace is line 1", 0, "SELECT 1", 1},
341 {"single leading newline", 0, "\nSELECT 1", 2},
342 {"three leading newlines (the BYT-9381 bug)", 0, "\n\n\nSELECT 1", 4},
343 {"CRLF leading newlines count once each", 0, "\r\n\r\n\r\nSELECT 1", 4},
344 {"non-zero baseLine plus two newlines", 5, "\n\nSELECT 1", 8},
345 {"leading spaces and tabs, no newline", 0, " \tSELECT 1", 1},
346 {"mixed leading whitespace with one newline", 0, " \n SELECT 1", 2},
347 }
348 for _, tc := range cases {
349 t.Run(tc.name, func(t *testing.T) {
350 got, err := applyTiDBLineTracking(node, tc.baseLine, tc.text)
351 require.NoError(t, err)
352 require.Equal(t, tc.want, got)
353 })
354 }
355}
356
357// TestCreateTableColumnLineTrackingBlankLines pins per-column line tracking for
358// a CREATE TABLE preceded by blank lines (BYT-9381). The native parser may

Callers

nothing calls this directly

Calls 5

ParseTiDBFunction · 0.85
applyTiDBLineTrackingFunction · 0.85
LenMethod · 0.80
EqualMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected