// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package orgmode_test
import (
"os"
"strings"
"testing"
"gitea.dev/modules/markup"
"gitea.dev/modules/markup/orgmode"
"gitea.dev/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(t *testing.T, input, expected string) {
buffer, err := orgmode.RenderString(markup.NewTestRenderContext(), input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
}
func TestRender_StandardLinks(t *testing.T) {
testRender(t, "[[https://google.com/]]",
`
https://google.com/
`)
testRender(t, "[[ImageLink.svg][The Image Desc]]",
`The Image Desc
`)
}
func TestRender_InternalLinks(t *testing.T) {
testRender(t, "[[file:test.org][Test]]",
`Test
`)
testRender(t, "[[./test.org][Test]]",
`Test
`)
testRender(t, "[[test.org][Test]]",
`Test
`)
testRender(t, "[[path/to/test.org][Test]]",
`Test
`)
}
func TestRender_Media(t *testing.T) {
testRender(t, "[[file:../../.images/src/02/train.jpg]]",
`
`)
testRender(t, "[[file:train.jpg]]",
`
`)
// With description.
testRender(t, "[[https://example.com][https://example.com/example.svg]]",
`
`)
testRender(t, "[[https://example.com][pre https://example.com/example.svg post]]",
`pre
post
`)
testRender(t, "[[https://example.com][https://example.com/example.mp4]]",
`
`)
testRender(t, "[[https://example.com][pre https://example.com/example.mp4 post]]",
`pre post
`)
// Without description.
testRender(t, "[[https://example.com/example.svg]]",
`
`)
testRender(t, "[[https://example.com/example.mp4]]",
``)
// test [[LINK][DESCRIPTION]] syntax with "file:" prefix
testRender(t, `[[https://example.com/][file:https://example.com/foo%20bar.svg]]`,
`
`)
testRender(t, `[[file:https://example.com/foo%20bar.svg][Goto Image]]`,
`Goto Image
`)
testRender(t, `[[file:https://example.com/link][https://example.com/image.jpg]]`,
`
`)
testRender(t, `[[file:https://example.com/link][file:https://example.com/image.jpg]]`,
`
`)
}
func TestRender_Source(t *testing.T) {
testRender(t, `#+begin_src c
int a;
#+end_src
`, ``)
}
func TestRender_IncludeLink(t *testing.T) {
testRender(t, `#+INCLUDE: "./other.org" src text`, ``)
}