]> git.lizzy.rs Git - micro.git/blob - cmd/micro/colorscheme_test.go
Start refactor
[micro.git] / cmd / micro / colorscheme_test.go
1 package main
2
3 import (
4         "testing"
5
6         "github.com/stretchr/testify/assert"
7         "github.com/zyedidia/tcell"
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 TestColor256StringToStyle(t *testing.T) {
30         s := StringToStyle("128,60")
31
32         fg, bg, _ := s.Decompose()
33
34         assert.Equal(t, tcell.Color128, fg)
35         assert.Equal(t, tcell.Color60, bg)
36 }
37
38 func TestColorHexStringToStyle(t *testing.T) {
39         s := StringToStyle("#deadbe,#ef1234")
40
41         fg, bg, _ := s.Decompose()
42
43         assert.Equal(t, tcell.NewRGBColor(222, 173, 190), fg)
44         assert.Equal(t, tcell.NewRGBColor(239, 18, 52), bg)
45 }
46
47 func TestColorschemeParser(t *testing.T) {
48         testColorscheme := `color-link default "#F8F8F2,#282828"
49 color-link comment "#75715E,#282828"
50 # comment
51 color-link identifier "#66D9EF,#282828" #comment
52 color-link constant "#AE81FF,#282828"
53 color-link constant.string "#E6DB74,#282828"
54 color-link constant.string.char "#BDE6AD,#282828"`
55
56         c, err := ParseColorscheme(testColorscheme)
57         assert.Nil(t, err)
58
59         fg, bg, _ := c["comment"].Decompose()
60         assert.Equal(t, tcell.NewRGBColor(117, 113, 94), fg)
61         assert.Equal(t, tcell.NewRGBColor(40, 40, 40), bg)
62 }