stdin: add ability to provide a reader for stdin

This commit is contained in:
Chris Sexton 2019-10-20 07:22:40 -04:00
parent 6ef9bee1b7
commit 3f83afe287
2 changed files with 8 additions and 3 deletions

View File

@ -4,6 +4,7 @@ package gofuck
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"io"
"os" "os"
) )
@ -19,12 +20,16 @@ type Machine struct {
} }
// Returns a new machine with standard memory size // Returns a new machine with standard memory size
func New() *Machine { func NewStdin() *Machine {
return New(os.Stdin)
}
func New(in io.Reader) *Machine {
bytes := make([]byte, MEM_STD) bytes := make([]byte, MEM_STD)
return &Machine{ return &Machine{
array: bytes, array: bytes,
ptr: 0, ptr: 0,
reader: bufio.NewReader(os.Stdin), reader: bufio.NewReader(in),
} }
} }

View File

@ -9,7 +9,7 @@ import (
) )
func main() { func main() {
m := gofuck.New() m := gofuck.NewStdin()
instructions := make([]byte, 0) instructions := make([]byte, 0)
// read in the instructions // read in the instructions