// Copyright 2017 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package markup import ( "os" "strings" "testing" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/setting" "github.com/stretchr/testify/assert" ) func TestMain(m *testing.M) { setting.AppURL = "http://localhost:3000/" setting.IsInTesting = true os.Exit(m.Run()) } func TestRender_StandardLinks(t *testing.T) { test := func(input, expected string) { buffer, err := RenderString(markup.NewTestRenderContext("/relative-path/media/branch/main/"), input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) } test("[[https://google.com/]]", `
`) test("[[ImageLink.svg][The Image Desc]]", ``) } func TestRender_InternalLinks(t *testing.T) { test := func(input, expected string) { buffer, err := RenderString(markup.NewTestRenderContext("/relative-path/src/branch/main"), input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) } test("[[file:test.org][Test]]", ``) test("[[./test.org][Test]]", ``) test("[[test.org][Test]]", ``) test("[[path/to/test.org][Test]]", ``) } func TestRender_Media(t *testing.T) { test := func(input, expected string) { buffer, err := RenderString(markup.NewTestRenderContext("./relative-path"), input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) } test("[[file:../../.images/src/02/train.jpg]]", `// HelloWorld prints "Hello World"
func HelloWorld() {
fmt.Println("Hello World")
}