diff options
author | clsr <clsr@clsr.net> | 2017-08-18 13:45:49 +0200 |
---|---|---|
committer | clsr <clsr@clsr.net> | 2017-08-18 13:45:49 +0200 |
commit | 26248678aafc2f8e277d4bdafc116f2b349b02c5 (patch) | |
tree | 15f82488edb8c05aae756443284731875f36737c /write_test.go | |
download | cnm-go-26248678aafc2f8e277d4bdafc116f2b349b02c5.tar.gz cnm-go-26248678aafc2f8e277d4bdafc116f2b349b02c5.zip |
Initial commitv0.1.0
Diffstat (limited to 'write_test.go')
-rw-r--r-- | write_test.go | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/write_test.go b/write_test.go new file mode 100644 index 0000000..fc13459 --- /dev/null +++ b/write_test.go @@ -0,0 +1,218 @@ +package cnm + +import ( + "bytes" + "testing" +) + +var writeTests = map[string]*Document{ + "": &Document{}, + + "title\n\tfoo bar\n": &Document{ + Title: "foo bar", + }, + + "title\n\tfoo bar baz\n" + + "links\n\tqwe asd\n\tzxc 123\n\tfoo\n" + + "site\n\tfoo\n\t\tbar\n\t\tbaz/quux\n\t\t\t123\n\ttest\n": &Document{ + Title: "foo bar baz", + Links: []Link{ + Link{"qwe", "asd", ""}, + Link{"zxc", "123", ""}, + Link{"foo", "", ""}, + }, + Site: Site{ + Children: []Site{ + Site{ + Path: "foo", + Children: []Site{ + Site{Path: "bar"}, + Site{ + Path: "baz/quux", + Children: []Site{ + Site{Path: "123"}, + }, + }, + }, + }, + Site{Path: "test"}, + }, + }, + }, + + `title + Test document +content + section Test section + text + This is \n just a + text pre + t e + s t + + raw text/plain + of various \n features + section of the + table + header + text + Column 1 + text + Column 2 + row + text + CNM + text + document + + format + row + section + list + text + ipsum + list ordered + list unordered + text + dolor + + sit amet + embed text/cnm cnp://example.com/ + thing whatever +`: &Document{ + Title: "Test document", + Content: &ContentBlock{ + name: "content", + args: nil, + children: []Block{ + &SectionBlock{ContentBlock{ + name: "section", + args: []string{"Test", "section"}, + children: []Block{ + &TextBlock{ + Contents: TextPlainContents{[]string{ + "This is \n just a", + }}, + }, + &TextBlock{ + Format: "pre", + Contents: TextPreContents{ + " t e \n s t \n\t", + }, + }, + &RawBlock{ + Syntax: "text/plain", + Contents: "of various \\n features", + }, + &SectionBlock{ContentBlock{ + name: "section", + args: []string{"of the"}, + children: []Block{ + &TableBlock{[]Block{ + &HeaderBlock{ContentBlock{ + name: "header", + args: []string{}, + children: []Block{ + &TextBlock{ + Contents: TextPlainContents{[]string{ + "Column 1", + }}, + }, + &TextBlock{ + Contents: TextPlainContents{[]string{ + "Column 2", + }}, + }, + }, + }}, + &RowBlock{ContentBlock{ + name: "row", + args: []string{}, + children: []Block{ + &TextBlock{ + Contents: TextPlainContents{[]string{ + "CNM", + }}, + }, + &TextBlock{ + Contents: TextPlainContents{[]string{ + "document", + "format", + }}, + }, + }, + }}, + &RowBlock{ContentBlock{ + name: "row", + args: []string{""}, + children: []Block{ + &SectionBlock{ContentBlock{ + name: "section", + args: []string{"", "", ""}, + }}, + &ListBlock{ContentBlock{ + name: "list", + args: nil, + children: []Block{ + &TextBlock{ + Contents: TextPlainContents{[]string{ + "ipsum", + }}, + }, + &ListBlock{ContentBlock{ + name: "list", + args: []string{"ordered"}, + children: []Block{ + &ListBlock{ContentBlock{ + name: "list", + args: []string{"unordered"}, + children: []Block{ + &TextBlock{ + Contents: TextPlainContents{[]string{ + "dolor", + "sit amet", + }}, + }, + }, + }}, + }, + }}, + }, + }}, + }, + }}, + }}, + }, + }}, + }, + }}, + &EmbedBlock{ + Type: "text/cnm", + URL: "cnp://example.com/", + Description: "thing whatever", + }, + }, + }, + }, +} + +func TestWrite(t *testing.T) { + for k, v := range writeTests { + t.Run(k, func(t *testing.T) { + var buf bytes.Buffer + err := v.Write(&buf) + if err != nil { + t.Fatalf("Write error: %v", err) + } + w := buf.String() + t.Log("====================") + t.Log("expected:\n" + k) + t.Log("--------------------") + t.Log(" got:\n" + w) + t.Log("====================") + if k != w { + t.Fatal("Write: output did not match expected document") + } + }) + } +} |