diff --git a/brainfuck.go b/brainfuck.go index 40328f0..e7f1f4e 100644 --- a/brainfuck.go +++ b/brainfuck.go @@ -4,6 +4,7 @@ package gofuck import ( "bufio" "fmt" + "io" "os" ) @@ -19,12 +20,16 @@ type Machine struct { } // 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) return &Machine{ array: bytes, ptr: 0, - reader: bufio.NewReader(os.Stdin), + reader: bufio.NewReader(in), } } diff --git a/gofuck/main.go b/gofuck/main.go index b741461..27f1237 100644 --- a/gofuck/main.go +++ b/gofuck/main.go @@ -9,7 +9,7 @@ import ( ) func main() { - m := gofuck.New() + m := gofuck.NewStdin() instructions := make([]byte, 0) // read in the instructions