-
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.
- Loading branch information
Showing
7 changed files
with
117 additions
and
17 deletions.
There are no files selected for viewing
Empty file.
Empty file.
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
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,40 @@ | ||
local path = require('go_to_test_file.path') | ||
local system = require('go_to_test_file.system') | ||
local cmd = require('go_to_test_file.cmd') | ||
local list = require('go_to_test_file.list') | ||
|
||
local peer_dunder_tests = { | ||
test_folder_names = {'__tests__'} | ||
} | ||
|
||
peer_dunder_tests.find_source_file = function(source_folder, filename) | ||
local ps = path.separator(system.name()) | ||
local cmmd = cmd.cd_string(source_folder) .. " && fd --type f --max-depth=1 '" .. filename .. "' | head -1" | ||
local output = vim.fn.trim(vim.fn.system(cmmd)):gsub('^.' .. ps, '') | ||
if vim.v.shell_error ~= 0 then | ||
error(output .. ' cmmd:' .. cmmd) | ||
end | ||
if output == '' then | ||
return '' | ||
else | ||
return path.join(ps, source_folder, output) | ||
end | ||
end | ||
|
||
peer_dunder_tests.find_test_file = peer_dunder_tests.find_source_file | ||
|
||
peer_dunder_tests.folder_tests_folder = function(source_folder) | ||
local ps = path.separator(system.name()) | ||
local identifiers = string.format("^%s/?$", list.unpack(peer_dunder_tests.test_folder_names)) | ||
local cmmd = cmd.cd_string(source_folder) .. " && fd --type d --max-depth=1 '" .. identifiers .. "' | head -1" | ||
local output = vim.fn.trim(vim.fn.system(cmmd)):gsub('^.' .. ps, '') | ||
if vim.v.shell_error ~= 0 then | ||
error(output .. ' cmmd:' .. cmmd) | ||
end | ||
if output == '' then | ||
return '' | ||
else | ||
return path.join(ps, source_folder, output) | ||
end | ||
end | ||
return peer_dunder_tests |
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,22 @@ | ||
local path = require('go_to_test_file.path') | ||
local system = require('go_to_test_file.system') | ||
local list = require('go_to_test_file.list') | ||
local root_tests = require('go_to_test_file.root_tests') | ||
local peer_dunder_tests = require('go_to_test_file.peer_dunder_tests') | ||
|
||
local project = {} | ||
|
||
project.test_folder_names = vim.list_extend(vim.list_extend({}, root_tests.test_folder_names), peer_dunder_tests.test_folder_names) | ||
|
||
project.test_path_from_filepath = function(current_file_with_abs_path) | ||
local ps = path.separator(system.name) | ||
local infix_match = list.match_one(current_file_with_abs_path, project.test_folder_names, ps, ps) | ||
if infix_match == '' then | ||
return '' | ||
else | ||
local _, stop = string.find(current_file_with_abs_path, infix_match) | ||
return string.sub(current_file_with_abs_path, 1, stop):gsub(ps .. '$', '') | ||
end | ||
end | ||
|
||
return project |
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,20 @@ | ||
local assert = require('luassert') | ||
|
||
local path = require('go_to_test_file.path') | ||
local system = require('go_to_test_file.system') | ||
local cmd = require('go_to_test_file.cmd') | ||
local project = require('go_to_test_file.project') | ||
|
||
describe('project', function() | ||
describe('test_path_from_filepath', function() | ||
it('returns the abs of the test folder from the path', function() | ||
local file_folder_abs_path = path.script_path(system.name) | ||
local cmmd = cmd.cd_string(file_folder_abs_path) .. ' && git rev-parse --show-toplevel' | ||
local git_root = vim.fn.trim(vim.fn.system(cmmd)) | ||
local expected = path.join(path.separator(system.name), git_root, 'spec') | ||
local tst = path.join(path.separator(system.name), file_folder_abs_path, 'project_spec.lua') | ||
local actual = project.test_path_from_filepath(tst) | ||
assert.are.equal(expected, actual) | ||
end) | ||
end) | ||
end) |