// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package markdown
import (
"strings"
"testing"
"gopkg.in/yaml.v3"
)
func TestRenderConfig_UnmarshalYAML(t *testing.T) {
tests := []struct {
name string
expected *RenderConfig
args string
}{
{
"empty", &RenderConfig{
Meta: "table",
Icon: "table",
Lang: "",
}, "",
},
"lang", &RenderConfig{
Lang: "test",
}, "lang: test",
"metatable", &RenderConfig{
}, "gitea: table",
"metanone", &RenderConfig{
Meta: "none",
}, "gitea: none",
"metadetails", &RenderConfig{
Meta: "details",
}, "gitea: details",
"metawrong", &RenderConfig{
}, "gitea: wrong",
"toc", &RenderConfig{
TOC: true,
}, "include_toc: true",
"tocfalse", &RenderConfig{
TOC: false,
}, "include_toc: false",
"toclang", &RenderConfig{
Lang: "testlang",
}, `
include_toc: true
lang: testlang
`,
"complexlang", &RenderConfig{
gitea:
"complexlang2", &RenderConfig{
lang: notright
"complex2", &RenderConfig{
Lang: "two",
Icon: "smiley",
lang: one
details_icon: smiley
meta: table
lang: two
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := &RenderConfig{
if err := yaml.Unmarshal([]byte(strings.ReplaceAll(tt.args, "\t", " ")), got); err != nil {
t.Errorf("RenderConfig.UnmarshalYAML() error = %v\n%q", err, tt.args)
return
if got.Meta != tt.expected.Meta {
t.Errorf("Meta Expected %s Got %s", tt.expected.Meta, got.Meta)
if got.Icon != tt.expected.Icon {
t.Errorf("Icon Expected %s Got %s", tt.expected.Icon, got.Icon)
if got.Lang != tt.expected.Lang {
t.Errorf("Lang Expected %s Got %s", tt.expected.Lang, got.Lang)
if got.TOC != tt.expected.TOC {
t.Errorf("TOC Expected %t Got %t", tt.expected.TOC, got.TOC)
})