Files
jbergner fe32431d21
Some checks failed
release-tag / release-image (push) Failing after 55s
init
2026-08-01 23:54:45 +02:00

47 lines
1.1 KiB
Go

package envfile
import (
"strings"
"testing"
)
func TestSetPreservesDocumentAndUpdatesLastDuplicate(t *testing.T) {
doc, err := Parse([]byte("# title\nA=one\nA=two\nB=3\n"))
if err != nil {
t.Fatal(err)
}
if err := doc.Set("A", "hello world"); err != nil {
t.Fatal(err)
}
got := string(doc.Render())
want := "# title\nA=one\nA=hello world\nB=3\n"
if got != want {
t.Fatalf("got %q want %q", got, want)
}
}
func TestImportMissingCopiesComments(t *testing.T) {
current, _ := Parse([]byte("A=1\n"))
example, _ := Parse([]byte("# Alpha\nA=1\n\n# Beta help\nB=2\n"))
missing, err := current.ImportMissing(example, "# imported")
if err != nil {
t.Fatal(err)
}
if len(missing) != 1 || missing[0] != "B" {
t.Fatalf("unexpected missing: %#v", missing)
}
got := string(current.Render())
if !strings.Contains(got, "# Beta help\nB=2") {
t.Fatalf("comments/value not imported: %q", got)
}
}
func TestEncodeDecode(t *testing.T) {
values := []string{"plain", "contains # hash", "line1\nline2", " leading"}
for _, value := range values {
if got := DecodeValue(EncodeValue(value)); got != value {
t.Fatalf("roundtrip %q -> %q", value, got)
}
}
}