2025-01-15 11:15:23 +00:00
|
|
|
package testdiff
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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)
|
|
|
|
|
2025-01-24 11:03:11 +00:00
|
|
|
assert.Equal(t, "<UUID>", repls.Replace("123e4567-e89b-12d3-a456-426614174000"))
|
2025-01-15 11:15:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReplacement_Number(t *testing.T) {
|
|
|
|
var repls ReplacementsContext
|
|
|
|
|
|
|
|
PrepareReplacementsNumber(t, &repls)
|
|
|
|
|
|
|
|
assert.Equal(t, "12", repls.Replace("12"))
|
2025-01-24 11:03:11 +00:00
|
|
|
assert.Equal(t, "<NUMID>", repls.Replace("123"))
|
2025-01-15 11:15:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReplacement_TemporaryDirectory(t *testing.T) {
|
|
|
|
var repls ReplacementsContext
|
|
|
|
|
|
|
|
PrepareReplacementsTemporaryDirectory(t, &repls)
|
|
|
|
|
|
|
|
assert.Equal(t, "/tmp/.../tail", repls.Replace("/tmp/foo/bar/qux/tail"))
|
|
|
|
}
|