-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwriter_test.go
77 lines (60 loc) · 1.7 KB
/
writer_test.go
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
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package ansiterm
import (
"bytes"
gc "gopkg.in/check.v1"
)
type writerSuite struct{}
var _ = gc.Suite(&writerSuite{})
func (*writerSuite) TestNoColor(c *gc.C) {
buff := &bytes.Buffer{}
writer := NewWriter(buff)
c.Check(writer.noColor, gc.Equals, true)
writer.SetForeground(Yellow)
writer.SetBackground(Blue)
writer.SetStyle(Bold)
writer.ClearStyle(Bold)
writer.Reset()
c.Check(buff.String(), gc.Equals, "")
}
func (*writerSuite) TestSetColorCapable(c *gc.C) {
buff := &bytes.Buffer{}
writer := NewWriter(buff)
c.Check(writer.noColor, gc.Equals, true)
writer.SetColorCapable(true)
c.Check(writer.noColor, gc.Equals, false)
writer.SetColorCapable(false)
c.Check(writer.noColor, gc.Equals, true)
}
func (*writerSuite) newWriter() (*bytes.Buffer, *Writer) {
buff := &bytes.Buffer{}
writer := NewWriter(buff)
writer.noColor = false
return buff, writer
}
func (s *writerSuite) TestSetForeground(c *gc.C) {
buff, writer := s.newWriter()
writer.SetForeground(Yellow)
c.Check(buff.String(), gc.Equals, "\x1b[33m")
}
func (s *writerSuite) TestSetBackground(c *gc.C) {
buff, writer := s.newWriter()
writer.SetBackground(Blue)
c.Check(buff.String(), gc.Equals, "\x1b[44m")
}
func (s *writerSuite) TestSetStyle(c *gc.C) {
buff, writer := s.newWriter()
writer.SetStyle(Bold)
c.Check(buff.String(), gc.Equals, "\x1b[1m")
}
func (s *writerSuite) TestClearStyle(c *gc.C) {
buff, writer := s.newWriter()
writer.ClearStyle(Bold)
c.Check(buff.String(), gc.Equals, "\x1b[21m")
}
func (s *writerSuite) TestReset(c *gc.C) {
buff, writer := s.newWriter()
writer.Reset()
c.Check(buff.String(), gc.Equals, "\x1b[0m")
}