2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.extractFunctionName = exports.toogleTests = exports.generateTestsFunction = exports.generateTestsExported = exports.generateTestsAll = void 0;
4 const coc_nvim_1 = require("coc.nvim");
5 const vscode_uri_1 = require("vscode-uri");
6 const tools_1 = require("./tools");
7 const binaries_1 = require("../binaries");
8 ////////////////////////////////////////////////////////////////////////////////
9 async function generateTestsAll(document) {
10 if (isTest(document)) {
11 coc_nvim_1.window.showMessage("Document is a test file", "error");
14 await runGotests(document, ["-all"]) && await openTests(document);
16 exports.generateTestsAll = generateTestsAll;
17 async function generateTestsExported(document) {
18 if (isTest(document)) {
19 coc_nvim_1.window.showMessage("Document is a test file", "error");
22 await runGotests(document, ["-exported"]) && await openTests(document);
24 exports.generateTestsExported = generateTestsExported;
25 async function generateTestsFunction(document) {
26 if (isTest(document)) {
27 coc_nvim_1.window.showMessage("Document is a test file", "error");
30 const { line } = await coc_nvim_1.window.getCursorPosition();
31 const text = await document.getText({
32 start: { line, character: 0 },
33 end: { line, character: Infinity },
35 coc_nvim_1.window.showMessage(text);
36 const funcName = extractFunctionName(text);
38 coc_nvim_1.window.showMessage("No function found", "error");
41 await runGotests(document, ["-only", `^${funcName}$`]) && await openTests(document);
43 exports.generateTestsFunction = generateTestsFunction;
44 async function toogleTests(document) {
45 const targetURI = isTest(document)
48 return coc_nvim_1.workspace.openResource(targetURI);
50 exports.toogleTests = toogleTests;
51 ////////////////////////////////////////////////////////////////////////////////
52 async function openTests(document) {
53 return coc_nvim_1.workspace.openResource(testURI(document));
55 function isTest(document) {
56 return document.uri.endsWith('_test.go');
58 function testURI(document) {
59 return document.uri.replace(/(_test)?\.go$/, '_test.go');
61 function sourceURI(document) {
62 return document.uri.replace(/(_test)?\.go$/, '.go');
64 async function runGotests(document, args) {
65 const config = coc_nvim_1.workspace.getConfiguration().get('go.tests', {});
66 args.push(...(config.generateFlags || []), '-w', vscode_uri_1.URI.parse(document.uri).fsPath);
68 const stdout = await (0, tools_1.execTool)(binaries_1.GOTESTS, args);
69 coc_nvim_1.window.showMessage(stdout || "");
73 coc_nvim_1.window.showMessage(`Error: ${err}`, "error");
77 ////////////////////////////////////////////////////////////////////////////////
78 function extractFunctionName(line) {
79 const m = /^func +(\([^)]+\) +)?([^\s(]+)/.exec(line);
84 exports.extractFunctionName = extractFunctionName;
85 //# sourceMappingURL=tests.js.map