Skip to content

Commit

Permalink
test: add a test for repl
Browse files Browse the repository at this point in the history
  • Loading branch information
Aden-Q committed May 5, 2024
1 parent ea1cace commit 8df639f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Monkey is an interpreted language written in Go. *This project is still under de
+ [ ] feat: scroll in command history with up and down keys
+ [ ] feat: PrettyPrint, color, AST, etc
+ [ ] feat: sys call such as print(...)
+ [ ] feat: add a helper for available functions

## References

Expand Down
12 changes: 6 additions & 6 deletions internal/repl/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (r *repl) Start(in io.ReadCloser, out io.WriteCloser, userName string) {
l := lexer.New()
p := parser.New(l)

io.WriteString(out, MONKEY_FACE)
io.WriteString(out, fmt.Sprintf("Hello %s! This is the Monkey programming language!\n", userName))
fmt.Print(MONKEY_FACE)
fmt.Printf("Hello %s! This is the Monkey programming language!\n", userName)

for {
fmt.Print(PROMPT)
Expand All @@ -61,15 +61,15 @@ func (r *repl) Start(in io.ReadCloser, out io.WriteCloser, userName string) {
printParserErrors(out, errs)
}

io.WriteString(out, program.String())
io.WriteString(out, "\n")
// TODO: PrettyPrint
fmt.Println(program.String())
}
}

func printParserErrors(out io.WriteCloser, errs []error) {
io.WriteString(out, "parser errors:\n")
fmt.Println("parser errors:")

for _, err := range errs {
io.WriteString(out, "\t"+err.Error()+"\n")
fmt.Println("\t" + err.Error())
}
}
8 changes: 6 additions & 2 deletions internal/repl/repl_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package repl_test

import (
"github.com/aden-q/monkey/internal/repl"
. "github.com/onsi/ginkgo/v2"
_ "github.com/onsi/gomega"
. "github.com/onsi/gomega"
)

var _ = Describe("Repl", func() {

It("New", func() {
r := repl.New(repl.Config{})
Expect(r).ToNot(BeNil())
})
})

0 comments on commit 8df639f

Please sign in to comment.