comparison zs_test.go @ 0:45a9e1fac18e draft

initial commit
author zaitsev.serge
date Fri, 05 Dec 2014 16:59:56 +0000
parents
children d647affd8ae9
comparison
equal deleted inserted replaced
-1:000000000000 0:45a9e1fac18e
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
51 func TestRender(t *testing.T) {
52 eval := func(a []string) ([]byte, error) {
53 return []byte("hello"), nil
54 }
55 vars := map[string]string{"foo": "bar"}
56
57 if s, err := render("plain text", vars, eval); err != nil || s != "plain text" {
58 t.Error()
59 }
60 if s, err := render("a {{greet}} text", vars, eval); err != nil || s != "a hello text" {
61 t.Error()
62 }
63 if s, err := render("{{greet}} x{{foo}}z", vars, eval); err != nil || s != "hello xbarz" {
64 t.Error()
65 }
66 }