package jdenticon import ( "os" "path/filepath" "testing" ) func TestJavaScriptReferenceCompatibility(t *testing.T) { testCases := []struct { input string size int }{ {"test-hash", 64}, {"example1@gmail.com", 64}, {"example2@yahoo.com", 64}, } for _, tc := range testCases { t.Run(tc.input+"_"+string(rune(tc.size)), func(t *testing.T) { // Generate Go SVG goSvg, err := ToSVG(tc.input, tc.size) if err != nil { t.Fatalf("Failed to generate Go SVG: %v", err) } // Read reference JavaScript SVG var refFilename string if tc.input == "test-hash" { refFilename = "test-hash_64.svg" } else if tc.input == "example1@gmail.com" { refFilename = "example1_at_gmail_com_64.svg" } else if tc.input == "example2@yahoo.com" { refFilename = "example2_at_yahoo_com_64.svg" } refPath := filepath.Join("../reference", refFilename) refData, err := os.ReadFile(refPath) if err != nil { t.Skipf("Reference file not found: %s", refPath) return } refSvg := string(refData) // Compare if goSvg != refSvg { t.Errorf("SVG output differs from JavaScript reference") t.Logf("Go output:\n%s", goSvg) t.Logf("JS reference:\n%s", refSvg) // Save Go output for manual inspection goPath := filepath.Join("../go-output", refFilename) os.WriteFile(goPath, []byte(goSvg), 0644) t.Logf("Go output saved to: %s", goPath) } }) } }