mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
markdown: Add (currently failing) test for empty body
This commit is contained in:
parent
d044e497f6
commit
fd14f257df
1 changed files with 47 additions and 22 deletions
|
@ -14,72 +14,92 @@ func check(t *testing.T, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParsers(t *testing.T) {
|
var TOML = [5]string{`
|
||||||
var TOML = [4]string{`
|
|
||||||
title = "A title"
|
title = "A title"
|
||||||
template = "default"
|
template = "default"
|
||||||
name = "value"
|
name = "value"
|
||||||
`,
|
`,
|
||||||
`+++
|
`+++
|
||||||
title = "A title"
|
title = "A title"
|
||||||
template = "default"
|
template = "default"
|
||||||
name = "value"
|
name = "value"
|
||||||
+++
|
+++
|
||||||
Page content
|
Page content
|
||||||
`,
|
`,
|
||||||
`+++
|
`+++
|
||||||
title = "A title"
|
title = "A title"
|
||||||
template = "default"
|
template = "default"
|
||||||
name = "value"
|
name = "value"
|
||||||
`,
|
`,
|
||||||
`title = "A title" template = "default" [variables] name = "value"`,
|
`title = "A title" template = "default" [variables] name = "value"`,
|
||||||
}
|
`+++
|
||||||
|
title = "A title"
|
||||||
|
template = "default"
|
||||||
|
name = "value"
|
||||||
|
+++
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
var YAML = [4]string{`
|
var YAML = [5]string{`
|
||||||
title : A title
|
title : A title
|
||||||
template : default
|
template : default
|
||||||
name : value
|
name : value
|
||||||
`,
|
`,
|
||||||
`---
|
`---
|
||||||
title : A title
|
title : A title
|
||||||
template : default
|
template : default
|
||||||
name : value
|
name : value
|
||||||
---
|
---
|
||||||
Page content
|
Page content
|
||||||
`,
|
`,
|
||||||
`---
|
`---
|
||||||
title : A title
|
title : A title
|
||||||
template : default
|
template : default
|
||||||
name : value
|
name : value
|
||||||
`,
|
`,
|
||||||
`title : A title template : default variables : name : value`,
|
`title : A title template : default variables : name : value`,
|
||||||
}
|
`---
|
||||||
var JSON = [4]string{`
|
title : A title
|
||||||
"title" : "A title",
|
template : default
|
||||||
"template" : "default",
|
name : value
|
||||||
"name" : "value"
|
---
|
||||||
`,
|
`,
|
||||||
`{
|
}
|
||||||
|
|
||||||
|
var JSON = [5]string{`
|
||||||
|
"title" : "A title",
|
||||||
|
"template" : "default",
|
||||||
|
"name" : "value"
|
||||||
|
`,
|
||||||
|
`{
|
||||||
"title" : "A title",
|
"title" : "A title",
|
||||||
"template" : "default",
|
"template" : "default",
|
||||||
"name" : "value"
|
"name" : "value"
|
||||||
}
|
}
|
||||||
Page content
|
Page content
|
||||||
`,
|
`,
|
||||||
`
|
`
|
||||||
{
|
{
|
||||||
"title" : "A title",
|
"title" : "A title",
|
||||||
"template" : "default",
|
"template" : "default",
|
||||||
"name" : "value"
|
"name" : "value"
|
||||||
`,
|
`,
|
||||||
`
|
`
|
||||||
{{
|
{
|
||||||
|
"title" :: "A title",
|
||||||
|
"template" : "default",
|
||||||
|
"name" : "value"
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
`{
|
||||||
"title" : "A title",
|
"title" : "A title",
|
||||||
"template" : "default",
|
"template" : "default",
|
||||||
"name" : "value"
|
"name" : "value"
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParsers(t *testing.T) {
|
||||||
expected := Metadata{
|
expected := Metadata{
|
||||||
Title: "A title",
|
Title: "A title",
|
||||||
Template: "default",
|
Template: "default",
|
||||||
|
@ -106,7 +126,7 @@ Page content
|
||||||
|
|
||||||
data := []struct {
|
data := []struct {
|
||||||
parser MetadataParser
|
parser MetadataParser
|
||||||
testData [4]string
|
testData [5]string
|
||||||
name string
|
name string
|
||||||
}{
|
}{
|
||||||
{&JSONMetadataParser{metadata: Metadata{Variables: make(map[string]string)}}, JSON, "json"},
|
{&JSONMetadataParser{metadata: Metadata{Variables: make(map[string]string)}}, JSON, "json"},
|
||||||
|
@ -149,6 +169,11 @@ Page content
|
||||||
if md, err = v.parser.Parse([]byte(v.testData[3])); err == nil {
|
if md, err = v.parser.Parse([]byte(v.testData[3])); err == nil {
|
||||||
t.Fatalf("Expected error for invalid metadata for %v", v.name)
|
t.Fatalf("Expected error for invalid metadata for %v", v.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// front matter but no body
|
||||||
|
if md, err = v.parser.Parse([]byte(v.testData[4])); err != nil {
|
||||||
|
t.Fatalf("Unexpected error for valid metadata but no body for %v", v.name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue