# HG changeset patch # User telesto # Date 1513836843 -3600 # Thu Dec 21 07:14:03 2017 +0100 # Node ID 99db993f9d6d775bd0e205ee0e7cf0f88a5dd4f8 # Parent 3236449f679698e916c604d8dc3f45bee2ac7369 remove SimulationScreen interface diff --git a/event_test.go b/event_test.go --- a/event_test.go +++ b/event_test.go @@ -35,10 +35,10 @@ func TestMouseEvents(t *testing.T) { - WithScreen(t, "", func(s SimulationScreen) { + WithScreen(t, "", func(s Screen) { s.EnableMouse() - s.InjectMouse(4, 9, Button1, ModCtrl) + s.(*SimScreen).InjectMouse(4, 9, Button1, ModCtrl) evch := make(chan Event) go eventLoop(s, evch) diff --git a/runes_test.go b/runes_test.go --- a/runes_test.go +++ b/runes_test.go @@ -20,7 +20,7 @@ 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 @@ 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 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 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) diff --git a/sim_test.go b/sim_test.go --- a/sim_test.go +++ b/sim_test.go @@ -18,44 +18,7 @@ "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 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 @@ 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 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 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 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) diff --git a/simulation.go b/simulation.go --- a/simulation.go +++ b/simulation.go @@ -69,6 +69,8 @@ Runes []rune } +var _ Screen = new(SimScreen) + type SimScreen struct { physw int physh int