|
| 1 | +local load_fixture = require "tests.load_fixture" |
| 2 | +local tw = require 'treewalker' |
| 3 | +local h = require 'tests.treewalker.helpers' |
| 4 | + |
| 5 | +describe("Movement in Go file with tab indentation:", function() |
| 6 | + before_each(function() |
| 7 | + load_fixture("/go.go") |
| 8 | + vim.opt.tabstop = 4 -- Standard Go tab width |
| 9 | + end) |
| 10 | + |
| 11 | + h.ensure_has_parser("go") |
| 12 | + |
| 13 | + -- This test validates the visual column fix in targets.lua |
| 14 | + -- Go files use tabs for indentation, which previously caused |
| 15 | + -- sibling navigation to fail due to byte vs visual column mismatch |
| 16 | + it("moves down between tab-indented var declarations (sibling nodes)", function() |
| 17 | + vim.fn.cursor(6, 1) -- First var declaration: var x = 1 |
| 18 | + tw.move_down() |
| 19 | + -- Should move to next sibling var, not skip or go elsewhere |
| 20 | + local row = vim.fn.line('.') |
| 21 | + assert.equals(7, row, "Should move from var x to var y (line 7)") |
| 22 | + tw.move_down() |
| 23 | + row = vim.fn.line('.') |
| 24 | + assert.equals(8, row, "Should move from var y to var z (line 8)") |
| 25 | + end) |
| 26 | + |
| 27 | + it("moves up between tab-indented var declarations (sibling nodes)", function() |
| 28 | + vim.fn.cursor(8, 1) -- Third var declaration: var z = 3 |
| 29 | + tw.move_up() |
| 30 | + local row = vim.fn.line('.') |
| 31 | + assert.equals(7, row, "Should move from var z to var y (line 7)") |
| 32 | + tw.move_up() |
| 33 | + row = vim.fn.line('.') |
| 34 | + assert.equals(6, row, "Should move from var y to var x (line 6)") |
| 35 | + end) |
| 36 | + |
| 37 | + it("moves down between tab-indented if blocks (sibling nodes)", function() |
| 38 | + vim.fn.cursor(10, 1) -- First if block |
| 39 | + tw.move_down() |
| 40 | + local row = vim.fn.line('.') |
| 41 | + assert.equals(14, row, "Should move from first if to second if (line 14)") |
| 42 | + end) |
| 43 | + |
| 44 | + it("moves between top-level function declarations", function() |
| 45 | + vim.fn.cursor(5, 1) -- func main() |
| 46 | + tw.move_down() |
| 47 | + local row = vim.fn.line('.') |
| 48 | + assert.equals(19, row, "Should move from main to helper (line 19)") |
| 49 | + end) |
| 50 | +end) |
0 commit comments