mergehtml/internal/merge_test.go

44 lines
954 B
Go
Raw Permalink Normal View History

package internal
import (
"strings"
"testing"
"github.com/andreyvit/diff"
)
const baseText = `
<style>body { background: #ccc; color: black; }</style>
<header></header>
<footer></footer>
`
const pageText = `
<title>This is a title</title>
<style>p { color: red; }</style>
<header><h1>Title</h1></header>
2021-11-16 06:23:37 +00:00
<p>Body text</p>
`
const mergeText = `<!DOCTYPE html><html><head><style>body { background: #ccc; color: black; }</style>
<title>This is a title</title>
<style>p { color: red; }</style>
</head><body><header><h1>Title</h1></header>
2021-11-16 06:23:37 +00:00
<p>Body text</p>
<footer></footer>
</body></html>`
func TestMerge(t *testing.T) {
got, _, err := Merge(strings.NewReader(baseText), strings.NewReader(pageText))
if err != nil {
t.Error(err)
return
}
if got != mergeText {
//fmt.Println(got)
//t.Errorf("merge mismatch (-want, +got):\n%s", cmp.Diff(mergeText, got))
t.Errorf("merge mismatch (-want, +got):\n%s", diff.LineDiff(mergeText, got))
}
}