summaryrefslogtreecommitdiffstats
path: root/parse_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'parse_test.go')
-rw-r--r--parse_test.go64
1 files changed, 47 insertions, 17 deletions
diff --git a/parse_test.go b/parse_test.go
index 3fbf0f6..fc0ef87 100644
--- a/parse_test.go
+++ b/parse_test.go
@@ -125,6 +125,19 @@ var parseTests = map[string]*Document{
},
},
+ "content\n\ttext __nonexistent__\n\t\tqwe zxc\n\n\t\tasd\\n123": &Document{
+ Content: &ContentBlock{
+ name: "content",
+ args: nil,
+ children: []Block{
+ &TextBlock{
+ Format: "__nonexistent__",
+ Contents: TextRawContents{"qwe zxc\n\nasd\\n123"},
+ },
+ },
+ },
+ },
+
"content\n\tnosuchblock\n\tsection test\n": &Document{
Content: &ContentBlock{
name: "content",
@@ -360,7 +373,7 @@ content
},
&RawBlock{
Syntax: "text/plain",
- Contents: "of various \\n features",
+ Contents: TextRawContents{"of various \\n features"},
},
&SectionBlock{ContentBlock{
name: "section",
@@ -462,7 +475,7 @@ func TestParse(t *testing.T) {
t.Fatalf("ParseDocument(%q): error: %v", k, err)
}
if !documentEqual(d, v) {
- t.Fatalf("ParseDocument(%q):\nexpected:\n%#v\n got:\n%#v", k, v, d)
+ t.Fatalf("ParseDocument(%q):\nexpected:\n%#v\n got:\n%#v\n\n%#v\n%#v", k, v, d, v.Content.Children()[0], d.Content.Children()[0])
}
})
}
@@ -591,15 +604,9 @@ func contentBlockEqual(a, b *ContentBlock) bool {
if a.Name() != b.Name() {
return false
}
- aa, ba := a.Args(), b.Args()
- if len(aa) != len(ba) {
+ if !argsEqual(a.Args(), b.Args()) {
return false
}
- for i := range aa {
- if aa[i] != ba[i] {
- return false
- }
- }
ca, cb := a.Children(), b.Children()
if len(ca) != len(cb) {
return false
@@ -612,12 +619,24 @@ func contentBlockEqual(a, b *ContentBlock) bool {
return true
}
+func argsEqual(a, b []string) bool {
+ if len(a) != len(b) {
+ return false
+ }
+ for i := range a {
+ if a[i] != b[i] {
+ return false
+ }
+ }
+ return true
+}
+
func sectionBlockEqual(a, b *SectionBlock) bool {
- return contentBlockEqual(&a.ContentBlock, &b.ContentBlock)
+ return a.Title() == b.Title() && contentBlockEqual(&a.ContentBlock, &b.ContentBlock)
}
func textBlockEqual(a, b *TextBlock) bool {
- if a.Format != b.Format {
+ if !argsEqual(a.Args(), b.Args()) {
return false
}
return textContentsEqual(a.Contents, b.Contents)
@@ -639,7 +658,14 @@ func textContentsEqual(a, b TextContents) bool {
}
return textPreContentsEqual(va, vb)
- default:
+ case TextRawContents:
+ vb, ok := b.(TextRawContents)
+ if !ok {
+ return false
+ }
+ return textRawContentsEqual(va, vb)
+
+ default: // handle unknown contents, e.g. text fmt
return reflect.TypeOf(a) == reflect.TypeOf(b) && reflect.DeepEqual(a, b)
}
}
@@ -660,16 +686,20 @@ func textPreContentsEqual(a, b TextPreContents) bool {
return a == b
}
+func textRawContentsEqual(a, b TextRawContents) bool {
+ return a.Text == b.Text
+}
+
func rawBlockEqual(a, b *RawBlock) bool {
- return *a == *b
+ return argsEqual(a.Args(), b.Args()) && textRawContentsEqual(a.Contents, b.Contents)
}
func listBlockEqual(a, b *ListBlock) bool {
- return contentBlockEqual(&a.ContentBlock, &b.ContentBlock)
+ return a.Ordered() == b.Ordered() && contentBlockEqual(&a.ContentBlock, &b.ContentBlock)
}
func tableBlockEqual(a, b *TableBlock) bool {
- ra, rb := a.Rows(), b.Rows()
+ ra, rb := a.Children(), b.Children()
if len(ra) != len(rb) {
return false
}
@@ -678,7 +708,7 @@ func tableBlockEqual(a, b *TableBlock) bool {
return false
}
}
- return true
+ return argsEqual(a.Args(), b.Args())
}
func rowBlockEqual(a, b *RowBlock) bool {
@@ -690,5 +720,5 @@ func headerBlockEqual(a, b *HeaderBlock) bool {
}
func embedBlockEqual(a, b *EmbedBlock) bool {
- return *a == *b
+ return argsEqual(a.Args(), b.Args())
}