forked from rcasia/neotest-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'rcasia:main' into main
- Loading branch information
Showing
3 changed files
with
85 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
local TEST_CLASS_PATTERNS = { | ||
"Test$", | ||
"Tests$", | ||
"Spec$", | ||
"IT$", | ||
} | ||
|
||
return TEST_CLASS_PATTERNS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,65 @@ | ||
---@diagnostic disable: undefined-field | ||
local async = require("nio").tests | ||
local a = require("nio").tests | ||
local resolve_qualified_name = require("neotest-java.util.resolve_qualified_name") | ||
|
||
local cwd = vim.fn.getcwd() | ||
local EXAMPLE_FILEPATH = cwd .. "/tests/fixtures/maven-demo/src/test/java/com/example/ExampleTest.java" | ||
local EXAMPLE_PACKAGE = "com.example.ExampleTest" | ||
local BAD_EXAMPLE_FILEPATH = cwd .. "/tests/fixtures/maven-demo/src/test/java/com/example/NonExistentTest.java" | ||
describe("resolve_qualified_name", function() | ||
local tmp_files | ||
|
||
describe("resolve_qualified_name function", function() | ||
async.it("it should resolve package from filename", function() | ||
assert.are.equal(EXAMPLE_PACKAGE, resolve_qualified_name(EXAMPLE_FILEPATH)) | ||
before_each(function() | ||
tmp_files = {} | ||
end) | ||
|
||
async.it("it should error when file does not exist", function() | ||
after_each(function() | ||
-- clear temporary files | ||
for _, file in ipairs(tmp_files) do | ||
os.remove(file) | ||
end | ||
end) | ||
|
||
---@param content string | ||
---@return string filename | ||
local function create_tmp_file(content) | ||
local tmp_file = os.tmpname() | ||
table.insert(tmp_files, tmp_file) | ||
local file = assert(io.open(tmp_file, "w")) | ||
file:write(content) | ||
file:close() | ||
return tmp_file | ||
end | ||
|
||
local testcases = { | ||
{ | ||
input = [[ | ||
package com.example; | ||
class ExampleTest {} | ||
]], | ||
expected = "com.example.ExampleTest", | ||
}, | ||
{ | ||
input = [[ | ||
package com.example; | ||
class SomeConfig {} | ||
class ExampleTest {} | ||
]], | ||
expected = "com.example.ExampleTest", | ||
}, | ||
} | ||
|
||
for _, case in ipairs(testcases) do | ||
a.it("should resolve the qualified name of a file", function() | ||
local result = resolve_qualified_name(create_tmp_file(case.input)) | ||
|
||
assert.are.same(case.expected, result) | ||
end) | ||
end | ||
|
||
a.it("it should error when file does not exist", function() | ||
local bad_example_filepath = "some-fake-filename" | ||
assert.has_error(function() | ||
resolve_qualified_name(BAD_EXAMPLE_FILEPATH) | ||
end, string.format("file does not exist: %s", BAD_EXAMPLE_FILEPATH)) | ||
resolve_qualified_name(bad_example_filepath) | ||
end, string.format("file does not exist: %s", bad_example_filepath)) | ||
end) | ||
end) |