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)
| 326 | // (line 1), single vs multiple leading newlines, CRLF line endings, a non-zero |
| 327 | // baseLine, and non-newline leading whitespace (BYT-9381). |
| 328 | func 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 |
nothing calls this directly
no test coverage detected