add unit tests

This commit is contained in:
Shreyas Goenka 2025-01-23 20:08:01 +01:00
parent 6b8e1dfff2
commit d9685ab33c
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 20 additions and 1 deletions

View File

@ -20,7 +20,7 @@ const (
)
var (
// From https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
// source: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
semverRegex = regexp.MustCompile(`(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?`)
uuidRegex = regexp.MustCompile(`[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}`)
numIdRegex = regexp.MustCompile(`[0-9]{3,}`)

View File

@ -1,6 +1,7 @@
package testdiff
import (
"runtime"
"testing"
"github.com/stretchr/testify/assert"
@ -44,3 +45,21 @@ func TestReplacement_TemporaryDirectory(t *testing.T) {
assert.Equal(t, "/tmp/.../tail", repls.Replace("/tmp/foo/bar/qux/tail"))
}
func TestReplacement_OS(t *testing.T) {
var repls ReplacementsContext
PrepareReplacementOS(t, &repls)
assert.Equal(t, "[OS]", repls.Replace(runtime.GOOS))
}
func TestReplacement_Semver(t *testing.T) {
var repls ReplacementsContext
PrepareReplacementsSemver(t, &repls)
assert.Equal(t, "[SEMVER]", repls.Replace("1.2.3"))
assert.Equal(t, "[SEMVER]", repls.Replace("1.2.3-alpha"))
assert.Equal(t, "[SEMVER]", repls.Replace("1.2.3-alpha+build"))
}