-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
86 lines (73 loc) · 2.11 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"bytes"
"errors"
"io/fs"
"os"
"testing"
"github.com/rcrowley/mergician/files"
"github.com/rcrowley/mergician/html"
)
func TestMain(t *testing.T) {
stdout := &bytes.Buffer{}
Main([]string{"mergician", "html/testdata/template.html", "html/testdata/article.html"}, os.Stdin, stdout)
actual := stdout.String()
expected := testTemplatePlusArticleHTML(t)
if actual != expected {
t.Fatalf("actual: %s != expected: %s", actual, expected)
}
}
func TestParseMergeHTML(t *testing.T) {
in, err := files.ParseSlice([]string{"html/testdata/template.html", "html/testdata/article.html"})
if err != nil {
t.Fatal(err)
}
out, err := html.Merge(in, html.DefaultRules())
if err != nil {
t.Fatal(err)
}
actual := html.String(out)
expected := testTemplatePlusArticleHTML(t)
if actual != expected {
t.Fatalf("actual: %s != expected: %s", actual, expected)
}
//t.Log(html.String(out))
}
func TestParseMergeMarkdown(t *testing.T) {
// Remove the HTML and hash files. We're cheating and reusing a file from
// another test and this ensures we don't encounter conflicts.
if err := os.Remove("testdata/test.html"); err != nil && !errors.Is(err, fs.ErrNotExist) {
t.Fatal(err)
}
if err := os.Remove("testdata/.test.html.sha256"); err != nil && !errors.Is(err, fs.ErrNotExist) {
t.Fatal(err)
}
in, err := files.ParseSlice([]string{"html/testdata/template.html", "testdata/test.md"})
if err != nil {
t.Fatal(err)
}
out, err := html.Merge(in, html.DefaultRules())
if err != nil {
t.Fatal(err)
}
actual := html.String(out)
expected := testTemplatePlusTestHTML(t) // <article>-in-<article> is weird but just an artifact of this specific test harness
if actual != expected {
t.Fatalf("actual: %s != expected: %s", actual, expected)
}
//t.Log(html.String(out))
}
func testTemplatePlusArticleHTML(t *testing.T) string {
b, err := os.ReadFile("html/testdata/template+article.html")
if err != nil {
t.Fatal(err)
}
return string(b)
}
func testTemplatePlusTestHTML(t *testing.T) string {
b, err := os.ReadFile("testdata/template+test.html")
if err != nil {
t.Fatal(err)
}
return string(b)
}