pat/internal/forms/placeholder_test.go
Martin Hebnes Pedersen d626aedeaf Refactor variable substitution
Variable substitution is essentially the same as tag insertion, so the
two features can share the same underlying implementation.
2024-04-13 07:33:20 +02:00

43 lines
949 B
Go

package forms
import (
"fmt"
"testing"
)
func TestPlaceholderReplacer(t *testing.T) {
tests := []struct {
In string
Replacer func(string) string
Expect string
}{
{
In: "<MyKey>",
Replacer: placeholderReplacer("<", ">", map[string]string{"mykey": "foobar"}),
Expect: "foobar",
},
{
In: "<mykey>",
Replacer: placeholderReplacer("<", ">", map[string]string{"MyKey": "foobar"}),
Expect: "foobar",
},
{
In: "< mykey \t>",
Replacer: placeholderReplacer("<", ">", map[string]string{"MyKey": "foobar"}),
Expect: "foobar",
},
{
In: "<var MyKey>",
Replacer: placeholderReplacer("<Var", ">", map[string]string{"mykey": "foobar"}),
Expect: "foobar",
},
}
for i, tt := range tests {
t.Run(fmt.Sprint(i), func(t *testing.T) {
if got := tt.Replacer(tt.In); got != tt.Expect {
t.Errorf("Expected %q, got %q", tt.Expect, got)
}
})
}
}