bitwise operators and boolean operators
Some checks failed
Test / build (push) Waiting to run
Build / build (push) Has been cancelled

This commit is contained in:
Chuck Smith
2024-03-23 10:00:02 -04:00
parent cbb430b47d
commit ef8c8f8f04
13 changed files with 427 additions and 188 deletions

View File

@@ -13,7 +13,7 @@ import (
func TestEvalIntegerExpression(t *testing.T) {
tests := []struct {
input string
expected int64
expected interface{}
}{
{"5", 5},
{"10", 10},
@@ -30,12 +30,21 @@ func TestEvalIntegerExpression(t *testing.T) {
{"3 * 3 * 3 + 10", 37},
{"3 * (3 * 3) + 10", 37},
{"(5 + 10 * 2 + 15 / 3) * 2 + -10", 50},
{"!1", false},
{"~1", -2},
{"5 % 2", 1},
{"1 | 2", 3},
{"2 ^ 4", 6},
{"3 & 6", 2},
}
for _, tt := range tests {
evaluated := testEval(tt.input)
testIntegerObject(t, evaluated, tt.expected)
if expected, ok := tt.expected.(int64); ok {
testIntegerObject(t, evaluated, expected)
} else if expected, ok := tt.expected.(bool); ok {
testBooleanObject(t, evaluated, expected)
}
}
}
@@ -46,6 +55,16 @@ func TestEvalBooleanExpression(t *testing.T) {
}{
{"true", true},
{"false", false},
{"!true", false},
{"!false", true},
{"true && true", true},
{"false && true", false},
{"true && false", false},
{"false && false", false},
{"true || true", true},
{"false || true", true},
{"true || false", true},
{"false || false", false},
{"1 < 2", true},
{"1 > 2", false},
{"1 < 1", false},
@@ -78,25 +97,6 @@ func TestEvalBooleanExpression(t *testing.T) {
}
}
func TestBangOperator(t *testing.T) {
tests := []struct {
input string
expected bool
}{
{"!true", false},
{"!false", true},
{"!5", false},
{"!!true", true},
{"!!false", false},
{"!!5", true},
}
for _, tt := range tests {
evaluated := testEval(tt.input)
testBooleanObject(t, evaluated, tt.expected)
}
}
func TestIfElseExpression(t *testing.T) {
tests := []struct {
input string