File: parser_test.go

package info (click to toggle)
tml 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 168 kB
  • sloc: makefile: 16
file content (46 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package tml

import (
	"bytes"
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestParser(t *testing.T) {

	testCases := []struct {
		name   string
		input  string
		output string
	}{
		{
			name:   "no-tags",
			input:  "plain",
			output: "\x1b[0mplain\x1b[0m",
		},
		{
			name:   "basic",
			input:  "plain <red>red</red> plain",
			output: "\x1b[0mplain \x1b[31mred\x1b[39m plain\x1b[0m",
		},
		{
			name:   "nesting",
			input:  "plain <red>red <bold>bold red</bold></red> plain <green>green</green> plain",
			output: "\x1b[0mplain \x1b[31mred \x1b[1mbold red\x1b[0m\x1b[31m\x1b[39m plain \x1b[32mgreen\x1b[39m plain\x1b[0m",
		},
	}

	for _, testCase := range testCases {
		t.Run(testCase.name, func(t *testing.T) {
			buffer := bytes.NewBufferString("")
			parser := NewParser(buffer)
			err := parser.Parse(strings.NewReader(testCase.input))
			require.Nil(t, err)
			assert.Equal(t, testCase.output, buffer.String())
		})
	}

}