| 1 |
package config |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/micro-editor/tcell/v2" |
| 7 |
"github.com/stretchr/testify/assert" |
| 8 |
) |
| 9 |
|
| 10 |
func TestSimpleStringToStyle(t *testing.T) { |
| 11 |
s := StringToStyle("lightblue,magenta") |
| 12 |
|
| 13 |
fg, bg, _ := s.Decompose() |
| 14 |
|
| 15 |
assert.Equal(t, tcell.ColorBlue, fg) |
| 16 |
assert.Equal(t, tcell.ColorPurple, bg) |
| 17 |
} |
| 18 |
|
| 19 |
func TestAttributeStringToStyle(t *testing.T) { |
| 20 |
s := StringToStyle("bold cyan,brightcyan") |
| 21 |
|
| 22 |
fg, bg, attr := s.Decompose() |
| 23 |
|
| 24 |
assert.Equal(t, tcell.ColorTeal, fg) |
| 25 |
assert.Equal(t, tcell.ColorAqua, bg) |
| 26 |
assert.NotEqual(t, 0, attr&tcell.AttrBold) |
| 27 |
} |
| 28 |
|
| 29 |
func TestMultiAttributesStringToStyle(t *testing.T) { |
| 30 |
s := StringToStyle("bold italic underline cyan,brightcyan") |
| 31 |
|
| 32 |
fg, bg, attr := s.Decompose() |
| 33 |
|
| 34 |
assert.Equal(t, tcell.ColorTeal, fg) |
| 35 |
assert.Equal(t, tcell.ColorAqua, bg) |
| 36 |
assert.NotEqual(t, 0, attr&tcell.AttrBold) |
| 37 |
assert.NotEqual(t, 0, attr&tcell.AttrItalic) |
| 38 |
assert.NotEqual(t, 0, attr&tcell.AttrUnderline) |
| 39 |
} |
| 40 |
|
| 41 |
func TestColor256StringToStyle(t *testing.T) { |
| 42 |
s := StringToStyle("128,60") |
| 43 |
|
| 44 |
fg, bg, _ := s.Decompose() |
| 45 |
|
| 46 |
assert.Equal(t, tcell.Color128, fg) |
| 47 |
assert.Equal(t, tcell.Color60, bg) |
| 48 |
} |
| 49 |
|
| 50 |
func TestColorHexStringToStyle(t *testing.T) { |
| 51 |
s := StringToStyle("#deadbe,#ef1234") |
| 52 |
|
| 53 |
fg, bg, _ := s.Decompose() |
| 54 |
|
| 55 |
assert.Equal(t, tcell.NewRGBColor(222, 173, 190), fg) |
| 56 |
assert.Equal(t, tcell.NewRGBColor(239, 18, 52), bg) |
| 57 |
} |
| 58 |
|
| 59 |
func TestColorschemeParser(t *testing.T) { |
| 60 |
testColorscheme := `color-link default "#F8F8F2,#282828" |
| 61 |
color-link comment "#75715E,#282828" |
| 62 |
# comment |
| 63 |
color-link identifier "#66D9EF,#282828" #comment |
| 64 |
color-link constant "#AE81FF,#282828" |
| 65 |
color-link constant.string "#E6DB74,#282828" |
| 66 |
color-link constant.string.char "#BDE6AD,#282828"` |
| 67 |
|
| 68 |
c, err := ParseColorscheme("testColorscheme", testColorscheme, nil) |
| 69 |
assert.Nil(t, err) |
| 70 |
|
| 71 |
fg, bg, _ := c["comment"].Decompose() |
| 72 |
assert.Equal(t, tcell.NewRGBColor(117, 113, 94), fg) |
| 73 |
assert.Equal(t, tcell.NewRGBColor(40, 40, 40), bg) |
| 74 |
} |