114 lines
2.4 KiB
Go
114 lines
2.4 KiB
Go
package step
|
|
|
|
import "strings"
|
|
import "testing"
|
|
|
|
const quickBrownFox = "The quick brown fox jumped over the lazy dog."
|
|
|
|
func TestSplitMetaLF (test *testing.T) {
|
|
correctBody :=
|
|
`this is some sample text
|
|
---
|
|
theres another hr that shouldnt
|
|
break anything
|
|
break: anything
|
|
`
|
|
meta, body, err := SplitMeta(
|
|
`---
|
|
FOO: baR
|
|
fOoo: Bar
|
|
Shouldn't break anything: ---
|
|
|
|
this : that
|
|
# a comment
|
|
#also a comment
|
|
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("META:")
|
|
test.Log(meta)
|
|
if meta.Get("foo") != "baR" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if meta.Get("fooo") != "Bar" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if meta.Get("shouldn't break anything") != "---" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if meta.Get("this") != "that" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if meta.Get("sentence") != quickBrownFox {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
}
|
|
|
|
func TestSplitMetaCRLF (test *testing.T) {
|
|
correctBody := "this is some sample text\r\n---\r\ntheres another hr that shouldnt\r\nbreak anything\r\nbreak: anything\r\n"
|
|
meta, body, err := SplitMeta(
|
|
"---\r\nFOO: baR\r\n fOoo: Bar\r\nShouldn't break anything: ---\r\n\r\nthis : that\r\nSentence: " + quickBrownFox + "\r\n---\r\n" + correctBody)
|
|
if err != nil {
|
|
test.Fatal(err)
|
|
}
|
|
|
|
test.Log("BODY:")
|
|
test.Log(body)
|
|
correctBody = strings.ReplaceAll(correctBody, "\r\n", "\n")
|
|
if body != correctBody {
|
|
test.Fatal("body is not correct")
|
|
}
|
|
|
|
test.Log("META:")
|
|
test.Log(meta)
|
|
if meta.Get("foo") != "baR" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if meta.Get("fooo") != "Bar" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if meta.Get("shouldn't break anything") != "---" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if meta.Get("this") != "that" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if meta.Get("sentence") != quickBrownFox {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
}
|
|
|
|
func TestParseMeta (test *testing.T) {
|
|
meta, err := ParseMeta(
|
|
`thing: " Quoted string!!!!! "
|
|
Other-Thing: askdjlksajd
|
|
|
|
number: 3849
|
|
`)
|
|
if err != nil {
|
|
test.Fatal(err)
|
|
}
|
|
|
|
test.Log("META:")
|
|
test.Log(meta)
|
|
if meta.Get("thing") != "\tQuoted string!!!!! " {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if meta.Get("other-thing") != "askdjlksajd" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if meta.Get("number") != "3849" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
}
|