mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-11 02:13:41 +09:00
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package anymark
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type MdCase struct {
|
|
MD string `json:"md"`
|
|
Blocks []map[string]interface{} `json:"blocks"`
|
|
Desc string `json:"desc"`
|
|
}
|
|
|
|
func TestConvertMdToBlocks(t *testing.T) {
|
|
bs, err := ioutil.ReadFile("_test/md_cases.json")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
var testCases []MdCase
|
|
if err := json.Unmarshal(bs, &testCases); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
for testNum, testCase := range testCases {
|
|
t.Run(testCase.Desc, func(t *testing.T) {
|
|
mdToBlocksConverter := New()
|
|
blocks, _, _ := mdToBlocksConverter.MarkdownToBlocks([]byte(testCases[testNum].MD), "", []string{})
|
|
replaceFakeIds(blocks)
|
|
|
|
actualJson, err := json.Marshal(blocks)
|
|
require.NoError(t, err)
|
|
|
|
var actual []map[string]interface{}
|
|
err = json.Unmarshal(actualJson, &actual)
|
|
require.NoError(t, err)
|
|
|
|
if !reflect.DeepEqual(testCase.Blocks, actual) {
|
|
fmt.Println("expected:\n", string(actualJson))
|
|
require.Equal(t, testCase.Blocks, actual)
|
|
}
|
|
})
|
|
}
|
|
}
|