mirror of https://github.com/databricks/cli.git
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package testdiff
|
|
|
|
import (
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestReplacement_Literal(t *testing.T) {
|
|
var repls ReplacementsContext
|
|
|
|
repls.Set(`foobar`, `[replacement]`)
|
|
assert.Equal(t, `[replacement]`, repls.Replace(`foobar`))
|
|
}
|
|
|
|
func TestReplacement_Encoded(t *testing.T) {
|
|
var repls ReplacementsContext
|
|
|
|
repls.Set(`foo"bar`, `[replacement]`)
|
|
assert.Equal(t, `"[replacement]"`, repls.Replace(`"foo\"bar"`))
|
|
}
|
|
|
|
func TestReplacement_UUID(t *testing.T) {
|
|
var repls ReplacementsContext
|
|
|
|
PrepareReplacementsUUID(t, &repls)
|
|
|
|
assert.Equal(t, "[UUID]", repls.Replace("123e4567-e89b-12d3-a456-426614174000"))
|
|
}
|
|
|
|
func TestReplacement_Number(t *testing.T) {
|
|
var repls ReplacementsContext
|
|
|
|
PrepareReplacementsNumber(t, &repls)
|
|
|
|
assert.Equal(t, "12", repls.Replace("12"))
|
|
assert.Equal(t, "[NUMID]", repls.Replace("123"))
|
|
}
|
|
|
|
func TestReplacement_TemporaryDirectory(t *testing.T) {
|
|
var repls ReplacementsContext
|
|
|
|
PrepareReplacementsTemporaryDirectory(t, &repls)
|
|
|
|
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"))
|
|
}
|