-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from JunNishimura/feature/add_quote_function
add quote function
- Loading branch information
Showing
11 changed files
with
251 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package evaluator | ||
|
||
import "testing" | ||
|
||
func TestLambdaExpression(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expected int64 | ||
}{ | ||
{"((lambda () 5))", 5}, | ||
{"((lambda (x) x) 5)", 5}, | ||
{"((lambda (x y) (+ x y)) 5 5)", 10}, | ||
{"(+ ((lambda () 1)) ((lambda (x y) (+ x y)) 1 2))", 4}, | ||
} | ||
|
||
for _, tt := range tests { | ||
evaluated := testEval(tt.input) | ||
testIntegerObject(t, evaluated, tt.expected) | ||
} | ||
} | ||
|
||
func TestQuote(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expected string | ||
}{ | ||
{"'5", "5"}, | ||
{"'-5", "-5"}, | ||
{"'(+ 1 2)", "(+ 1 2)"}, | ||
{"'(+ . (1 . (2 . nil)))", "(+ 1 2)"}, | ||
{"(quote 5)", "5"}, | ||
{"(quote -5)", "-5"}, | ||
{"(quote (+ 1 2))", "(+ 1 2)"}, | ||
{"(quote (+ . (1 . (2 . nil))))", "(+ 1 2)"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
evaluated := testEval(tt.input) | ||
if evaluated.Inspect() != tt.expected { | ||
t.Errorf("expected=%q, got=%q", tt.expected, evaluated.Inspect()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.