-
Notifications
You must be signed in to change notification settings - Fork 0
/
fipmd_test.go
95 lines (78 loc) · 1.96 KB
/
fipmd_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
87
88
89
90
91
92
93
94
95
package fipmd
import (
"log"
"testing"
)
/*
func TestQuote1(t *testing.T) {
input := `>quoted line1.
>another line 2
`
el, idx := parseQuote([]byte(input))
buf := new(bytes.Buffer)
el.html(buf)
if string(buf.Bytes()) != "<blockquote><p>quoted line1.<br> another line 2</p></blockquote>" ||
idx != len(input) {
t.Log("parseQuote, output:", string(buf.Bytes()), idx, len(input))
t.FailNow()
}
}
*/
func TestParse(t *testing.T) {
input := `## Header #
text
1. >ordered 1
continue quote
2. ordered 2
>quote
* unordered 1
* unordered 2
`
out := Parse([]byte(input))
if string(out) != `<h2>Header</h2><p>text</p><ol><li><blockquote><p>ordered 1 continue quote</p></blockquote></li><li>ordered 2</li></ol><blockquote><p>quote</p></blockquote><ul><li>unordered 1</li><li>unordered 2</li></ul>` {
t.Log("TestParse, output:", string(out))
t.Fail()
}
}
func hook1(header *Header) {
log.Println("hook1", header.Tag(), header.Text())
}
func hook2(header *Header) {
log.Println("hook2", header.Tag(), header.Text())
}
func TestHook(t *testing.T) {
input := `# Header1 #
## header2`
parser := NewParser()
parser.AddHeaderHook(hook1)
parser.AddHeaderHook(hook2)
result := parser.Parse([]byte(input))
t.Log(string(result))
/*if string(buf.Bytes()) != "<h2>Header</h2>" ||
idx != 12 {
t.Log("TestHeader, output:",string(buf.Bytes()),idx)
t.Fail()
}*/
}
func TestA(t *testing.T) {
input := `>**NOTE**
>The operator -> marks a pair, a -> b equals to (a, b)`
/*2. A statement is considered not end when
The line ends in the middle of parentheses() or brackets[]
The line ends in a word that not valid as the end of a statement, such as infix operators (+, -, \*, / ...)
*/
//out := Parse([]byte(input))
//t.Logf("%s",out)
el, _ := parseQuote([]byte(input), nil)
html := el.Html()
t.Log(html)
}
func TestParseFile(t *testing.T) {
path := "test.md"
c, e := ParseFile(path)
if e != nil {
t.Log("err:", e)
} else {
t.Log(string(c))
}
}