42 lines
932 B
Go
42 lines
932 B
Go
|
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>
|
||
|
<p>Body text
|
||
|
`
|
||
|
|
||
|
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>
|
||
|
<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))
|
||
|
}
|
||
|
}
|