| 491 | } |
| 492 | |
| 493 | func TestMinifyErrors(t *testing.T) { |
| 494 | errorTests := []struct { |
| 495 | html string |
| 496 | err error |
| 497 | }{ |
| 498 | {`<style>abc</style>`, test.ErrPlain}, |
| 499 | {`<p style="abc"/>`, test.ErrPlain}, |
| 500 | {`<p onclick="abc"/>`, test.ErrPlain}, |
| 501 | {`<svg></svg>`, test.ErrPlain}, |
| 502 | {`<math></math>`, test.ErrPlain}, |
| 503 | } |
| 504 | |
| 505 | m := minify.New() |
| 506 | m.AddFunc("text/css", func(_ *minify.M, w io.Writer, r io.Reader, _ map[string]string) error { |
| 507 | return test.ErrPlain |
| 508 | }) |
| 509 | m.AddFunc("application/javascript", func(_ *minify.M, w io.Writer, r io.Reader, _ map[string]string) error { |
| 510 | return test.ErrPlain |
| 511 | }) |
| 512 | m.AddFunc("image/svg+xml", func(_ *minify.M, w io.Writer, r io.Reader, _ map[string]string) error { |
| 513 | return test.ErrPlain |
| 514 | }) |
| 515 | m.AddFunc("application/mathml+xml", func(_ *minify.M, w io.Writer, r io.Reader, _ map[string]string) error { |
| 516 | return test.ErrPlain |
| 517 | }) |
| 518 | for _, tt := range errorTests { |
| 519 | t.Run(tt.html, func(t *testing.T) { |
| 520 | r := bytes.NewBufferString(tt.html) |
| 521 | w := &bytes.Buffer{} |
| 522 | err := Minify(m, w, r, nil) |
| 523 | test.T(t, err, tt.err) |
| 524 | }) |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | func TestMinifyErrorPropagation(t *testing.T) { |
| 529 | errorTests := []struct { |