Mercurial > yakumo_izuru > aya
comparison zs_test.go @ 17:0214b1b5f5eb draft
added amber and gcss compilers
author | zaitsev.serge |
---|---|
date | Sat, 29 Aug 2015 15:47:16 +0000 |
parents | cb66f5b86616 |
children | ae3116ea938b |
comparison
equal
deleted
inserted
replaced
16:be58ace6edae | 17:0214b1b5f5eb |
---|---|
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "bytes" | 4 "bytes" |
5 "fmt" | 5 "fmt" |
6 "io/ioutil" | |
6 "log" | 7 "log" |
7 "os" | 8 "os" |
8 "os/exec" | 9 "os/exec" |
9 "strings" | 10 "strings" |
10 "testing" | 11 "testing" |
29 if a, b := split2("", ":"); a != "" || b != "" { | 30 if a, b := split2("", ":"); a != "" || b != "" { |
30 t.Fail() | 31 t.Fail() |
31 } | 32 } |
32 } | 33 } |
33 | 34 |
35 func tmpfile(path, s string) string { | |
36 ioutil.WriteFile(path, []byte(s), 0644) | |
37 return path | |
38 } | |
39 | |
34 func TestMD(t *testing.T) { | 40 func TestMD(t *testing.T) { |
35 v, body := md("foo.md", ` | 41 defer os.Remove("foo.md") |
42 v, body, _ := md(tmpfile("foo.md", ` | |
36 title: Hello, world! | 43 title: Hello, world! |
37 keywords: foo, bar, baz | 44 keywords: foo, bar, baz |
38 empty: | 45 empty: |
39 bayan: [:|||:] | 46 bayan: [:|||:] |
40 | 47 |
41 this: is a content`) | 48 this: is a content`)) |
42 if v["title"] != "Hello, world!" { | 49 if v["title"] != "Hello, world!" { |
43 t.Error() | 50 t.Error() |
44 } | 51 } |
45 if v["keywords"] != "foo, bar, baz" { | 52 if v["keywords"] != "foo, bar, baz" { |
46 t.Error() | 53 t.Error() |
54 if body != "this: is a content" { | 61 if body != "this: is a content" { |
55 t.Error(body) | 62 t.Error(body) |
56 } | 63 } |
57 | 64 |
58 // Test empty md | 65 // Test empty md |
59 v, body = md("foo.md", "") | 66 v, body, _ = md(tmpfile("foo.md", "")) |
60 if len(v) != 0 || len(body) != 0 { | 67 if len(v) != 0 || len(body) != 0 { |
61 t.Error(v, body) | 68 t.Error(v, body) |
62 } | 69 } |
63 | 70 |
64 // Test empty header | 71 // Test empty header |
65 v, body = md("foo.md", "Hello") | 72 v, body, _ = md(tmpfile("foo.md", "Hello")) |
66 if len(v) != 0 || body != "Hello" { | 73 if len(v) != 0 || body != "Hello" { |
67 t.Error(v, body) | 74 t.Error(v, body) |
68 } | 75 } |
69 } | 76 } |
70 | 77 |
71 func TestRender(t *testing.T) { | 78 func TestRender(t *testing.T) { |
72 eval := func(a []string, vars map[string]string) (string, error) { | 79 eval := func(a []string, vars Vars) (string, error) { |
73 return "hello", nil | 80 return "hello", nil |
74 } | 81 } |
75 vars := map[string]string{"foo": "bar"} | 82 vars := map[string]string{"foo": "bar"} |
76 | 83 |
77 if s, err := render("plain text", vars, eval); err != nil || s != "plain text" { | 84 if s, err := render("plain text", vars, eval); err != nil || s != "plain text" { |