~bigbes/confluence-md-utilities

ref: e0e81bc69b5622c2bd20261155fc36519a7621d8 confluence-md-utilities/format/color_test.go -rw-r--r-- 2.1 KiB
e0e81bc6 — Eugene Blikh chore: rename module to go.bigb.es/confluence-md-utilities a month ago
                                                                                
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package format

import (
	"strings"
	"testing"

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

func TestColorize_TagName(t *testing.T) {
	result := Colorize("<p>text</p>")
	// Should contain ANSI codes
	assert.Contains(t, result, "\033[")
	// Tag names should be colored, text should not have color wrapping
	assert.Contains(t, result, "text")
}

func TestColorize_ACNamespace(t *testing.T) {
	result := Colorize(`<ac:structured-macro ac:name="code">`)
	// ac: tags should use magenta
	assert.Contains(t, result, magenta+"ac:structured-macro")
}

func TestColorize_RINamespace(t *testing.T) {
	result := Colorize(`<ri:user ri:userkey="abc123"/>`)
	// ri: tags should use cyan
	assert.Contains(t, result, cyan+"ri:user")
}

func TestColorize_HTMLTag(t *testing.T) {
	result := Colorize("<p>hello</p>")
	// Standard HTML tags should use blue
	assert.Contains(t, result, blue+"p")
}

func TestColorize_Attributes(t *testing.T) {
	result := Colorize(`<ac:parameter ac:name="language">go</ac:parameter>`)
	// Attribute names should be yellow
	assert.Contains(t, result, yellow+"ac:name")
	// Attribute values should be green
	assert.Contains(t, result, green+`"language"`)
}

func TestColorize_CDATA(t *testing.T) {
	result := Colorize(`<![CDATA[code here]]>`)
	// CDATA should be gray
	assert.Contains(t, result, gray+"<![CDATA[code here]]>")
}

func TestColorize_Comment(t *testing.T) {
	result := Colorize(`<!-- comment -->`)
	assert.Contains(t, result, gray+"<!-- comment -->")
}

func TestColorize_PlainText(t *testing.T) {
	result := Colorize("just text")
	// No ANSI codes for plain text
	assert.False(t, strings.Contains(result, "\033["))
}

func TestColorize_SelfClosingTag(t *testing.T) {
	result := Colorize(`<hr/>`)
	assert.Contains(t, result, gray+"/>")
}

func TestColorize_ComplexDocument(t *testing.T) {
	input := `<ac:layout>
  <p>Hello <strong>world</strong></p>
  <!-- comment -->
</ac:layout>`
	result := Colorize(input)
	// Should not panic, should contain resets
	assert.True(t, strings.Count(result, reset) > 0)
	// Plain text "Hello " and "world" should be present without color wrapping
	assert.Contains(t, result, "Hello ")
}