aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-17 06:52:23 +0000
committer_ov4 <ov4@ov4.org>2026-10-17 06:52:23 +0000
commit39661855c0816ac248be437704c76f58359cb5f0 (patch)
tree202b014805e40208e3adb861f4a97d31770f13e6 /tests
parentc89477d615fb0ce4d89786ef848ffe6aca1da088 (diff)
feat(classes): construct declared objects and nested fields and arrays
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/i/class-constructors/case.json1
-rw-r--r--tests/i/class-constructors/expected.txt17
-rw-r--r--tests/i/class-constructors/notes.md5
-rw-r--r--tests/i/class-constructors/program.cps42
-rw-r--r--tests/i/class-new-methods/notes.md2
-rw-r--r--tests/i/class-new-methods/program.cps2
-rw-r--r--tests/iii/class-constructor-default-errors/case.json32
-rw-r--r--tests/iii/class-constructor-default-errors/program.cps21
8 files changed, 120 insertions, 2 deletions
diff --git a/tests/i/class-constructors/case.json b/tests/i/class-constructors/case.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/tests/i/class-constructors/case.json
@@ -0,0 +1 @@
+{}
diff --git a/tests/i/class-constructors/expected.txt b/tests/i/class-constructors/expected.txt
new file mode 100644
index 0000000..cb57e7c
--- /dev/null
+++ b/tests/i/class-constructors/expected.txt
@@ -0,0 +1,17 @@
+leaf:0
+leaf:0
+name
+0
+leaf:0
+leaf:0
+leaf:0
+leaf:0
+3,3
+leaf:0
+leaf:0
+pair:6
+3,3
+leaf:0
+3
+leaf:0
+3
diff --git a/tests/i/class-constructors/notes.md b/tests/i/class-constructors/notes.md
new file mode 100644
index 0000000..0145a0a
--- /dev/null
+++ b/tests/i/class-constructors/notes.md
@@ -0,0 +1,5 @@
+# Class constructors
+
+Human review: pending. Expected output was independently traced by AI.
+
+The project extends guide section 10.2 with automatic stack, field and array construction. Leaf observes its zeroed Value before setting it to 3. A and B each construct once; Named stores name; Plain has no constructor and stays zero. Four array elements each construct once. Wrapped constructs Pair's two Leaf fields in order before Pair observes their sum of 6. Each execution of the loop declaration zeroes and constructs Local again, so both iterations print leaf:0 then 3 despite storing 99 in the previous iteration.
diff --git a/tests/i/class-constructors/program.cps b/tests/i/class-constructors/program.cps
new file mode 100644
index 0000000..2b85b4d
--- /dev/null
+++ b/tests/i/class-constructors/program.cps
@@ -0,0 +1,42 @@
+CLASS Leaf
+ Value : INTEGER
+ PROCEDURE New()
+ OUTPUT "leaf:", Value
+ Value <- 3
+ ENDPROCEDURE
+ENDCLASS
+CLASS Pair
+ First : Leaf
+ Second : Leaf
+ PROCEDURE NEW()
+ OUTPUT "pair:", First.Value + Second.Value
+ ENDPROCEDURE
+ENDCLASS
+TYPE Wrapped
+ DECLARE Item : Pair
+ENDTYPE
+CLASS Named
+ Text : STRING
+ PROCEDURE NEW(Name : STRING)
+ Text <- Name
+ ENDPROCEDURE
+ENDCLASS
+CLASS Plain
+ Value : INTEGER
+ENDCLASS
+DECLARE A : Leaf
+DECLARE B : Leaf()
+DECLARE N : Named("name")
+OUTPUT N.Text
+DECLARE P : Plain()
+OUTPUT P.Value
+DECLARE Items : ARRAY[-1:0, 2:3] OF Leaf
+OUTPUT Items[-1,2].Value, ",", Items[0,3].Value
+DECLARE W : Wrapped
+OUTPUT W.Item.First.Value, ",", W.Item.Second.Value
+DECLARE Index : INTEGER
+FOR Index <- 1 TO 2
+ DECLARE Local : Leaf
+ OUTPUT Local.Value
+ Local.Value <- 99
+NEXT Index
diff --git a/tests/i/class-new-methods/notes.md b/tests/i/class-new-methods/notes.md
index 53192fb..cc7cffa 100644
--- a/tests/i/class-new-methods/notes.md
+++ b/tests/i/class-new-methods/notes.md
@@ -2,4 +2,4 @@
Human review: pending. Expected output was independently traced by AI.
-NEW is an ordinary procedure: the bare member call stores x, CALL with mixed case stores call, and Reset calls this.NEW to store again. DECLARE is extended with arguments in the next implementation step.
+NEW is an ordinary procedure: the bare member call stores x, CALL with mixed case stores call, and Reset calls this.NEW to store again. The initial constructor value is overwritten before output.
diff --git a/tests/i/class-new-methods/program.cps b/tests/i/class-new-methods/program.cps
index 573fe0f..880f538 100644
--- a/tests/i/class-new-methods/program.cps
+++ b/tests/i/class-new-methods/program.cps
@@ -7,7 +7,7 @@ CLASS Box
this.NEW("again")
ENDPROCEDURE
ENDCLASS
-DECLARE Obj : Box
+DECLARE Obj : Box("initial")
Obj.NEW("x")
OUTPUT Obj.Value
CALL Obj.new("call")
diff --git a/tests/iii/class-constructor-default-errors/case.json b/tests/iii/class-constructor-default-errors/case.json
new file mode 100644
index 0000000..adcefe8
--- /dev/null
+++ b/tests/iii/class-constructor-default-errors/case.json
@@ -0,0 +1,32 @@
+{
+ "errors": [
+ {
+ "reason": "Incorrect # arguments passed to Required.NEW",
+ "line": 15
+ },
+ {
+ "reason": "Incorrect # arguments passed to Required.NEW",
+ "line": 16
+ },
+ {
+ "reason": "has no constructor NEW",
+ "line": 17
+ },
+ {
+ "reason": "Cannot access private method NEW",
+ "line": 18
+ },
+ {
+ "reason": "Incorrect # arguments passed to Required.NEW",
+ "line": 19
+ },
+ {
+ "reason": "Incorrect # arguments passed to Required.NEW",
+ "line": 20
+ },
+ {
+ "reason": "Constructor arguments require a class type",
+ "line": 21
+ }
+ ]
+}
diff --git a/tests/iii/class-constructor-default-errors/program.cps b/tests/iii/class-constructor-default-errors/program.cps
new file mode 100644
index 0000000..43dfef7
--- /dev/null
+++ b/tests/iii/class-constructor-default-errors/program.cps
@@ -0,0 +1,21 @@
+CLASS Required
+ PROCEDURE NEW(Number : INTEGER)
+ ENDPROCEDURE
+ENDCLASS
+CLASS Plain
+ Value : INTEGER
+ENDCLASS
+CLASS Hidden
+ PRIVATE PROCEDURE NEW()
+ ENDPROCEDURE
+ENDCLASS
+TYPE Wrapped
+ DECLARE Item : Required
+ENDTYPE
+DECLARE Missing : Required
+DECLARE EmptyArgs : Required()
+DECLARE Extra : Plain(1)
+DECLARE PrivateObject : Hidden
+DECLARE Items : ARRAY[1:2] OF Required
+DECLARE Nested : Wrapped
+DECLARE Scalar : INTEGER()