step/frontmatter_test.go

53 lines
1.3 KiB
Go

package step
import "testing"
const quickBrownFox = "The quick brown fox jumped over the lazy dog."
func TestSplitFrontMatter (test *testing.T) {
correctBody :=
`this is some sample text
---
theres another hr that shouldnt
break anything
break: anything
`
frontMatter, body, err := SplitFrontMatter(
`---
FOO: baR
fOoo: Bar
Shouldn't break anything: ---
this : that
Sentence: ` + quickBrownFox + `
---
` + correctBody)
if err != nil {
test.Fatal(err)
}
test.Log("BODY:")
test.Log(body)
if body != correctBody {
test.Fatal("body is not correct")
}
test.Log("FRONT MATTER:")
test.Log(frontMatter)
value0, ok := frontMatter["foo"]
if !ok { test.Fatal("missing key") }
value1, ok := frontMatter["fooo"]
if !ok { test.Fatal("missing key") }
value2, ok := frontMatter["shouldn't break anything"]
if !ok { test.Fatal("missing key") }
value3, ok := frontMatter["this"]
if !ok { test.Fatal("missing key") }
value4, ok := frontMatter["sentence"]
if !ok { test.Fatal("missing key") }
if value0 != "baR" { test.Fatal("value is not correct") }
if value1 != "Bar" { test.Fatal("value is not correct") }
if value2 != "---" { test.Fatal("value is not correct") }
if value3 != "that" { test.Fatal("value is not correct") }
if value4 != quickBrownFox { test.Fatal("value is not correct") }
}