Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions converter.go

This file was deleted.

7 changes: 7 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package textplain

import "errors"

var (
ErrBodyNotFound = errors.New("could not find a `body` element in your html document")
)
318 changes: 0 additions & 318 deletions regexp.go

This file was deleted.

27 changes: 4 additions & 23 deletions setup_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package textplain_test

import (
"reflect"
"testing"

"github.com/mailproto/textplain"
Expand All @@ -18,23 +17,12 @@ func runTestCases(t *testing.T, testCases []testCase) {
}
}

func runTestCase(t *testing.T, tc testCase, converters ...textplain.Converter) {
func runTestCase(t *testing.T, tc testCase) {
t.Helper()
if len(converters) == 0 {
converters = []textplain.Converter{textplain.NewRegexpConverter(), textplain.NewTreeConverter()}
}

for _, converter := range converters {
if tc.skipRegexp && reflect.TypeOf(converter) == reflect.TypeOf(&textplain.RegexpConverter{}) {
continue
}
t.Run(reflect.TypeOf(converter).Elem().Name(), func(tt *testing.T) {
result, err := converter.Convert(tc.body, textplain.DefaultLineLength)
assert.Nil(tt, err)
assert.Equal(tt, tc.expect, result)
})
}

result, err := textplain.Convert(tc.body, textplain.DefaultLineLength)
assert.Nil(t, err)
assert.Equal(t, tc.expect, result)
}

const html = `<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head>
Expand Down Expand Up @@ -63,13 +51,6 @@ const html = `<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "htt

<img src="https://example.com/footer-animation.gif" /></body></html>`

func BenchmarkRegexp(b *testing.B) {
converter := textplain.NewRegexpConverter()
for i := 0; i < b.N; i++ {
_, _ = converter.Convert(html, textplain.DefaultLineLength)
}
}

func BenchmarkTree(b *testing.B) {
converter := textplain.NewTreeConverter()
for i := 0; i < b.N; i++ {
Expand Down
Loading