Debian Codegraph @

colors_test.go

raw
1 package main
2
3 import (
4 "testing"
5
6 "github.com/gdamore/tcell/v3"
7 )
8
9 func TestParseColor(t *testing.T) {
10 tests := []struct {
11 toks []string
12 color tcell.Color
13 offset int
14 success bool
15 }{
16 {[]string{}, tcell.ColorDefault, 0, false},
17 {[]string{"foo"}, tcell.ColorDefault, 0, false},
18 {[]string{"5"}, tcell.ColorDefault, 0, false},
19 {[]string{"5", "foo"}, tcell.ColorDefault, 0, false},
20 {[]string{"5", "42"}, tcell.PaletteColor(42), 2, true},
21 {[]string{"2"}, tcell.ColorDefault, 0, false},
22 {[]string{"2", "foo"}, tcell.ColorDefault, 0, false},
23 {[]string{"2", "42", "foo"}, tcell.ColorDefault, 0, false},
24 {[]string{"2", "42", "43", "foo"}, tcell.ColorDefault, 0, false},
25 {[]string{"2", "42", "43", "44"}, tcell.NewRGBColor(42, 43, 44), 4, true},
26 }
27
28 for _, test := range tests {
29 color, offset, err := parseColor(test.toks)
30 success := err == nil
31 if color != test.color || offset != test.offset || success != test.success {
32 t.Errorf("at input %v expected (%v, %v, %v) but got (%v, %v, %v)",
33 test.toks, test.color, test.offset, test.success, color, offset, success)
34 }
35 }
36 }