github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/markup/orgmode/orgmode_test.go (about) 1 // Copyright 2023 The GitBundle Inc. All rights reserved. 2 // Copyright 2017 The Gitea Authors. All rights reserved. 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file. 5 6 package markup 7 8 import ( 9 "strings" 10 "testing" 11 12 "github.com/gitbundle/modules/markup" 13 "github.com/gitbundle/modules/setting" 14 "github.com/gitbundle/modules/util" 15 16 "github.com/stretchr/testify/assert" 17 ) 18 19 const ( 20 AppURL = "http://localhost:3000/" 21 Repo = "gogits/gogs" 22 AppSubURL = AppURL + Repo + "/" 23 ) 24 25 func TestRender_StandardLinks(t *testing.T) { 26 setting.AppURL = AppURL 27 setting.AppSubURL = AppSubURL 28 29 test := func(input, expected string) { 30 buffer, err := RenderString(&markup.RenderContext{ 31 URLPrefix: setting.AppSubURL, 32 }, input) 33 assert.NoError(t, err) 34 assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) 35 } 36 37 googleRendered := "<p><a href=\"https://google.com/\" title=\"https://google.com/\">https://google.com/</a></p>" 38 test("[[https://google.com/]]", googleRendered) 39 40 lnk := util.URLJoin(AppSubURL, "WikiPage") 41 test("[[WikiPage][WikiPage]]", 42 "<p><a href=\""+lnk+"\" title=\"WikiPage\">WikiPage</a></p>") 43 } 44 45 func TestRender_Images(t *testing.T) { 46 setting.AppURL = AppURL 47 setting.AppSubURL = AppSubURL 48 49 test := func(input, expected string) { 50 buffer, err := RenderString(&markup.RenderContext{ 51 URLPrefix: setting.AppSubURL, 52 }, input) 53 assert.NoError(t, err) 54 assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) 55 } 56 57 url := "../../.images/src/02/train.jpg" 58 result := util.URLJoin(AppSubURL, url) 59 60 test("[[file:"+url+"]]", 61 "<p><img src=\""+result+"\" alt=\""+result+"\" title=\""+result+"\" /></p>") 62 } 63 64 func TestRender_Source(t *testing.T) { 65 setting.AppURL = AppURL 66 setting.AppSubURL = AppSubURL 67 68 test := func(input, expected string) { 69 buffer, err := RenderString(&markup.RenderContext{ 70 URLPrefix: setting.AppSubURL, 71 }, input) 72 assert.NoError(t, err) 73 assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) 74 } 75 76 test(`#+begin_src go 77 // HelloWorld prints "Hello World" 78 func HelloWorld() { 79 fmt.Println("Hello World") 80 } 81 #+end_src 82 `, `<div class="src src-go"> 83 <pre><code class="chroma language-go"><span class="line"><span class="cl"><span class="c1">// HelloWorld prints "Hello World" 84 </span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="kd">func</span> <span class="nf">HelloWorld</span><span class="p">()</span> <span class="p">{</span> 85 </span></span><span class="line"><span class="cl"> <span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="s">"Hello World"</span><span class="p">)</span> 86 </span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre> 87 </div>`) 88 }