This repository was archived by the owner on Feb 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoloredstring_test.go
More file actions
65 lines (50 loc) · 1.45 KB
/
coloredstring_test.go
File metadata and controls
65 lines (50 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package color
import (
"testing"
)
func TestNewColoredText(t *testing.T) {
c, err := NewColoredText(nil, "test")
if err != nil {
t.Fatal(err)
}
if c.Background != None {
t.Fatalf("Expected c.Background == None, got %s", c.Background.String())
}
if c.Foreground != None {
t.Fatalf("Expected c.Foreground == None, got %s", c.Foreground.String())
}
}
func TestNewColoredTextWithForegroundColor(t *testing.T) {
c, err := NewColoredText([]Color{LightRed}, "this text is red")
if err != nil {
t.Fatal(err)
}
if c.Background != None {
t.Fatalf("Expected c.Background == None, got %s", c.Background.String())
}
if c.Foreground != LightRed {
t.Fatalf("Expected c.Foreground == LightRed, got %s", c.Foreground.String())
}
}
func TestNewColoredTextWithBackgroundAndForegroundColor(t *testing.T) {
c, err := NewColoredText([]Color{LightRed, Blue}, "this text will blind you")
if err != nil {
t.Fatal(err)
}
if c.Background != Blue {
t.Fatalf("Expected c.Background == Blue, got %s", c.Background.String())
}
if c.Foreground != LightRed {
t.Fatalf("Expected c.Foreground == LightRed, got %s", c.Foreground.String())
}
}
func TestNewColoredTextWithColorsThatMakeNoSense(t *testing.T) {
_, err := NewColoredText([]Color{LightBlue, Black, Green}, "Hi")
if err != ErrWrongColorNumber || err == nil {
t.Fatal("Expected an error")
}
_, err = NewColoredText([]Color{Color(55)}, "test")
if err != ErrBadColor || err == nil {
t.Fatal(err)
}
}