github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/markup/csv/csv_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  
    14  	"github.com/stretchr/testify/assert"
    15  )
    16  
    17  func TestRenderCSV(t *testing.T) {
    18  	var render Renderer
    19  	kases := map[string]string{
    20  		"a":        "<table class=\"data-table\"><tr><th class=\"line-num\">1</th><th>a</th></tr></table>",
    21  		"1,2":      "<table class=\"data-table\"><tr><th class=\"line-num\">1</th><th>1</th><th>2</th></tr></table>",
    22  		"1;2\n3;4": "<table class=\"data-table\"><tr><th class=\"line-num\">1</th><th>1</th><th>2</th></tr><tr><td class=\"line-num\">2</td><td>3</td><td>4</td></tr></table>",
    23  		"<br/>":    "<table class=\"data-table\"><tr><th class=\"line-num\">1</th><th>&lt;br/&gt;</th></tr></table>",
    24  	}
    25  
    26  	for k, v := range kases {
    27  		var buf strings.Builder
    28  		err := render.Render(&markup.RenderContext{}, strings.NewReader(k), &buf)
    29  		assert.NoError(t, err)
    30  		assert.EqualValues(t, v, buf.String())
    31  	}
    32  }