@@ 20,7 20,7 @@ import (
func TestCanDisplay(t *testing.T) {
- WithScreen(t, "UTF-8", func(s SimulationScreen) {
+ WithScreen(t, "UTF-8", func(s Screen) {
assertEqual("utf8 1", s.CharacterSet(), "UTF-8", t)
assertEqual("utf8 2", s.CanDisplay('a', true), true, t)
assertEqual("utf8 3", s.CanDisplay(RuneHLine, true), true, t)
@@ 28,7 28,7 @@ func TestCanDisplay(t *testing.T) {
assertEqual("utf8 5", s.CanDisplay('⌀', false), true, t)
})()
- WithScreen(t, "US-ASCII", func(s SimulationScreen) {
+ WithScreen(t, "US-ASCII", func(s Screen) {
assertEqual("ascii 1", s.CharacterSet(), "US-ASCII", t)
assertEqual("ascii 2", s.CanDisplay('a', true), true, t)
assertEqual("ascii 3", s.CanDisplay(RuneHLine, true), true, t)
@@ 40,7 40,7 @@ func TestCanDisplay(t *testing.T) {
func TestRegisterFallback(t *testing.T) {
- WithScreen(t, "US-ASCII", func(s SimulationScreen) {
+ WithScreen(t, "US-ASCII", func(s Screen) {
assertEqual("ascii 1", s.CharacterSet(), "US-ASCII", t)
s.RegisterRuneFallback('⌀', "o")
assertEqual("registered false", s.CanDisplay('⌀', false), false, t)
@@ 54,7 54,7 @@ func TestRegisterFallback(t *testing.T)
func TestUnregisterFallback(t *testing.T) {
- WithScreen(t, "US-ASCII", func(s SimulationScreen) {
+ WithScreen(t, "US-ASCII", func(s Screen) {
assertEqual("ascii 1", s.CharacterSet(), "US-ASCII", t)
assertEqual("registered", s.CanDisplay(RuneHLine, true), true, t)
@@ 18,44 18,7 @@ import (
"testing"
)
-// SimulationScreen represents a screen simulation. This is intended to
-// be a superset of normal Screens, but also adds some important interfaces
-// for testing.
-type SimulationScreen interface {
- // InjectKeyBytes injects a stream of bytes corresponding to
- // the native encoding (see charset). It turns true if the entire
- // set of bytes were processed and delivered as KeyEvents, false
- // if any bytes were not fully understood. Any bytes that are not
- // fully converted are discarded.
- InjectKeyBytes(buf []byte) bool
-
- // InjectKey injects a key event. The rune is a UTF-8 rune, post
- // any translation.
- InjectKey(key Key, r rune, mod ModMask)
-
- // InjectMouse injects a mouse event.
- InjectMouse(x, y int, buttons ButtonMask, mod ModMask)
-
- // SetSize resizes the underlying physical screen. It also causes
- // a resize event to be injected during the next Show() or Sync().
- // A new physical contents array will be allocated (with data from
- // the old copied), so any prior value obtained with GetContents
- // won't be used anymore
- SetSize(width, height int)
-
- // GetContents returns screen contents as an array of
- // cells, along with the physical width & height. Note that the
- // physical contents will be used until the next time SetSize()
- // is called.
- GetContents() (cells []SimCell, width int, height int)
-
- // GetCursor returns the cursor details.
- GetCursor() (x int, y int, visible bool)
-
- Screen
-}
-
-func WithScreen(t *testing.T, charset string, fn func(s SimulationScreen)) func() {
+func WithScreen(t *testing.T, charset string, fn func(s Screen)) func() {
return func() {
s, e := NewSimScreen(charset)
assertNotEqual("sim screen", s, nil, t)
@@ 67,7 30,7 @@ func WithScreen(t *testing.T, charset st
func TestInitScreen(t *testing.T) {
- WithScreen(t, "", func(s SimulationScreen) {
+ WithScreen(t, "", func(s Screen) {
x, y := s.Size()
assertEqual("x", x, 80, t)
assertEqual("y", y, 25, t)
@@ 75,7 38,7 @@ func TestInitScreen(t *testing.T) {
assertEqual("character set", s.CharacterSet(), "UTF-8", t)
//Backing size is correct
- b, x, y := s.GetContents()
+ b, x, y := s.(*SimScreen).GetContents()
assertNotEqual("data", b, nil, t)
assertEqual("x", x, 80, t)
assertEqual("y", y, 25, t)
@@ 85,10 48,10 @@ func TestInitScreen(t *testing.T) {
}
func TestClearScreen(t *testing.T) {
- WithScreen(t, "", func(s SimulationScreen) {
+ WithScreen(t, "", func(s Screen) {
s.Clear()
- b, x, y := s.GetContents()
+ b, x, y := s.(*SimScreen).GetContents()
assertNotEqual("data", b, nil, t)
assertEqual("x", x, 80, t)
assertEqual("y", y, 25, t)
@@ 122,10 85,10 @@ func TestClearScreen(t *testing.T) {
}
func TestSetCell(t *testing.T) {
- WithScreen(t, "", func(s SimulationScreen) {
+ WithScreen(t, "", func(s Screen) {
st := StyleDefault.Background(ColorRed).Blink(true)
s.SetContent(2, 5, '@', nil, st)
- b, x, y := s.GetContents()
+ b, x, y := s.(*SimScreen).GetContents()
assertEqual("x", x, 80, t)
assertEqual("y", y, 25, t)
assertEqual("backing len", len(b), x*y, t)
@@ 142,15 105,15 @@ func TestSetCell(t *testing.T) {
}
func TestResize(t *testing.T) {
- WithScreen(t, "", func(s SimulationScreen) {
+ WithScreen(t, "", func(s Screen) {
st := StyleDefault.Background(ColorYellow).Underline(true)
s.SetContent(2, 5, '&', nil, st)
- b, _, _ := s.GetContents()
+ ss := s.(*SimScreen)
+ b, _, _ := ss.GetContents()
s.Show()
-
- s.SetSize(30, 10)
+ ss.SetSize(30, 10)
s.Show()
- b2, x2, y2 := s.GetContents()
+ b2, x2, y2 := ss.GetContents()
_ = b2
// todo So(b2, ShouldNotEqual, b)
assertEqual("x", x2, 30, t)