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 ")
}