package qrcode import ( "bytes" "strings" "testing" ) func TestEncodeSVG_Basics(t *testing.T) { svg, err := EncodeSVG("https://atmoquest/c/did:plc:abc", DefaultOptions()) if err != nil { t.Fatalf("EncodeSVG: %v", err) } s := string(svg) if !strings.HasPrefix(s, "") { t.Error("missing closing tag") } } func TestEncodeSVG_DeterministicForSameInput(t *testing.T) { a, err := EncodeSVG("https://atmoquest/c/did:plc:abc", DefaultOptions()) if err != nil { t.Fatalf("first encode: %v", err) } b, err := EncodeSVG("https://atmoquest/c/did:plc:abc", DefaultOptions()) if err != nil { t.Fatalf("second encode: %v", err) } if !bytes.Equal(a, b) { t.Error("same input produced different SVG bytes") } } func TestEncodeSVG_ContentChangesShape(t *testing.T) { a, _ := EncodeSVG("aaaa", DefaultOptions()) b, _ := EncodeSVG("bbbb", DefaultOptions()) if bytes.Equal(a, b) { t.Error("different content produced identical SVG") } } func TestEncodeSVG_CustomColors(t *testing.T) { opts := DefaultOptions() opts.Foreground = "#ff00ff" opts.Background = "#00ff00" svg, err := EncodeSVG("test", opts) if err != nil { t.Fatalf("EncodeSVG: %v", err) } s := string(svg) if !strings.Contains(s, "#ff00ff") || !strings.Contains(s, "#00ff00") { t.Errorf("custom colors not present: %s", s[:200]) } } func TestEncodeSVG_DefaultsApplied(t *testing.T) { // Pass an empty options struct; defaults should be filled in and no // error. svg, err := EncodeSVG("hello", SVGOptions{}) if err != nil { t.Fatalf("EncodeSVG with empty opts: %v", err) } s := string(svg) if !strings.Contains(s, "#11111b") { t.Errorf("expected default foreground #11111b in SVG; got: %.200s", s) } if !strings.Contains(s, "#cdd6f4") { t.Errorf("expected default background #cdd6f4 in SVG; got: %.200s", s) } }