Skip to content

Commit

Permalink
Go: Add UnformatSemVer function
Browse files Browse the repository at this point in the history
  • Loading branch information
mbg committed May 8, 2024
1 parent 8a9fd8c commit dfa2319
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions go/extractor/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,12 @@ func FormatSemVer(version string) string {

return version
}

// Removes "v" from `semver`, if present.
func UnformatSemVer(semver string) string {
if strings.HasPrefix(semver, "v") {
return semver[1:]
}

return semver
}
7 changes: 7 additions & 0 deletions go/extractor/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ func TestFormatSemVer(t *testing.T) {
t.Errorf("Expected FormatSemVer(\"%s\") to be \"%s\", but got \"%s\".", pair.Input, pair.Expected, actual)
}
}

for _, pair := range tests {
actual := UnformatSemVer(pair.Input)
if actual != pair.Expected[1:] {
t.Errorf("Expected UnformatSemVer(\"%s\") to be \"%s\", but got \"%s\".", pair.Input, pair.Expected, actual)
}
}
}

0 comments on commit dfa2319

Please sign in to comment.