mirror of https://github.com/mum4k/termdash.git
Adding test coverage to cell options.
This commit is contained in:
parent
af3c5b9b00
commit
e5e1397ce9
|
@ -27,6 +27,7 @@ func TestNewOptions(t *testing.T) {
|
|||
want *Options
|
||||
}{
|
||||
{
|
||||
|
||||
desc: "no provided options",
|
||||
want: &Options{},
|
||||
},
|
||||
|
@ -72,6 +73,21 @@ func TestNewOptions(t *testing.T) {
|
|||
BgColor: ColorMagenta,
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "setting font attributes",
|
||||
opts: []Option{
|
||||
Bold(),
|
||||
Italic(),
|
||||
Underline(),
|
||||
Strikethrough(),
|
||||
},
|
||||
want: &Options{
|
||||
Bold: true,
|
||||
Italic: true,
|
||||
Underline: true,
|
||||
Strikethrough: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
|
|
|
@ -57,7 +57,7 @@ func cellOptsToStyle(opts *cell.Options, colorMode terminalapi.ColorMode) tcell.
|
|||
fg = fixColor(fg, colorMode)
|
||||
bg = fixColor(bg, colorMode)
|
||||
|
||||
// FIXME: tcell doesn't have a strikethrough style option
|
||||
// FIXME: tcell doesn't have a strikethrough style option until #254 is resolved.
|
||||
st = st.Foreground(fg).Background(bg).Bold(opts.Bold).Italic(opts.Italic).Underline(opts.Underline)
|
||||
return st
|
||||
}
|
||||
|
|
|
@ -31,22 +31,21 @@ func cellColor(c cell.Color) tbx.Attribute {
|
|||
// cellOptsToFg converts the cell options to the termbox foreground attribute.
|
||||
func cellOptsToFg(opts *cell.Options) (tbx.Attribute, error) {
|
||||
a := cellColor(opts.FgColor)
|
||||
var err error
|
||||
if opts.Bold {
|
||||
a |= tbx.AttrBold
|
||||
}
|
||||
// FIXME: Termbox doesn't have an italics attribute
|
||||
if opts.Italic {
|
||||
err = errors.New("Termbox: Unsupported attribute: Italic")
|
||||
return 0, errors.New("Termbox: Unsupported attribute: Italic")
|
||||
}
|
||||
if opts.Underline {
|
||||
a |= tbx.AttrUnderline
|
||||
}
|
||||
// FIXME: Termbox doesn't have a strikethrough attribute
|
||||
if opts.Strikethrough {
|
||||
err = errors.New("Termbox: Unsupported attribute: Strikethrough")
|
||||
return 0, errors.New("Termbox: Unsupported attribute: Strikethrough")
|
||||
}
|
||||
return a, err
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// cellOptsToBg converts the cell options to the termbox background attribute.
|
||||
|
|
|
@ -52,18 +52,24 @@ func TestCellColor(t *testing.T) {
|
|||
|
||||
func TestCellFontModifier(t *testing.T) {
|
||||
tests := []struct {
|
||||
opt cell.Options
|
||||
want tbx.Attribute
|
||||
opt cell.Options
|
||||
want tbx.Attribute
|
||||
wantErr bool
|
||||
}{
|
||||
{cell.Options{Bold: true}, tbx.AttrBold},
|
||||
{cell.Options{Underline: true}, tbx.AttrUnderline},
|
||||
{cell.Options{Bold: true}, tbx.AttrBold, false},
|
||||
{cell.Options{Underline: true}, tbx.AttrUnderline, false},
|
||||
{cell.Options{Italic: true}, 0, true},
|
||||
{cell.Options{Strikethrough: true}, 0, true},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(fmt.Sprintf("%v", tc.opt), func(t *testing.T) {
|
||||
got, err := cellOptsToFg(&tc.opt)
|
||||
if (err != nil) != tc.wantErr {
|
||||
t.Errorf("cellOptsToFg(%v) => unexpected error: %v, wantErr: %v", tc.opt, err, tc.wantErr)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("cellOptsToFg(%v) failed: %s", tc.opt, err)
|
||||
return
|
||||
}
|
||||
if got != tc.want {
|
||||
t.Errorf("cellOptsToFg(%v) => got %v, want %v", tc.opt, got, tc.want)
|
||||
|
|
Loading…
Reference in New Issue