Skip to content

Commit c1028cb

Browse files
ahdzib-mayaaaronik
authored andcommitted
Add Go test for tab-indented sibling navigation
Tests the visual column fix by using Go files (which use tabs by convention). Validates that move_down/move_up correctly navigate between sibling nodes at the same indentation level when the file uses tab characters. Test cases: - var declarations as siblings - if blocks as siblings - top-level function declarations
1 parent 501cb86 commit c1028cb

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

tests/fixtures/go.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
var x = 1
7+
var y = 2
8+
var z = 3
9+
10+
if x > 0 {
11+
fmt.Println("positive")
12+
}
13+
14+
if y > 0 {
15+
fmt.Println("also positive")
16+
}
17+
}
18+
19+
func helper() {
20+
var a = 10
21+
var b = 20
22+
}

tests/treewalker/go_spec.lua

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)