1 | package main
|
---|
2 |
|
---|
3 | import "testing"
|
---|
4 |
|
---|
5 | func TestSplit2(t *testing.T) {
|
---|
6 | if a, b := split2("a:b", ":"); a != "a" || b != "b" {
|
---|
7 | t.Fail()
|
---|
8 | }
|
---|
9 | if a, b := split2(":b", ":"); a != "" || b != "b" {
|
---|
10 | t.Fail()
|
---|
11 | }
|
---|
12 | if a, b := split2("a:", ":"); a != "a" || b != "" {
|
---|
13 | t.Fail()
|
---|
14 | }
|
---|
15 | if a, b := split2(":", ":"); a != "" || b != "" {
|
---|
16 | t.Fail()
|
---|
17 | }
|
---|
18 | if a, b := split2("a", ":"); a != "a" || b != "" {
|
---|
19 | t.Fail()
|
---|
20 | }
|
---|
21 | if a, b := split2("", ":"); a != "" || b != "" {
|
---|
22 | t.Fail()
|
---|
23 | }
|
---|
24 | }
|
---|
25 |
|
---|
26 | func TestMD(t *testing.T) {
|
---|
27 | v, body := md(`
|
---|
28 | title: Hello, world!
|
---|
29 | keywords: foo, bar, baz
|
---|
30 | empty:
|
---|
31 | bayan: [:|||:]
|
---|
32 |
|
---|
33 | this: is a content`)
|
---|
34 | if v["title"] != "Hello, world!" {
|
---|
35 | t.Error()
|
---|
36 | }
|
---|
37 | if v["keywords"] != "foo, bar, baz" {
|
---|
38 | t.Error()
|
---|
39 | }
|
---|
40 | if s, ok := v["empty"]; !ok || len(s) != 0 {
|
---|
41 | t.Error()
|
---|
42 | }
|
---|
43 | if v["bayan"] != "[:|||:]" {
|
---|
44 | t.Error()
|
---|
45 | }
|
---|
46 | if body != "this: is a content" {
|
---|
47 | t.Error(body)
|
---|
48 | }
|
---|
49 |
|
---|
50 | // Test empty md
|
---|
51 | v, body = md("")
|
---|
52 | if len(v) != 0 || len(body) != 0 {
|
---|
53 | t.Error(v, body)
|
---|
54 | }
|
---|
55 |
|
---|
56 | // Test empty header
|
---|
57 | v, body = md("Hello")
|
---|
58 | if len(v) != 0 || body != "Hello" {
|
---|
59 | t.Error(v, body)
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | func TestRender(t *testing.T) {
|
---|
64 | eval := func(a []string, vars map[string]string) (string, error) {
|
---|
65 | return "hello", nil
|
---|
66 | }
|
---|
67 | vars := map[string]string{"foo": "bar"}
|
---|
68 |
|
---|
69 | if s, err := render("plain text", vars, eval); err != nil || s != "plain text" {
|
---|
70 | t.Error()
|
---|
71 | }
|
---|
72 | if s, err := render("a {{greet}} text", vars, eval); err != nil || s != "a hello text" {
|
---|
73 | t.Error()
|
---|
74 | }
|
---|
75 | if s, err := render("{{greet}} x{{foo}}z", vars, eval); err != nil || s != "hello xbarz" {
|
---|
76 | t.Error()
|
---|
77 | }
|
---|
78 | }
|
---|