| // Copyright 2011 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| type MockTerminal struct { |
| func (c *MockTerminal) Read(data []byte) (n int, err error) { |
| if c.bytesPerRead > 0 && n > c.bytesPerRead { |
| func (c *MockTerminal) Write(data []byte) (n int, err error) { |
| c.received = append(c.received, data...) |
| func TestClose(t *testing.T) { |
| line, err := ss.ReadLine() |
| t.Errorf("Expected empty line but got: %s", line) |
| t.Errorf("Error should have been EOF but got: %s", err) |
| var keyPressTests = []struct { |
| func TestKeyPresses(t *testing.T) { |
| for i, test := range keyPressTests { |
| for j := 0; j < len(test.in); j++ { |
| line, err := ss.ReadLine() |
| t.Errorf("Line resulting from test %d (%d bytes per read) was '%s', expected '%s'", i, j, line, test.line) |
| t.Errorf("Error resulting from test %d (%d bytes per read) was '%v', expected '%v'", i, j, err, test.err) |