| 526 | } |
| 527 | |
| 528 | func TestMinifyErrorPropagation(t *testing.T) { |
| 529 | errorTests := []struct { |
| 530 | html string |
| 531 | err string |
| 532 | }{ |
| 533 | {"line\n<script><</script>", "unexpected < in expression on line 2 and column 9"}, |
| 534 | {"line\n<script> <</script>", "unexpected < in expression on line 2 and column 10"}, |
| 535 | {"<div onclick='<'>", "unexpected < in expression on line 1 and column 15"}, |
| 536 | } |
| 537 | |
| 538 | m := minify.New() |
| 539 | m.AddFunc("application/javascript", js.Minify) |
| 540 | for _, tt := range errorTests { |
| 541 | t.Run(tt.html, func(t *testing.T) { |
| 542 | r := bytes.NewBufferString(tt.html) |
| 543 | w := &bytes.Buffer{} |
| 544 | err := Minify(m, w, r, nil) |
| 545 | if err == nil { |
| 546 | test.Fail(t) |
| 547 | } |
| 548 | errMessage := err.Error() |
| 549 | if i := strings.IndexByte(errMessage, '\n'); i != -1 { |
| 550 | errMessage = errMessage[:i] |
| 551 | } |
| 552 | test.String(t, errMessage, tt.err) |
| 553 | }) |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | //////////////////////////////////////////////////////////////// |
| 558 | |