mirror of
https://github.com/tjboldt/Apple2-IO-RPi.git
synced 2024-06-10 01:29:31 +00:00
More lint fixes
This commit is contained in:
parent
ce0ee8acc9
commit
2e16a9e361
|
@ -12,6 +12,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// MockIoData is used to verify tests were successful
|
||||
type MockIoData struct {
|
||||
BytesToRead []byte
|
||||
BytesWritten []byte
|
||||
|
@ -25,16 +26,19 @@ type MockIo struct {
|
|||
Data *MockIoData
|
||||
}
|
||||
|
||||
// Init is only here to complete A2Io interface
|
||||
func (mockIo MockIo) Init() {
|
||||
|
||||
}
|
||||
|
||||
// WriteByte mocks writing a byte to the Apple II
|
||||
func (mockIo MockIo) WriteByte(data byte) error {
|
||||
mockIo.Data.BytesWritten[mockIo.Data.NumberBytesWritten] = data
|
||||
mockIo.Data.NumberBytesWritten++
|
||||
return mockIo.Data.ErrorToThrow
|
||||
}
|
||||
|
||||
// WriteString mocks writing a string to the Apple II
|
||||
func (mockIo MockIo) WriteString(outString string) error {
|
||||
for i, b := range outString {
|
||||
mockIo.Data.BytesWritten[i+mockIo.Data.NumberBytesWritten] = byte(b)
|
||||
|
@ -43,6 +47,7 @@ func (mockIo MockIo) WriteString(outString string) error {
|
|||
return mockIo.Data.ErrorToThrow
|
||||
}
|
||||
|
||||
// WriteBlock mocks writing a block to the Apple II
|
||||
func (mockIo MockIo) WriteBlock(buffer []byte) error {
|
||||
for i, b := range buffer {
|
||||
mockIo.Data.BytesWritten[i+mockIo.Data.NumberBytesWritten] = b
|
||||
|
@ -51,6 +56,7 @@ func (mockIo MockIo) WriteBlock(buffer []byte) error {
|
|||
return mockIo.Data.ErrorToThrow
|
||||
}
|
||||
|
||||
// WriteBuffer mocks writing a buffer to the Apple II
|
||||
func (mockIo MockIo) WriteBuffer(buffer []byte) error {
|
||||
for i, b := range buffer {
|
||||
mockIo.Data.BytesWritten[i+mockIo.Data.NumberBytesWritten] = b
|
||||
|
@ -59,17 +65,19 @@ func (mockIo MockIo) WriteBuffer(buffer []byte) error {
|
|||
return mockIo.Data.ErrorToThrow
|
||||
}
|
||||
|
||||
// ReadByte mocks reading a byte from the Apple II
|
||||
func (mockIo MockIo) ReadByte() (byte, error) {
|
||||
b := mockIo.Data.BytesToRead[mockIo.Data.NumberBytesRead]
|
||||
mockIo.Data.NumberBytesRead++
|
||||
return b, mockIo.Data.ErrorToThrow
|
||||
}
|
||||
|
||||
// ReadString mocks reading a null terminated string from the Apple II
|
||||
func (mockIo MockIo) ReadString() (string, error) {
|
||||
builder := strings.Builder{}
|
||||
for {
|
||||
if mockIo.Data.NumberBytesRead > len(mockIo.Data.BytesToRead) {
|
||||
return "", errors.New("Read more data than available")
|
||||
return "", errors.New("read more data than available")
|
||||
}
|
||||
builder.WriteByte(mockIo.Data.BytesToRead[mockIo.Data.NumberBytesRead])
|
||||
mockIo.Data.NumberBytesRead++
|
||||
|
@ -81,9 +89,10 @@ func (mockIo MockIo) ReadString() (string, error) {
|
|||
return builder.String(), mockIo.Data.ErrorToThrow
|
||||
}
|
||||
|
||||
// ReadBlock mocks reading a 512 byte block from the Apple II
|
||||
func (mockIo MockIo) ReadBlock(buffer []byte) error {
|
||||
if mockIo.Data.NumberBytesRead+512 > len(mockIo.Data.BytesToRead) {
|
||||
return errors.New("Read more data than available")
|
||||
return errors.New("read more data than available")
|
||||
}
|
||||
for i := 0; i < 512; i++ {
|
||||
buffer[i] = mockIo.Data.BytesToRead[mockIo.Data.NumberBytesRead]
|
||||
|
|
|
@ -18,25 +18,30 @@ import (
|
|||
type UserIo struct {
|
||||
}
|
||||
|
||||
// Init is only here to complete A2Io interface
|
||||
func (userIo UserIo) Init() {
|
||||
|
||||
}
|
||||
|
||||
// WriteByte simulates writing to the Apple II but uses stdout instead
|
||||
func (userIo UserIo) WriteByte(data byte) error {
|
||||
fmt.Printf("WriteByte: %02X\n", data)
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteString simulates writing to the Apple II but uses stdout instead
|
||||
func (userIo UserIo) WriteString(outString string) error {
|
||||
fmt.Printf("WriteString: %s\n", strings.ReplaceAll(outString, "\r", "\n"))
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteBlock simulates writing to the Apple II but uses stdout instead
|
||||
func (userIo UserIo) WriteBlock(buffer []byte) error {
|
||||
fmt.Printf("WriteBlock:\n")
|
||||
return userIo.WriteBuffer(buffer)
|
||||
}
|
||||
|
||||
// WriteBuffer simulates writing to the Apple II but uses stdout instead
|
||||
func (userIo UserIo) WriteBuffer(buffer []byte) error {
|
||||
fmt.Printf("WriteBuffer:\n")
|
||||
for i, b := range buffer {
|
||||
|
@ -49,6 +54,7 @@ func (userIo UserIo) WriteBuffer(buffer []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// ReadByte simulates reading to the Apple II but uses stdin instead
|
||||
func (userIo UserIo) ReadByte() (byte, error) {
|
||||
fmt.Printf("ReadByte: ")
|
||||
var b byte
|
||||
|
@ -57,6 +63,7 @@ func (userIo UserIo) ReadByte() (byte, error) {
|
|||
return b, nil
|
||||
}
|
||||
|
||||
// ReadString simulates reading to the Apple II but uses stdin instead
|
||||
func (userIo UserIo) ReadString() (string, error) {
|
||||
fmt.Printf("ReadString: ")
|
||||
var s string
|
||||
|
@ -65,6 +72,7 @@ func (userIo UserIo) ReadString() (string, error) {
|
|||
return s, nil
|
||||
}
|
||||
|
||||
// ReadBlock should simulate reading to the Apple II but is not yet supported
|
||||
func (userIo UserIo) ReadBlock(buffer []byte) error {
|
||||
fmt.Printf("ReadBlock: (Not supported)")
|
||||
return errors.New("ReadBlock not supported")
|
||||
|
|
Loading…
Reference in New Issue
Block a user