Skip to content

Commit 2b48ceb

Browse files
committed
test: update test cases for lexical scoping and closure behavior
Modify test cases in r1, r2, and r3 directories to clarify lexical scoping and closure scenarios, including: - Updating variable assignment and function naming - Refining comments to better explain test expectations - Ensuring consistent test case structure
1 parent 1f0d5c7 commit 2b48ceb

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

test_programs/r1/1.lox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ fun foo() {
88
}
99

1010
foo(); // expect: outer
11-
var a = "inner";
11+
a = "inner";
1212
foo(); // expect: inner

test_programs/r1/4.lox

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ var counter1 = makeCounter();
1616
counter1(); // Should print 1
1717
counter1(); // Should print 2
1818

19-
var count = 0;
20-
counter1(); // Should print 1
19+
count = 0; // Global count is reset
20+
counter1(); // Should again print 1

test_programs/r2/3.lox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var add10 = makeAdder(10);
1616
print add5(3); // expect: 8
1717
print add10(3); // expect: 13
1818

19-
// Redefine the outer function but keep the closures
19+
// Redefine the outer function
2020
fun makeAdder(x) {
2121
counter = counter + 1;
2222
fun add(y) {

test_programs/r3/1.lox

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ expected_error_type: none
33
---
44
var variable = "global";
55
{
6-
fun printer() {
6+
fun f() {
77
print variable;
88
}
99

10-
printer(); // expect: global
10+
f(); // expect: global
1111
var variable = "local";
12-
printer(); // expect: global
12+
f(); // expect: global
1313
}

test_programs/r3/2.lox

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ fun global() {
66
}
77

88
{
9-
fun printer() {
9+
fun f() {
1010
global();
1111
}
1212

13-
printer();
13+
f();
1414
fun global() {
1515
print "local";
1616
}
17-
printer();
17+
f();
1818
}

test_programs/r3/3.lox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ var count = 0;
1717
counter1(); // Should print 1
1818
counter1(); // Should print 2
1919

20-
var count = 0;
20+
var count = 0; // This local variable shouldn't affect our counter
2121
counter1(); // Should print 3
2222
}

0 commit comments

Comments
 (0)