From e3066c91c1e2775814e08404b29c9a5c9e34f73b Mon Sep 17 00:00:00 2001 From: sun qirui Date: Sat, 11 Nov 2023 19:23:29 +0800 Subject: [PATCH 1/2] add Toggle between code and tests --- src/goGenerateTests.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/goGenerateTests.ts b/src/goGenerateTests.ts index 5f460d2bbc..1ae8741dc0 100644 --- a/src/goGenerateTests.ts +++ b/src/goGenerateTests.ts @@ -60,15 +60,18 @@ export const toggleTestFile: CommandFactory = () => () => { let targetFilePath = ''; if (currentFilePath.endsWith('.go')) { if (currentFilePath.endsWith('_test.go')) { - targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.go')) + '.go'; + targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.go')) + '.gop'; + if (!fs.existsSync(targetFilePath)) { + targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.go')) + '.go'; + } } else { targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('.go')) + '_test.go'; } } else { - if (currentFilePath.endsWith('_test.gop')) { - targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.gop')) + '.gop'; + if (currentFilePath.endsWith('_test.go')) { + targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.go')) + '.gop'; } else { - targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('.gop')) + '_test.gop'; + targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('.gop')) + '_test.go'; } } From dff695789e9ebdba6f52634449ab31ab49bb5305 Mon Sep 17 00:00:00 2001 From: sun qirui Date: Sat, 11 Nov 2023 19:43:29 +0800 Subject: [PATCH 2/2] add Toggle between code and tests --- src/goGenerateTests.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/goGenerateTests.ts b/src/goGenerateTests.ts index 1ae8741dc0..6fc406d238 100644 --- a/src/goGenerateTests.ts +++ b/src/goGenerateTests.ts @@ -60,18 +60,35 @@ export const toggleTestFile: CommandFactory = () => () => { let targetFilePath = ''; if (currentFilePath.endsWith('.go')) { if (currentFilePath.endsWith('_test.go')) { - targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.go')) + '.gop'; + //xx_test.go => xx.go + //xx_test.go => xx.gop + targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.go')) + '.go'; if (!fs.existsSync(targetFilePath)) { - targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.go')) + '.go'; + targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.go')) + '.gop'; } } else { + //xx.go => xx_test.go + //xx.go => xx_test.gop targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('.go')) + '_test.go'; + if (!fs.existsSync(targetFilePath)) { + targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('.go')) + '_test.gop'; + } } } else { - if (currentFilePath.endsWith('_test.go')) { - targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.go')) + '.gop'; + if (currentFilePath.endsWith('_test.gop')) { + //xx_test.gop => xx.go + //xx_test.gop => xx.gop + targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.gop')) + '.go'; + if (!fs.existsSync(targetFilePath)) { + targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.gop')) + '.gop'; + } } else { + //xx.gop => xx_test.go + //xx.gop => xx_test.gop targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('.gop')) + '_test.go'; + if (!fs.existsSync(targetFilePath)) { + targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('.gop')) + '.gop'; + } } }