Skip to content

Commit

Permalink
expand unit tests for parser and evaluator (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jul 7, 2024
1 parent 2105a42 commit ec75520
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions evaluator/specialform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func TestQuote(t *testing.T) {
{"'-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 {
Expand Down
46 changes: 46 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,52 @@ func TestQuoteExpression(t *testing.T) {
},
},
},
{
name: "atom with quote symbol",
input: "(quote 1)",
expected: &ast.ConsCell{
CarField: &ast.Symbol{Token: token.Token{Type: token.SYMBOL, Literal: "quote"}, Value: "quote"},
CdrField: &ast.ConsCell{
CarField: &ast.IntegerLiteral{Token: token.Token{Type: token.INT, Literal: "1"}, Value: 1},
CdrField: &ast.Nil{Token: token.Token{Type: token.NIL, Literal: "nil"}},
},
},
},
{
name: "prefix atom with quote symbol",
input: "(quote -1)",
expected: &ast.ConsCell{
CarField: &ast.Symbol{Token: token.Token{Type: token.SYMBOL, Literal: "quote"}, Value: "quote"},
CdrField: &ast.ConsCell{
CarField: &ast.PrefixAtom{
Token: token.Token{Type: token.MINUS, Literal: "-"},
Operator: "-",
Right: &ast.IntegerLiteral{
Token: token.Token{Type: token.INT, Literal: "1"},
Value: 1,
},
},
CdrField: &ast.Nil{Token: token.Token{Type: token.NIL, Literal: "nil"}},
},
},
},
{
name: "list with quote symbol",
input: "(quote (1 2))",
expected: &ast.ConsCell{
CarField: &ast.Symbol{Token: token.Token{Type: token.SYMBOL, Literal: "quote"}, Value: "quote"},
CdrField: &ast.ConsCell{
CarField: &ast.ConsCell{
CarField: &ast.IntegerLiteral{Token: token.Token{Type: token.INT, Literal: "1"}, Value: 1},
CdrField: &ast.ConsCell{
CarField: &ast.IntegerLiteral{Token: token.Token{Type: token.INT, Literal: "2"}, Value: 2},
CdrField: &ast.Nil{Token: token.Token{Type: token.NIL, Literal: "nil"}},
},
},
CdrField: &ast.Nil{Token: token.Token{Type: token.NIL, Literal: "nil"}},
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit ec75520

Please sign in to comment.