mirror of
https://github.com/Luzifer/wiki.git
synced 2024-12-20 10:31:18 +00:00
44 lines
692 B
Go
44 lines
692 B
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestStoredFileParse(t *testing.T) {
|
|
var (
|
|
err error
|
|
file string
|
|
sFile *storedFile
|
|
)
|
|
|
|
// Case: Proper file with header
|
|
|
|
file = `
|
|
---
|
|
key: value
|
|
---
|
|
|
|
# Header
|
|
|
|
content
|
|
`
|
|
|
|
sFile, err = storedFileFromString(file)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "# Header\n\ncontent", sFile.Content)
|
|
assert.Equal(t, map[string]any{"key": "value"}, sFile.Meta)
|
|
|
|
// Case: No header
|
|
|
|
file = "# Header\n\ncontent"
|
|
|
|
sFile, err = storedFileFromString(file)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "# Header\n\ncontent", sFile.Content)
|
|
assert.Len(t, sFile.Meta, 0)
|
|
}
|