Skip to content

Commit

Permalink
Merge pull request #24 from sunqirui1987/goplus
Browse files Browse the repository at this point in the history
add Toggle between code and tests
  • Loading branch information
xushiwei authored Nov 11, 2023
2 parents 7a292e6 + dff6957 commit fc7b918
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/goGenerateTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,35 @@ export const toggleTestFile: CommandFactory = () => () => {
let targetFilePath = '';
if (currentFilePath.endsWith('.go')) {
if (currentFilePath.endsWith('_test.go')) {
//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')) + '.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.gop')) {
targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('_test.gop')) + '.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 {
targetFilePath = currentFilePath.substr(0, currentFilePath.lastIndexOf('.gop')) + '_test.gop';
//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';
}
}
}

Expand Down

0 comments on commit fc7b918

Please sign in to comment.