Skip to content

Commit

Permalink
Merge 28aa2df into af3c5b9
Browse files Browse the repository at this point in the history
  • Loading branch information
mum4k committed Nov 14, 2020
2 parents af3c5b9 + 28aa2df commit b5a5860
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- coveralls again triggers and reports on PRs.
- improving test coverage in some modules.

## [0.12.2] - 31-Aug-2020

Expand Down
16 changes: 16 additions & 0 deletions cell/cell_test.go
Expand Up @@ -27,6 +27,7 @@ func TestNewOptions(t *testing.T) {
want *Options
}{
{

desc: "no provided options",
want: &Options{},
},
Expand Down Expand Up @@ -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 {
Expand Down
69 changes: 69 additions & 0 deletions private/faketerm/diff_test.go
@@ -0,0 +1,69 @@
package faketerm

import (
"image"
"testing"

"github.com/mum4k/termdash/cell"
)

func TestDiff(t *testing.T) {
tests := []struct {
desc string
term1 *Terminal
term2 *Terminal
wantDiff bool
}{
{
desc: "no diff on equal terminals",
term1: func() *Terminal {
t := MustNew(image.Point{2, 2})
t.SetCell(image.Point{0, 0}, 'a')
return t
}(),
term2: func() *Terminal {
t := MustNew(image.Point{2, 2})
t.SetCell(image.Point{0, 0}, 'a')
return t
}(),
wantDiff: false,
},
{
desc: "reports diff on when cell runes differ",
term1: func() *Terminal {
t := MustNew(image.Point{2, 2})
t.SetCell(image.Point{0, 0}, 'a')
return t
}(),
term2: func() *Terminal {
t := MustNew(image.Point{2, 2})
t.SetCell(image.Point{1, 1}, 'a')
return t
}(),
wantDiff: true,
},
{
desc: "reports diff on when cell options differ",
term1: func() *Terminal {
t := MustNew(image.Point{2, 2})
t.SetCell(image.Point{0, 0}, 'a', cell.Bold())
return t
}(),
term2: func() *Terminal {
t := MustNew(image.Point{2, 2})
t.SetCell(image.Point{0, 0}, 'a')
return t
}(),
wantDiff: true,
},
}

for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
gotDiff := Diff(tc.term1, tc.term2)
if (gotDiff != "") != tc.wantDiff {
t.Errorf("Diff -> unexpected diff while wantDiff:%v, the diff:\n%s", tc.wantDiff, gotDiff)
}
})
}
}
2 changes: 1 addition & 1 deletion terminal/tcell/cell_options.go
Expand Up @@ -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
}
7 changes: 3 additions & 4 deletions terminal/termbox/cell_options.go
Expand Up @@ -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.
Expand Down
16 changes: 11 additions & 5 deletions terminal/termbox/cell_options_test.go
Expand Up @@ -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)
Expand Down

0 comments on commit b5a5860

Please sign in to comment.