diff --git a/tests/go/positions_spec.lua b/tests/go/positions_spec.lua index 50362fd..fe09490 100644 --- a/tests/go/positions_spec.lua +++ b/tests/go/positions_spec.lua @@ -10,18 +10,63 @@ describe("Discovery of test positions", function() id = test_filepath, name = vim.fn.fnamemodify(test_filepath, ":t"), path = test_filepath, - range = { 0, 0, 10, 0 }, + range = { 0, 0, 37, 0 }, -- NOTE: this always gets changed when tests are added or removed type = "file", }, { { - id = test_filepath .. "::TestAdd", - name = "TestAdd", + id = test_filepath .. "::TestTopLevel", + name = "TestTopLevel", path = test_filepath, - range = { 5, 0, 9, 1 }, + range = { 4, 0, 8, 1 }, type = "test", }, }, + { + { + id = test_filepath .. "::TestTopLevelWithSubTest", + name = "TestTopLevelWithSubTest", + path = test_filepath, + range = { 10, 0, 16, 1 }, + type = "test", + }, + { + { + id = test_filepath .. '::TestTopLevelWithSubTest::"SubTest"', + name = '"SubTest"', + path = test_filepath, + range = { 11, 1, 15, 3 }, + type = "test", + }, + }, + }, + { + { + id = test_filepath .. "::TestTopLevelWithTableTests", + name = "TestTopLevelWithTableTests", + path = test_filepath, + range = { 18, 0, 36, 1 }, + type = "test", + }, + { + { + id = test_filepath .. '::TestTopLevelWithTableTests::"TableTest1"', + name = '"TableTest1"', + path = test_filepath, + range = { 25, 2, 25, 47 }, + type = "test", + }, + }, + { + { + id = test_filepath .. '::TestTopLevelWithTableTests::"TableTest2"', + name = '"TableTest2"', + path = test_filepath, + range = { 26, 2, 26, 47 }, + type = "test", + }, + }, + }, } -- Act @@ -31,6 +76,6 @@ describe("Discovery of test positions", function() -- Assert local result = tree:to_list() - assert.are.same(expected, result) + assert.are.same(vim.inspect(expected), vim.inspect(result)) end) end) diff --git a/tests/go/positions_test.go b/tests/go/positions_test.go index 4418b0b..cfef5aa 100644 --- a/tests/go/positions_test.go +++ b/tests/go/positions_test.go @@ -2,9 +2,36 @@ package main import "testing" -// A dummy test, just to assert that Go tests can run. -func TestAdd(t *testing.T) { +func TestTopLevel(t *testing.T) { if Add(1, 2) != 3 { t.Fail() } } + +func TestTopLevelWithSubTest(t *testing.T) { + t.Run("SubTest", func(t *testing.T) { + if Add(1, 2) != 3 { + t.Fail() + } + }) +} + +func TestTopLevelWithTableTests(t *testing.T) { + tt := []struct { + name string + x int + y int + expected int + }{ + {name: "TableTest1", x: 1, y: 2, expected: 3}, + {name: "TableTest2", x: 3, y: 4, expected: 7}, + } + + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + if Add(tc.x, tc.y) != tc.expected { + t.Fail() + } + }) + } +}