mirror of
https://github.com/go-gitea/gitea.git
synced 2024-08-25 21:44:20 -04:00
There is a small bug in #20571 whereby `$a a$b b$` will not be correctly detected as a math inline block of `a a$b b`. This PR fixes this. Also reenable test cases as per #21340 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
164 lines
2.9 KiB
Go
164 lines
2.9 KiB
Go
// 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{
|
|
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{
|
|
TOC: true,
|
|
Meta: "table",
|
|
Icon: "table",
|
|
Lang: "",
|
|
}, "include_toc: true",
|
|
},
|
|
{
|
|
"tocfalse", &RenderConfig{
|
|
TOC: false,
|
|
Meta: "table",
|
|
Icon: "table",
|
|
Lang: "",
|
|
}, "include_toc: false",
|
|
},
|
|
{
|
|
"toclang", &RenderConfig{
|
|
Meta: "table",
|
|
Icon: "table",
|
|
TOC: true,
|
|
Lang: "testlang",
|
|
}, `
|
|
include_toc: true
|
|
lang: testlang
|
|
`,
|
|
},
|
|
{
|
|
"complexlang", &RenderConfig{
|
|
Meta: "table",
|
|
Icon: "table",
|
|
Lang: "testlang",
|
|
}, `
|
|
gitea:
|
|
lang: testlang
|
|
`,
|
|
},
|
|
{
|
|
"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",
|
|
TOC: true,
|
|
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: "",
|
|
}
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|