github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/markup/console/console_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 console 7 8 import ( 9 "strings" 10 "testing" 11 12 "github.com/gitbundle/modules/markup" 13 14 "github.com/stretchr/testify/assert" 15 ) 16 17 func TestRenderConsole(t *testing.T) { 18 var render Renderer 19 kases := map[string]string{ 20 "\x1b[37m\x1b[40mnpm\x1b[0m \x1b[0m\x1b[32minfo\x1b[0m \x1b[0m\x1b[35mit worked if it ends with\x1b[0m ok": "<span class=\"term-fg37 term-bg40\">npm</span> <span class=\"term-fg32\">info</span> <span class=\"term-fg35\">it worked if it ends with</span> ok", 21 } 22 23 for k, v := range kases { 24 var buf strings.Builder 25 canRender := render.CanRender("test", strings.NewReader(k)) 26 assert.True(t, canRender) 27 28 err := render.Render(&markup.RenderContext{}, strings.NewReader(k), &buf) 29 assert.NoError(t, err) 30 assert.EqualValues(t, v, buf.String()) 31 } 32 }