-
Notifications
You must be signed in to change notification settings - Fork 0
/
werich_test.go
49 lines (45 loc) · 1.08 KB
/
werich_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
package werich
import (
"bytes"
"encoding/json"
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
"golang.org/x/net/html"
)
type metaData struct {
ID string
Date string
Title string
Author string
Tags []string
}
func TestRun(t *testing.T) {
input, err := ioutil.ReadFile("test.md")
if err != nil {
t.Error(err)
}
md := NewMD(input)
// meta
var meta = new(metaData)
assert.Nil(t, md.Meta(meta))
assert.Equal(t, "", meta.ID)
assert.Equal(t, "2018-11-20 14:14", meta.Date, "date fail")
assert.Equal(t, "WeRich Test", meta.Title, "title fail")
assert.Equal(t, "Muninn", meta.Author, "author fail")
assert.Equal(t, []string{"golang", "wechat"}, meta.Tags, "tag fail")
// html
div := md.HTML()
// t.Log(string(div))
_, err = html.Parse(bytes.NewReader(div))
assert.Nil(t, err, "html fail")
// rich
rich := md.Rich()
// t.Log(string(rich))
dst, err := ioutil.ReadFile("test.txt")
assert.Equal(t, rich, dst, "rich text fail")
var pretty bytes.Buffer
err = json.Indent(&pretty, rich, "", " ")
assert.Nil(t, err, "pretty fail")
// t.Log(pretty.String())
}