1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-01-28 03:29:41 +02:00
chroma/style_test.go
Alec Thomas d5083b3f7c Big changes to the style and colour APIs.
- Styles now use a builder system, to enforce immutability of styles.
- Corrected and cleaned up how style inheritance works.
- Added a brightening function to colours
- HTML formatter will now automatically pick line and highlight colours
  if they are not provided in the style. This is done by slightly
  darkening or lightening.

Fixes #21.
2017-09-23 22:09:46 +10:00

38 lines
993 B
Go

package chroma
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestStyleInherit(t *testing.T) {
s, err := NewStyle("test", StyleEntries{
Name: "bold #f00",
NameVariable: "#fff",
})
assert.NoError(t, err)
assert.Equal(t, StyleEntry{Colour: 0x1000000, Bold: Yes}, s.Get(NameVariable))
}
func TestStyleColours(t *testing.T) {
s, err := NewStyle("test", StyleEntries{
Name: "#f00 bg:#001 border:#ansiblue",
})
assert.NoError(t, err)
assert.Equal(t, StyleEntry{Colour: 0xff0001, Background: 0x000012, Border: 0x000100}, s.Get(Name))
}
func TestStyleClone(t *testing.T) {
parent, err := NewStyle("test", StyleEntries{
Background: "bg:#ffffff",
})
assert.NoError(t, err)
clone, err := parent.Builder().Add(Comment, "#0f0").Build()
assert.NoError(t, err)
assert.Equal(t, "bg:#ffffff", clone.Get(Background).String())
assert.Equal(t, "#00ff00 bg:#ffffff", clone.Get(Comment).String())
assert.Equal(t, "bg:#ffffff", parent.Get(Comment).String())
}