Skip to content

Commit

Permalink
evaluate string literal (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Sep 30, 2024
1 parent ebd5e48 commit a86928e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
13 changes: 0 additions & 13 deletions evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ func evalPrefixAtom(operator string, right object.Object) object.Object {
switch operator {
case "-":
return evalMinusPrefix(right)
case "!":
return evalExclamationPrefix(right)
default:
return newError("unknown operator: %s%s", operator, right)
}
Expand All @@ -98,17 +96,6 @@ func evalMinusPrefix(right object.Object) object.Object {
return &object.Integer{Value: -value}
}

func evalExclamationPrefix(right object.Object) object.Object {
switch right {
case True:
return False
case False:
return True
default:
return newError("unknown operator: !%s", right)
}
}

func evalSymbol(symbol *ast.Symbol, env *object.Environment) object.Object {
builtintFunc, ok := builtins[symbol.Value]
if ok {
Expand Down
32 changes: 22 additions & 10 deletions evaluator/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,6 @@ func TestEvalBooleanExpression(t *testing.T) {
input: "false",
expected: false,
},
{
name: "negation of true",
input: "!true",
expected: false,
},
{
name: "negation of false",
input: "!false",
expected: true,
},
{
name: "equation symbol: return true",
input: `
Expand Down Expand Up @@ -280,6 +270,28 @@ func TestEvalBooleanExpression(t *testing.T) {
}`,
expected: false,
},
{
name: "negation of true",
input: `
{
"command": {
"symbol": "!",
"args": true
}
}`,
expected: false,
},
{
name: "negation of false",
input: `
{
"command": {
"symbol": "!",
"args": false
}
}`,
expected: true,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit a86928e

Please sign in to comment.