From 5dbd763ceb3f9e1be63b83a83dd93e66b5db778b Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sat, 29 Jun 2024 13:17:43 +0200 Subject: [PATCH] test: expand tests (top-level, subtests, table tests) (#66) --- tests/go/positions_spec.lua | 94 +++++++++++++++++++++++++++++++++++-- tests/go/positions_test.go | 53 ++++++++++++++++++++- 2 files changed, 140 insertions(+), 7 deletions(-) diff --git a/tests/go/positions_spec.lua b/tests/go/positions_spec.lua index 50362fdb..e5e2c28f 100644 --- a/tests/go/positions_spec.lua +++ b/tests/go/positions_spec.lua @@ -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 @@ -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) diff --git a/tests/go/positions_test.go b/tests/go/positions_test.go index 4418b0b2..60329c31 100644 --- a/tests/go/positions_test.go +++ b/tests/go/positions_test.go @@ -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() + } + }) + } + }) +}