Jelajahi Sumber

bindings & The environment -- letStatement

runningwater 3 tahun lalu
induk
melakukan
b230e0faa1
1 mengubah file dengan 20 tambahan dan 0 penghapusan
  1. 20 0
      evaluator/evaluator_test.go

+ 20 - 0
evaluator/evaluator_test.go

@@ -161,6 +161,10 @@ func TestErrorHandling(t *testing.T) {
        		`,
 			"unknown operator: BOOLEAN + BOOLEAN",
 		},
+		{
+			"foobar",
+			"identifier not found: foobar",
+		},
 	}
 
 	for _, tt := range tests {
@@ -176,6 +180,22 @@ func TestErrorHandling(t *testing.T) {
 		}
 	}
 }
+
+func TestLetStatement(t *testing.T) {
+	tests := []struct {
+		input    string
+		expected int64
+	}{
+		{"let a = 5;a;", 5},
+		{"let a = 5 * 5;a;", 25},
+		{"let a = 5;let b = a;b;", 5},
+		{"let a = 5; let b = a;let c = a + b + 5;c;", 15},
+	}
+
+	for _, tt := range tests {
+		testIntegerObject(t, testEval(tt.input), tt.expected)
+	}
+}
 func testNullObject(t *testing.T, obj object.Object) bool {
 	if obj != NULL {
 		t.Errorf("object is not NULL. got=%T (%+v)", obj, obj)