Skip to content

Commit

Permalink
test: expand tests (top-level, subtests, table tests) (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil authored Jun 29, 2024
1 parent b31607b commit 5dbd763
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 7 deletions.
94 changes: 89 additions & 5 deletions tests/go/positions_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,102 @@ 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, 59, 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",
},
},
},
{
{
id = test_filepath .. "::TestTopLevelWithSubTestWithTableTests",
name = "TestTopLevelWithSubTestWithTableTests",
path = test_filepath,
range = { 38, 0, 58, 1 },
type = "test",
},
{
{
id = test_filepath
.. '::TestTopLevelWithSubTestWithTableTests::"SubTest"',
name = '"SubTest"',
path = test_filepath,
range = { 39, 1, 57, 3 },
type = "test",
},
{
{
id = test_filepath
.. '::TestTopLevelWithSubTestWithTableTests::"SubTest"::"TableTest1"',
name = '"TableTest1"',
path = test_filepath,
range = { 46, 3, 46, 48 },
type = "test",
},
},
{
{
id = test_filepath
.. '::TestTopLevelWithSubTestWithTableTests::"SubTest"::"TableTest2"',
name = '"TableTest2"',
path = test_filepath,
range = { 47, 3, 47, 48 },
type = "test",
},
},
},
},
}

-- Act
Expand All @@ -31,6 +115,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)
53 changes: 51 additions & 2 deletions tests/go/positions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,58 @@ 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()
}
})
}
}

func TestTopLevelWithSubTestWithTableTests(t *testing.T) {
t.Run("SubTest", func(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()
}
})
}
})
}

0 comments on commit 5dbd763

Please sign in to comment.