Skip to content

Commit c9156a6

Browse files
committed
feat: refine class inheritance test cases and introduce runtime error scenarios
1 parent fb2c854 commit c9156a6

File tree

6 files changed

+38
-17
lines changed

6 files changed

+38
-17
lines changed

test_programs/i1/1.lox

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
---
22
expected_error_type: none
33
---
4-
class Doughnut {
5-
cook() {
6-
print "Fry until golden brown.";
7-
}
8-
}
4+
class Doughnut {}
95

106
class BostonCream < Doughnut {}
117

12-
BostonCream().cook();
8+
print Doughnut();
9+
print BostonCream();

test_programs/i1/2.lox

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
---
22
expected_error_type: none
33
---
4-
class A {}
4+
{
5+
class A {}
56

6-
fun f() {
77
class B < A {}
8-
return B;
9-
}
108

11-
print f(); // expect: B
9+
class C < A {}
10+
11+
print A();
12+
print B();
13+
print C();
14+
}

test_programs/i1/3.lox

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
---
2-
expected_error_type: compile
2+
expected_error_type: none
33
---
4-
class Foo < Foo {} // Error at 'Foo': A class can't inherit from itself.
4+
class A {}
5+
6+
fun f() {
7+
class B < A {}
8+
return B;
9+
}
10+
11+
print f(); // expect: B

test_programs/i1/4.lox

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
---
22
expected_error_type: compile
33
---
4-
{
5-
class Foo < Foo {} // Error at 'Foo': A class can't inherit from itself.
6-
}
7-
// [c line 5] Error at end: Expect '}' after block.
4+
class Foo < Foo {} // Error at 'Foo': A class can't inherit from itself.

test_programs/i1/5.lox

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
expected_error_type: runtime
3+
---
4+
fun A() {}
5+
6+
class B < A {}
7+
8+
print A();
9+
print B();

test_programs/i1/6.lox

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
expected_error_type: runtime
3+
---
4+
var A = "class";
5+
6+
class B < A {}
7+
8+
print B();

0 commit comments

Comments
 (0)