-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd2html_test.go
110 lines (88 loc) · 2.59 KB
/
md2html_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
/*
find files in the pattern of name.ext and roll them back to name.num.ext. Any name.num.ext should also be rolled back by one
*/
import (
"bytes"
"strings"
"testing"
//"time"
)
/******************************************************************************/
func init() {
}
func TestNow(t *testing.T) {
td := TemplateData{
Title: "Page Title",
SafeTitle: "page_title",
Content: "<b>content</b>",
Date: "2023-05-10 07:47 PM",
Path: "some-file-here"}
if td.Exists("null") {
t.Errorf("File should not exist")
}
td.Path = "/dev"
if !td.Exists("null") {
t.Errorf("File does not exist")
}
if len(td.Random("fish")) > 0 {
t.Errorf("value when there should not be")
}
}
func TestBurnList(t *testing.T) {
burn := BurnList{}
//empty tests
if !burn.Available(42) {
t.Errorf("42 should be available")
}
if burn.Burned(42) {
t.Errorf("no number should be burned yet")
}
for i := 0 ; i < 9 ; i++ {
burn.Burn(i)
}
if !burn.Available(9) {
t.Errorf("last one not available: %v", burn)
}
if len(burn) != 9 {
t.Errorf("9 items, 0-8 should be burned: %v", burn)
}
actual := burn.NotRepeated(10)
if 9 != actual {
t.Errorf("last number not available %d %v.", actual, burn)
}
if len(burn) != 10 {
t.Errorf("10 items, 0-9 should be burned: %v", burn)
}
actual = burn.NotRepeated(10)
if actual != -1 {
t.Errorf("9 items already burned: %v", burn)
}
}
func TestRender(t *testing.T) {
data := TemplateData{
Title: "Page Title",
SafeTitle: "page_title",
Content: "<b>content</b>",
Date: "2023-05-10 07:47 PM",
Path: "some-file-here"}
test := func(msg, input, expected, logMsg string) bool {
var output bytes.Buffer
Log.Error.SetOutput(&output)
Log.Warn.SetOutput(&output)
actual := Render(input, data)
if expected != actual {
t.Errorf("%s: '%s' vs '%s'", msg, expected, actual)
}
if !strings.Contains(output.String(), logMsg) {
t.Errorf("%s: '%s' vs '%s'", msg, logMsg, output.String())
}
return true
}
test("Title", "* {{.Title}}", "* Page Title", "")
test("Safe Title", "* {{.SafeTitle}}", "* page_title", "")
test("Content", "`{{.Content}}`", "`<b>content</b>`", "")
test("Date", "{{.Date}}", "2023-05-10 07:47 PM", "")
test("Error", "{{.Fake}}", "",
"can't evaluate field Fake in type main.TemplateData")
}