From d9685ab33cbc67450a288e965b52c876be485fda Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Thu, 23 Jan 2025 20:08:01 +0100 Subject: [PATCH] add unit tests --- libs/testdiff/replacement.go | 2 +- libs/testdiff/replacement_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libs/testdiff/replacement.go b/libs/testdiff/replacement.go index 60f4695a0..634259085 100644 --- a/libs/testdiff/replacement.go +++ b/libs/testdiff/replacement.go @@ -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,}`) diff --git a/libs/testdiff/replacement_test.go b/libs/testdiff/replacement_test.go index 1b6c5fe2d..3fddd67b9 100644 --- a/libs/testdiff/replacement_test.go +++ b/libs/testdiff/replacement_test.go @@ -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")) +}