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 ` frontMatter, body, err := SplitMeta( `--- 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("META:") 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") } } 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" frontMatter, 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(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") } }