diff --git a/__snapshots__/version-go.js b/__snapshots__/version-go.js index c494d5b96..1cf7ce2b8 100644 --- a/__snapshots__/version-go.js +++ b/__snapshots__/version-go.js @@ -1,4 +1,4 @@ -exports['version.go updateContent updates version in version.go 1'] = ` +exports['basic-update'] = ` // Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,3 +17,17 @@ package api const Version = "0.59.0" ` + +exports['double-digit-patch'] = ` +package api + +const Version = "0.58.12-rc02" + +` + +exports['prerelease-dots-dashes'] = ` +package api + +const Version = "0.58.0-rc.2" + +` diff --git a/src/updaters/go/version-go.ts b/src/updaters/go/version-go.ts index f854231bd..856a9eaf1 100644 --- a/src/updaters/go/version-go.ts +++ b/src/updaters/go/version-go.ts @@ -17,7 +17,7 @@ import {DefaultUpdater} from '../default'; export class VersionGo extends DefaultUpdater { updateContent(content: string): string { return content.replace( - /const Version = "[0-9]+\.[0-9]+\.[0-9](-\w+)?"/, + /const Version = "[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?"/, `const Version = "${this.version.toString()}"` ); } diff --git a/test/updaters/version-go.ts b/test/updaters/version-go.ts index c628a4521..e47064b15 100644 --- a/test/updaters/version-go.ts +++ b/test/updaters/version-go.ts @@ -32,7 +32,36 @@ describe('version.go', () => { version: Version.parse('0.59.0'), }); const newContent = version.updateContent(oldContent); - snapshot(newContent); + snapshot('basic-update', newContent); + }); + + it('updates prerelease version with dots and dashes in version.go', async () => { + const oldContent = 'package api\n\nconst Version = "0.58.0-rc.1"\n'; + const version = new VersionGo({ + version: Version.parse('0.58.0-rc.2'), + }); + const newContent = version.updateContent(oldContent); + snapshot('prerelease-dots-dashes', newContent); + }); + + it('updates double digit patch versions in version.go', async () => { + const oldContent = 'package api\n\nconst Version = "0.58.12-rc01"\n'; + const version = new VersionGo({ + version: Version.parse('0.58.12-rc02'), + }); + const newContent = version.updateContent(oldContent); + snapshot('double-digit-patch', newContent); + }); + + it('does not update versions with consecutive dots in prerelease in version.go', async () => { + const oldContent = 'package api\n\nconst Version = "0.58.0-rc..1"\n'; + const version = new VersionGo({ + version: Version.parse('0.58.0-rc.2'), + }); + const newContent = version.updateContent(oldContent); + if (newContent !== oldContent) { + throw new Error(`Content was modified: ${newContent}`); + } }); }); });