2022-09-13 16:33:37 +00:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-09-13 16:33:37 +00:00
|
|
|
|
|
|
|
package markdown
|
|
|
|
|
|
|
|
import (
|
2022-10-05 18:55:36 +00:00
|
|
|
"strings"
|
2022-09-13 16:33:37 +00:00
|
|
|
"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{
|
|
|
|
Meta: "table",
|
|
|
|
Icon: "table",
|
|
|
|
Lang: "test",
|
|
|
|
}, "lang: test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"metatable", &RenderConfig{
|
|
|
|
Meta: "table",
|
|
|
|
Icon: "table",
|
|
|
|
Lang: "",
|
|
|
|
}, "gitea: table",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"metanone", &RenderConfig{
|
|
|
|
Meta: "none",
|
|
|
|
Icon: "table",
|
|
|
|
Lang: "",
|
|
|
|
}, "gitea: none",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"metadetails", &RenderConfig{
|
|
|
|
Meta: "details",
|
|
|
|
Icon: "table",
|
|
|
|
Lang: "",
|
|
|
|
}, "gitea: details",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"metawrong", &RenderConfig{
|
|
|
|
Meta: "details",
|
|
|
|
Icon: "table",
|
|
|
|
Lang: "",
|
|
|
|
}, "gitea: wrong",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"toc", &RenderConfig{
|
2023-04-17 19:05:19 +00:00
|
|
|
TOC: "true",
|
2022-09-13 16:33:37 +00:00
|
|
|
Meta: "table",
|
|
|
|
Icon: "table",
|
|
|
|
Lang: "",
|
|
|
|
}, "include_toc: true",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"tocfalse", &RenderConfig{
|
2023-04-17 19:05:19 +00:00
|
|
|
TOC: "false",
|
2022-09-13 16:33:37 +00:00
|
|
|
Meta: "table",
|
|
|
|
Icon: "table",
|
|
|
|
Lang: "",
|
|
|
|
}, "include_toc: false",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"toclang", &RenderConfig{
|
|
|
|
Meta: "table",
|
|
|
|
Icon: "table",
|
2023-04-17 19:05:19 +00:00
|
|
|
TOC: "true",
|
2022-09-13 16:33:37 +00:00
|
|
|
Lang: "testlang",
|
|
|
|
}, `
|
2022-10-05 18:55:36 +00:00
|
|
|
include_toc: true
|
|
|
|
lang: testlang
|
|
|
|
`,
|
2022-09-13 16:33:37 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"complexlang", &RenderConfig{
|
|
|
|
Meta: "table",
|
|
|
|
Icon: "table",
|
|
|
|
Lang: "testlang",
|
|
|
|
}, `
|
2022-10-05 18:55:36 +00:00
|
|
|
gitea:
|
|
|
|
lang: testlang
|
|
|
|
`,
|
2022-09-13 16:33:37 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"complexlang2", &RenderConfig{
|
|
|
|
Meta: "table",
|
|
|
|
Icon: "table",
|
|
|
|
Lang: "testlang",
|
|
|
|
}, `
|
|
|
|
lang: notright
|
|
|
|
gitea:
|
|
|
|
lang: testlang
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"complexlang", &RenderConfig{
|
|
|
|
Meta: "table",
|
|
|
|
Icon: "table",
|
|
|
|
Lang: "testlang",
|
|
|
|
}, `
|
|
|
|
gitea:
|
|
|
|
lang: testlang
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"complex2", &RenderConfig{
|
|
|
|
Lang: "two",
|
|
|
|
Meta: "table",
|
2023-04-17 19:05:19 +00:00
|
|
|
TOC: "true",
|
2022-09-13 16:33:37 +00:00
|
|
|
Icon: "smiley",
|
|
|
|
}, `
|
|
|
|
lang: one
|
|
|
|
include_toc: true
|
|
|
|
gitea:
|
|
|
|
details_icon: smiley
|
|
|
|
meta: table
|
|
|
|
include_toc: true
|
|
|
|
lang: two
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got := &RenderConfig{
|
|
|
|
Meta: "table",
|
|
|
|
Icon: "table",
|
|
|
|
Lang: "",
|
|
|
|
}
|
2022-10-05 18:55:36 +00:00
|
|
|
if err := yaml.Unmarshal([]byte(strings.ReplaceAll(tt.args, "\t", " ")), got); err != nil {
|
|
|
|
t.Errorf("RenderConfig.UnmarshalYAML() error = %v\n%q", err, tt.args)
|
2022-09-13 16:33:37 +00:00
|
|
|
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 {
|
2023-04-17 19:05:19 +00:00
|
|
|
t.Errorf("TOC Expected %q Got %q", tt.expected.TOC, got.TOC)
|
2022-09-13 16:33:37 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|