@@ 16,8 16,6 @@ package tcell
import (
"testing"
-
- . "github.com/smartystreets/goconvey/convey"
)
// SimulationScreen represents a screen simulation. This is intended to
@@ 60,49 58,41 @@ type SimulationScreen interface {
func WithScreen(t *testing.T, charset string, fn func(s SimulationScreen)) func() {
return func() {
s, e := NewSimScreen(charset)
- So(s, ShouldNotBeNil)
- So(e, ShouldBeNil)
- Reset(func() {
- s.Fini()
- })
+ assertNotEqual("sim screen", s, nil, t)
+ assertEqual("error", e, nil, t)
fn(s)
+ s.Fini()
}
}
func TestInitScreen(t *testing.T) {
- Convey("Init a screen", t, WithScreen(t, "", func(s SimulationScreen) {
+ WithScreen(t, "", func(s SimulationScreen) {
+ x, y := s.Size()
+ assertEqual("x", x, 80, t)
+ assertEqual("y", y, 25, t)
- Convey("Size should be valid", func() {
- x, y := s.Size()
- So(x, ShouldEqual, 80)
- So(y, ShouldEqual, 25)
- })
+ assertEqual("character set", s.CharacterSet(), "UTF-8", t)
- Convey("Default charset is UTF-8", func() {
- So(s.CharacterSet(), ShouldEqual, "UTF-8")
- })
-
- Convey("Backing size is correct", func() {
- b, x, y := s.GetContents()
- So(b, ShouldNotBeNil)
- So(x, ShouldEqual, 80)
- So(y, ShouldEqual, 25)
- So(len(b), ShouldEqual, x*y)
- })
- }))
+ //Backing size is correct
+ b, x, y := s.GetContents()
+ assertNotEqual("data", b, nil, t)
+ assertEqual("x", x, 80, t)
+ assertEqual("y", y, 25, t)
+ assertEqual("backing len", len(b), x*y, t)
+ })()
}
func TestClearScreen(t *testing.T) {
- Convey("Clear screen", t, WithScreen(t, "", func(s SimulationScreen) {
+ WithScreen(t, "", func(s SimulationScreen) {
s.Clear()
b, x, y := s.GetContents()
- So(b, ShouldNotBeNil)
- So(x, ShouldEqual, 80)
- So(y, ShouldEqual, 25)
- So(len(b), ShouldEqual, x*y)
+ assertNotEqual("data", b, nil, t)
+ assertEqual("x", x, 80, t)
+ assertEqual("y", y, 25, t)
+ assertEqual("backing len", len(b), x*y, t)
s.Sync()
nmatch := 0
@@ 111,7 101,7 @@ func TestClearScreen(t *testing.T) {
nmatch++
}
}
- So(nmatch, ShouldEqual, x*y)
+ assertEqual("nmatch runes", nmatch, x*y, t)
nmatch = 0
for i := 0; i < x*y; i++ {
@@ 119,7 109,7 @@ func TestClearScreen(t *testing.T) {
nmatch++
}
}
- So(nmatch, ShouldEqual, x*y)
+ assertEqual("nmatch bytes", nmatch, x*y, t)
nmatch = 0
for i := 0; i < x*y; i++ {
@@ 127,60 117,50 @@ func TestClearScreen(t *testing.T) {
nmatch++
}
}
- So(nmatch, ShouldEqual, x*y)
- }))
+ assertEqual("nmatch styles", nmatch, x*y, t)
+ })()
}
func TestSetCell(t *testing.T) {
st := StyleDefault.Background(ColorRed).Blink(true)
- Convey("Set contents", t, WithScreen(t, "", func(s SimulationScreen) {
+ WithScreen(t, "", func(s SimulationScreen) {
s.SetContent(2, 5, '@', nil, st)
b, x, y := s.GetContents()
- So(len(b), ShouldEqual, x*y)
- So(x, ShouldEqual, 80)
- So(y, ShouldEqual, 25)
+ assertEqual("x", x, 80, t)
+ assertEqual("y", y, 25, t)
+ assertEqual("backing len", len(b), x*y, t)
s.Show()
sc := &b[5*80+2]
- So(len(sc.Runes), ShouldEqual, 1)
- So(len(sc.Bytes), ShouldEqual, 1)
- So(sc.Bytes[0], ShouldEqual, '@')
- So(sc.Runes[0], ShouldEqual, '@')
- So(sc.Style, ShouldEqual, st)
- }))
+ assertEqual("len runes", len(sc.Runes), 1, t)
+ assertEqual("len bytes", len(sc.Bytes), 1, t)
+ assertEqual("byte value", sc.Bytes[0], byte('@'), t)
+ assertEqual("rune value", sc.Runes[0], '@', t)
+ assertEqual("style", sc.Style, st, t)
+
+ })()
}
func TestResize(t *testing.T) {
st := StyleDefault.Background(ColorYellow).Underline(true)
- Convey("Resize", t, WithScreen(t, "", func(s SimulationScreen) {
+ WithScreen(t, "", func(s SimulationScreen) {
s.SetContent(2, 5, '&', nil, st)
- b, x, y := s.GetContents()
- So(len(b), ShouldEqual, x*y)
- So(x, ShouldEqual, 80)
- So(y, ShouldEqual, 25)
+ b, _, _ := s.GetContents()
s.Show()
- sc := &b[5*80+2]
- So(len(sc.Runes), ShouldEqual, 1)
- So(len(sc.Bytes), ShouldEqual, 1)
- So(sc.Bytes[0], ShouldEqual, '&')
- So(sc.Runes[0], ShouldEqual, '&')
- So(sc.Style, ShouldEqual, st)
+ s.SetSize(30, 10)
+ s.Show()
+ b2, x2, y2 := s.GetContents()
+ _ = b2
+ // todo So(b2, ShouldNotEqual, b)
+ assertEqual("x", x2, 30, t)
+ assertEqual("y", y2, 10, t)
- Convey("Do resize", func() {
- s.SetSize(30, 10)
- s.Show()
- b2, x2, y2 := s.GetContents()
- So(b2, ShouldNotEqual, b)
- So(x2, ShouldEqual, 30)
- So(y2, ShouldEqual, 10)
-
- sc2 := &b[5*80+2]
- So(len(sc2.Runes), ShouldEqual, 1)
- So(len(sc2.Bytes), ShouldEqual, 1)
- So(sc2.Bytes[0], ShouldEqual, '&')
- So(sc2.Runes[0], ShouldEqual, '&')
- So(sc2.Style, ShouldEqual, st)
- })
- }))
+ sc2 := &b[5*80+2]
+ assertEqual("len runes", len(sc2.Runes), 1, t)
+ assertEqual("len bytes", len(sc2.Bytes), 1, t)
+ assertEqual("byte value", sc2.Bytes[0], byte('&'), t)
+ assertEqual("rune value", sc2.Runes[0], '&', t)
+ assertEqual("style", sc2.Style, st, t)
+ })()
}