(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestDocumentParsing(t *testing.T) { |
| 15 | testImagesPath, err := filepath.Abs("../testdata/test-images/svg-test-suite") |
| 16 | require.NoError(t, err) |
| 17 | |
| 18 | err = filepath.Walk(testImagesPath, func(path string, info os.FileInfo, err error) error { |
| 19 | require.NoError(t, err) |
| 20 | |
| 21 | // Skip directories |
| 22 | if info.IsDir() { |
| 23 | return nil |
| 24 | } |
| 25 | |
| 26 | // Skip non-SVG files |
| 27 | if filepath.Ext(path) != ".svg" { |
| 28 | return nil |
| 29 | } |
| 30 | |
| 31 | // Open the SVG file |
| 32 | file, err := os.Open(path) |
| 33 | require.NoError(t, err) |
| 34 | defer file.Close() |
| 35 | |
| 36 | // Parse the document |
| 37 | doc1, err := xmlparser.NewDocument(file) |
| 38 | require.NoError(t, err, "Failed to parse SVG: %s", path) |
| 39 | |
| 40 | // Write the document back to a buffer |
| 41 | buf := new(bytes.Buffer) |
| 42 | err = doc1.WriteTo(buf) |
| 43 | require.NoError(t, err, "Failed to write SVG: %s", path) |
| 44 | |
| 45 | // Parse the document again from the written buffer |
| 46 | doc2, err := xmlparser.NewDocument(buf) |
| 47 | require.NoError(t, err, "Failed to re-parse SVG: %s", path) |
| 48 | |
| 49 | // Ensure that the two documents are equivalent |
| 50 | require.Equal(t, doc1, doc2, "Documents do not match after re-parsing: %s", path) |
| 51 | |
| 52 | return nil |
| 53 | }) |
| 54 | |
| 55 | require.NoError(t, err) |
| 56 | } |
| 57 | |
| 58 | func TestEntityReplacement(t *testing.T) { |
| 59 | svgData := []byte(`<?xml version="1.0"?> |
nothing calls this directly
no test coverage detected