-
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.
Move tests into source directories (#62)
- Loading branch information
1 parent
6d84929
commit 72d7c4c
Showing
73 changed files
with
642 additions
and
750 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
2 changes: 1 addition & 1 deletion
2
evaluator/tests/type_builtins_test.go → evaluator/eval_access_expression_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package evaluator_tests | ||
package evaluator | ||
|
||
import ( | ||
"math/big" | ||
|
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,10 @@ | ||
package evaluator | ||
|
||
import ( | ||
"github.com/0xM-D/interpreter/ast" | ||
"github.com/0xM-D/interpreter/object" | ||
) | ||
|
||
func evalBooleanLiteral(node *ast.BooleanLiteral) object.Object { | ||
return nativeBoolToBooleanObject(node.Value) | ||
} |
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,13 @@ | ||
package evaluator | ||
|
||
import "testing" | ||
|
||
func TestBooleanTrueLiteral(t *testing.T) { | ||
evaluated := testEval("true") | ||
testBooleanObject(t, evaluated, true) | ||
} | ||
|
||
func TestBooleanFalseLiteral(t *testing.T) { | ||
evaluated := testEval("false") | ||
testBooleanObject(t, evaluated, false) | ||
} |
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
2 changes: 1 addition & 1 deletion
2
evaluator/tests/function_application_test.go → evaluator/eval_call_expression_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package evaluator_tests | ||
package evaluator | ||
|
||
import ( | ||
"math/big" | ||
|
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,107 @@ | ||
package evaluator | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/0xM-D/interpreter/object" | ||
) | ||
|
||
func TestAssignmentDeclaration(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expected int64 | ||
}{ | ||
{"a := 5; a;", 5}, | ||
{"a := 5 * 5; a;", 25}, | ||
{"a := 5; let b = a; b;", 5}, | ||
{"a := 5; let b = a; let c = a + b + 5; c;", 15}, | ||
} | ||
for _, tt := range tests { | ||
testIntegerObject(t, testEval(tt.input), big.NewInt(tt.expected)) | ||
} | ||
} | ||
|
||
func TestAsignmentExpression(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expected interface{} | ||
}{ | ||
{"let a = 5; a = 3;", big.NewInt(3)}, | ||
{"a := 5 * 5; a += 20;", big.NewInt(45)}, | ||
{"a := 3; b := a; a += b", big.NewInt(6)}, | ||
{"a := 5; a -= 1", big.NewInt(4)}, | ||
{"a := 5; a *= 2", big.NewInt(10)}, | ||
{"a := 50; a /= 5", big.NewInt(10)}, | ||
{`a := "a"; a += "bc"`, "abc"}, | ||
} | ||
for _, tt := range tests { | ||
switch expected := tt.expected.(type) { | ||
case *big.Int: | ||
testIntegerObject(t, testEval(tt.input), expected) | ||
case string: | ||
testStringObject(t, testEval(tt.input), expected) | ||
case bool: | ||
testBooleanObject(t, testEval(tt.input), expected) | ||
case []string: | ||
testArrayObject(t, testEval(tt.input), expected) | ||
} | ||
} | ||
} | ||
|
||
func TestTypedDeclarationStatement(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expected interface{} | ||
}{ | ||
{"int64 a = 5; a;", big.NewInt(5)}, | ||
{"string a = \"testmmm\"; a;", "testmmm"}, | ||
{"const []int a = new []int{1, 2, 3, 4}; let b = a; b;", []string{"1", "2", "3", "4"}}, | ||
{"bool a = true; let b = !a; b;", false}, | ||
{"const function(int64, int64)->int64 sum = fn(a: int64, b: int64) -> int64 { return a + b; }; sum", ExpectedFunction{ | ||
"fn(a, b) {" + "\n" + | ||
"return (a + b);" + "\n" + | ||
"}", | ||
object.FunctionObjectType{ | ||
ParameterTypes: []object.ObjectType{object.Int64Kind, object.Int64Kind}, | ||
ReturnValueType: object.Int64Kind, | ||
}, | ||
}}, | ||
{"function()->void sum = fn() -> void {}; sum", ExpectedFunction{ | ||
"fn() {\n\n}", | ||
object.FunctionObjectType{ | ||
ParameterTypes: []object.ObjectType{}, | ||
ReturnValueType: object.VoidKind, | ||
}, | ||
}}, | ||
} | ||
for _, tt := range tests { | ||
switch expected := tt.expected.(type) { | ||
case *big.Int: | ||
testIntegerObject(t, testEval(tt.input), expected) | ||
case string: | ||
testStringObject(t, testEval(tt.input), expected) | ||
case bool: | ||
testBooleanObject(t, testEval(tt.input), expected) | ||
case []string: | ||
testArrayObject(t, testEval(tt.input), expected) | ||
case ExpectedFunction: | ||
testFunctionObject(t, testEval(tt.input), expected) | ||
} | ||
} | ||
} | ||
|
||
func TestLetStatements(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expected *big.Int | ||
}{ | ||
{"let a = 5; a;", big.NewInt(5)}, | ||
{"let a = 5 * 5; a;", big.NewInt(25)}, | ||
{"let a = 5; let b = a; b;", big.NewInt(5)}, | ||
{"let a = 5; let b = a; let c = a + b + 5; c;", big.NewInt(15)}, | ||
} | ||
for _, tt := range tests { | ||
testIntegerObject(t, testEval(tt.input), tt.expected) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
evaluator/tests/explicit_type_cast_test.go → evaluator/eval_explicit_type_cast_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package evaluator_tests | ||
package evaluator | ||
|
||
import ( | ||
"math/big" | ||
|
2 changes: 1 addition & 1 deletion
2
evaluator/tests/for_statement_test.go → evaluator/eval_for_statement_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package evaluator_tests | ||
package evaluator | ||
|
||
import "testing" | ||
|
||
|
4 changes: 2 additions & 2 deletions
4
evaluator/tests/function_object_test.go → evaluator/eval_function_literal_test.go
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
evaluator/tests/if_else_expression_test.go → evaluator/eval_if_else_expression_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package evaluator_tests | ||
package evaluator | ||
|
||
import ( | ||
"math/big" | ||
|
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
2 changes: 1 addition & 1 deletion
2
evaluator/tests/index_operator_exp_test.go → evaluator/eval_index_expression_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package evaluator_tests | ||
package evaluator | ||
|
||
import ( | ||
"math/big" | ||
|
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,88 @@ | ||
package evaluator | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/0xM-D/interpreter/object" | ||
) | ||
|
||
func TestStringConcatenation(t *testing.T) { | ||
input := `"Hello" + " " + "World!"` | ||
evaluated := testEval(input) | ||
str, ok := evaluated.(*object.String) | ||
if !ok { | ||
t.Fatalf("object is not String. got=%T (%+v)", evaluated, evaluated) | ||
} | ||
if str.Value != "Hello World!" { | ||
t.Errorf("String has wrong value. got=%q", str.Value) | ||
} | ||
} | ||
|
||
func TestBooleanInfixExpression(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
|
||
expected bool | ||
}{ | ||
{"1 < 2", true}, | ||
{"1 > 2", false}, | ||
{"1 < 1", false}, | ||
{"1 > 1", false}, | ||
{"1 == 1", true}, | ||
{"1 != 1", false}, | ||
{"1 == 2", false}, | ||
{"1 != 2", true}, | ||
{"true == true", true}, | ||
{"false == false", true}, | ||
{"true == false", false}, | ||
{"true != false", true}, | ||
{"false != true", true}, | ||
{"(1 < 2) == true", true}, | ||
{"(1 < 2) == false", false}, | ||
{"(1 > 2) == true", false}, | ||
{"(1 > 2) == false", true}, | ||
{"true && true", true}, | ||
{"false && false", false}, | ||
{"false && true", false}, | ||
{"true || true", true}, | ||
{"false || false", false}, | ||
{"false || true", true}, | ||
{"(1 < 2) && (2 < 3)", true}, | ||
} | ||
for _, tt := range tests { | ||
evaluated := testEval(tt.input) | ||
testBooleanObject(t, evaluated, tt.expected) | ||
} | ||
} | ||
|
||
func TestFloatInfixExpression(t *testing.T) { | ||
|
||
tests := []struct { | ||
input string | ||
expected interface{} | ||
}{ | ||
{"5.0", 5.0}, | ||
{"-6.0", -6.0}, | ||
{"1.1f", float32(1.1)}, | ||
{"-5f", float32(-5.0)}, | ||
{"-10.22233344f", -float32(10.22233344)}, | ||
{"2.0 + 2", 4.0}, | ||
{"2.0f * 3", float32(6.0)}, | ||
{"5.0 + 5.0f + .5 + 5 - 10", 5.5}, | ||
{"2.0 * 2f * 2.0f * 2 * 2", 32.0}, | ||
{"-50 + 100 + -50", big.NewInt(0)}, | ||
{"5f * 2 + 10f", float32(20)}, | ||
{"5 + 2f * 10", float32(25)}, | ||
{"20f + 2.0 * -10f", 0.0}, | ||
{"51 / 2 * 2f + 10f", float32(60)}, | ||
{"2 * (5f + 10.0)", 30.0}, | ||
{"3f * 3f * 3f + 10", float32(37.0)}, | ||
{"3 * (3f * 3) + 10", float32(37.0)}, | ||
{"(5.0f + 10 * 2 + 11f / 3) * 2 + -10", float32(47.333333333333336)}, | ||
} | ||
for _, tt := range tests { | ||
evaluated := testEval(tt.input) | ||
testNumber(t, evaluated, tt.expected) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
evaluator/tests/eval_integer_exp_test.go → evaluator/eval_integer_exp_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package evaluator_tests | ||
package evaluator | ||
|
||
import ( | ||
"math/big" | ||
|
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
2 changes: 1 addition & 1 deletion
2
evaluator/tests/bang_operator_test.go → evaluator/eval_prefix_expression_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package evaluator_tests | ||
package evaluator | ||
|
||
import "testing" | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
evaluator/tests/return_statement_test.go → evaluator/eval_return_statement_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package evaluator_tests | ||
package evaluator | ||
|
||
import ( | ||
"math/big" | ||
|
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,10 @@ | ||
package evaluator | ||
|
||
import ( | ||
"github.com/0xM-D/interpreter/ast" | ||
"github.com/0xM-D/interpreter/object" | ||
) | ||
|
||
func evalStringLiteral(node *ast.StringLiteral) object.Object { | ||
return &object.String{Value: node.Value} | ||
} |
Oops, something went wrong.