diff --git a/event_test.go b/event_test.go index c9f2415..93ff4d8 100644 --- a/event_test.go +++ b/event_test.go @@ -35,11 +35,11 @@ func eventLoop(s Screen, evch chan Event) { func TestMouseEvents(t *testing.T) { - s, ss := mkTestScreen(t, "") + s := mkTestScreen(t, "") defer s.Fini() s.EnableMouse() - ss.InjectMouse(4, 9, Button1, ModCtrl) + s.InjectMouse(4, 9, Button1, ModCtrl) evch := make(chan Event) em := &EventMouse{} done := false @@ -71,11 +71,11 @@ func TestMouseEvents(t *testing.T) { func TestChannelMouseEvents(t *testing.T) { - s, ss := mkTestScreen(t, "") + s := mkTestScreen(t, "") defer s.Fini() s.EnableMouse() - ss.InjectMouse(4, 9, Button1, ModCtrl) + s.InjectMouse(4, 9, Button1, ModCtrl) evch := make(chan Event) quit := make(chan struct{}) em := new(EventMouse) diff --git a/runes_test.go b/runes_test.go index 36fc78f..88bca5d 100644 --- a/runes_test.go +++ b/runes_test.go @@ -19,7 +19,7 @@ import ( ) func TestCanDisplayUTF8(t *testing.T) { - s, _ := mkTestScreen(t, "UTF-8") + s := mkTestScreen(t, "UTF-8") defer s.Fini() if s.CharacterSet() != "UTF-8" { @@ -39,7 +39,7 @@ func TestCanDisplayUTF8(t *testing.T) { } } func TestCanDisplayASCII(t *testing.T) { - s, _ := mkTestScreen(t, "US-ASCII") + s := mkTestScreen(t, "US-ASCII") defer s.Fini() if s.CharacterSet() != "US-ASCII" { @@ -60,7 +60,7 @@ func TestCanDisplayASCII(t *testing.T) { } func TestRuneFallbacks(t *testing.T) { - s, _ := mkTestScreen(t, "US-ASCII") + s := mkTestScreen(t, "US-ASCII") defer s.Fini() if s.CharacterSet() != "US-ASCII" { t.Errorf("Wrong character set: %v", s.CharacterSet()) diff --git a/sim_test.go b/sim_test.go index cf992bb..0c1949f 100644 --- a/sim_test.go +++ b/sim_test.go @@ -18,20 +18,20 @@ import ( "testing" ) -func mkTestScreen(t *testing.T, charset string) (Screen, SimulationScreen) { - s, ss := NewSimulationScreen(charset) - if s == nil || ss == nil { +func mkTestScreen(t *testing.T, charset string) SimulationScreen { + s := NewSimulationScreen(charset) + if s == nil { t.Fatalf("Failed to get simulation screen") } if e := s.Init(); e != nil { t.Fatalf("Failed to initialize screen: %v", e) } - return s, ss + return s } func TestInitScreen(t *testing.T) { - s, ss := mkTestScreen(t, "") + s := mkTestScreen(t, "") defer s.Fini() if x, y := s.Size(); x != 80 || y != 25 { @@ -40,16 +40,16 @@ func TestInitScreen(t *testing.T) { if s.CharacterSet() != "UTF-8" { t.Fatalf("Character Set (%v) not UTF-8", s.CharacterSet()) } - if b, x, y := ss.GetContents(); len(b) != x*y || x != 80 || y != 25 { + if b, x, y := s.GetContents(); len(b) != x*y || x != 80 || y != 25 { t.Fatalf("Contents (%v, %v, %v) wrong", len(b), x, y) } } func TestClearScreen(t *testing.T) { - s, ss := mkTestScreen(t, "") + s := mkTestScreen(t, "") defer s.Fini() s.Clear() - b, x, y := ss.GetContents() + b, x, y := s.GetContents() if len(b) != x*y || x != 80 || y != 25 { t.Fatalf("Contents (%v, %v, %v) wrong", len(b), x, y) } @@ -65,10 +65,10 @@ func TestClearScreen(t *testing.T) { func TestSetCell(t *testing.T) { st := StyleDefault.Background(ColorRed).Blink(true) - s, ss := mkTestScreen(t, "") + s := mkTestScreen(t, "") defer s.Fini() s.SetCell(2, 5, st, '@') - b, _, _ := ss.GetContents() + b, _, _ := s.GetContents() s.Show() if len(b) != 80*25 { t.Fatalf("Wrong content size") @@ -83,10 +83,10 @@ func TestSetCell(t *testing.T) { func TestResize(t *testing.T) { st := StyleDefault.Background(ColorYellow).Underline(true) - s, ss := mkTestScreen(t, "") + s := mkTestScreen(t, "") defer s.Fini() s.SetCell(2, 5, st, '&') - b, x, y := ss.GetContents() + b, x, y := s.GetContents() s.Show() cell := &b[5*80+2] @@ -97,7 +97,7 @@ func TestResize(t *testing.T) { } s.SetSize(30, 10) s.Show() - b2, x2, y2 := ss.GetContents() + b2, x2, y2 := s.GetContents() if len(b2) == len(b) || x2 == x || y2 == y { t.Errorf("Screen parameters should not match") } @@ -111,17 +111,17 @@ func TestResize(t *testing.T) { } func TestBeep(t *testing.T) { - s, ss := mkTestScreen(t, "") + s := mkTestScreen(t, "") defer s.Fini() - b0, x0, y0 := ss.GetContents() + b0, x0, y0 := s.GetContents() if err := s.Beep(); err != nil { t.Errorf("could not beep: %v", err) } s.Show() - b1, x1, y1 := ss.GetContents() + b1, x1, y1 := s.GetContents() if x0 != x1 { t.Fatalf("screen width changed unexpectedly from %d to %d", x0, x1) } diff --git a/simulation.go b/simulation.go index 61814cf..ff6dae1 100644 --- a/simulation.go +++ b/simulation.go @@ -23,19 +23,21 @@ import ( // NewSimulationScreen returns a SimulationScreen. Note that // SimulationScreen is also a Screen. -func NewSimulationScreen(charset string) (Screen, SimulationScreen) { +func NewSimulationScreen(charset string) SimulationScreen { if charset == "" { charset = "UTF-8" } ss := &simscreen{charset: charset} - s := &baseScreen{screenImpl: ss} - return s, ss + ss.Screen = &baseScreen{screenImpl: ss} + return ss } // 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 { + Screen + // 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 @@ -97,6 +99,7 @@ type simscreen struct { fillstyle Style fallback map[rune]string + Screen sync.Mutex } diff --git a/style_test.go b/style_test.go index 9d23b4c..861c65f 100644 --- a/style_test.go +++ b/style_test.go @@ -19,7 +19,7 @@ import ( ) func TestStyle(t *testing.T) { - s, _ := mkTestScreen(t, "") + s := mkTestScreen(t, "") defer s.Fini() style := StyleDefault