aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-18 06:11:42 +0000
committer_ov4 <ov4@ov4.org>2026-10-18 06:11:42 +0000
commit5a67f4e3833c2acca4a351f5dd613bc08f04bfc0 (patch)
tree6d75f5d13931ba0f7c15d286028049a421a6e974 /tests
parentb17f101cfc75565f9991c856ec62f1e17b0ab104 (diff)
feat(operators): document overloads and cover remaining operator forms
Add fixed cases for every supported operator, imported global and member operators, CASE comparisons, and declared result type errors. Document syntax, exact matching, access rules and temporary receiver lifetimes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/i/multifile-operators/case.json7
-rw-r--r--tests/i/multifile-operators/expected.txt5
-rw-r--r--tests/i/multifile-operators/notes.md7
-rw-r--r--tests/i/multifile-operators/operators.cps4
-rw-r--r--tests/i/multifile-operators/program.cps21
-rw-r--r--tests/i/multifile-operators/types.cps12
-rw-r--r--tests/i/operator-kinds/case.json1
-rw-r--r--tests/i/operator-kinds/expected.txt18
-rw-r--r--tests/i/operator-kinds/notes.md7
-rw-r--r--tests/i/operator-kinds/program.cps70
-rw-r--r--tests/iii/operator-result-errors/case.json20
-rw-r--r--tests/iii/operator-result-errors/notes.md3
-rw-r--r--tests/iii/operator-result-errors/program.cps20
13 files changed, 195 insertions, 0 deletions
diff --git a/tests/i/multifile-operators/case.json b/tests/i/multifile-operators/case.json
new file mode 100644
index 0000000..a71b210
--- /dev/null
+++ b/tests/i/multifile-operators/case.json
@@ -0,0 +1,7 @@
+{
+ "sources": [
+ "program.cps",
+ "operators.cps",
+ "types.cps"
+ ]
+}
diff --git a/tests/i/multifile-operators/expected.txt b/tests/i/multifile-operators/expected.txt
new file mode 100644
index 0000000..7642205
--- /dev/null
+++ b/tests/i/multifile-operators/expected.txt
@@ -0,0 +1,5 @@
+5
+FALSE
+range
+TRUE
+8
diff --git a/tests/i/multifile-operators/notes.md b/tests/i/multifile-operators/notes.md
new file mode 100644
index 0000000..73263d1
--- /dev/null
+++ b/tests/i/multifile-operators/notes.md
@@ -0,0 +1,7 @@
+# multifile-operators
+
+Human review: pending. Expected output was independently traced by AI, not captured from cpsc.
+
+Basis: INCLUDE and operator overloading are project extensions.
+
+Trace: program imports the global INTEGER addition and transitively imports Key and its comparison methods. Value 3 plus 2 gives 5; 3 equals 4 is FALSE. CASE first rejects equality with 1, then matches the inclusive range 1 through 4. Array element value 4 equals high, yielding TRUE. Dereferencing the pointer to item then adding 5 gives 8.
diff --git a/tests/i/multifile-operators/operators.cps b/tests/i/multifile-operators/operators.cps
new file mode 100644
index 0000000..f0c4f05
--- /dev/null
+++ b/tests/i/multifile-operators/operators.cps
@@ -0,0 +1,4 @@
+INCLUDE "types.cps"
+OVERLOAD FUNCTION OPERATOR+(lhs : Key, rhs : INTEGER) RETURNS INTEGER
+RETURN lhs.Value + rhs
+ENDFUNCTION
diff --git a/tests/i/multifile-operators/program.cps b/tests/i/multifile-operators/program.cps
new file mode 100644
index 0000000..85eb3ee
--- /dev/null
+++ b/tests/i/multifile-operators/program.cps
@@ -0,0 +1,21 @@
+INCLUDE "operators.cps"
+DECLARE item : Key
+DECLARE low : Key
+DECLARE high : Key
+item.Value <- 3
+low.Value <- 1
+high.Value <- 4
+OUTPUT item + 2
+OUTPUT item = high
+CASE OF item
+low : OUTPUT "wrong"
+low TO high : OUTPUT "range"
+OTHERWISE : OUTPUT "wrong"
+ENDCASE
+DECLARE items : ARRAY[1:2] OF Key
+items[2].Value <- 4
+OUTPUT items[2] = high
+TYPE KeyPointer = ^Key
+DECLARE pointer : KeyPointer
+pointer <- ^item
+OUTPUT pointer^ + 5
diff --git a/tests/i/multifile-operators/types.cps b/tests/i/multifile-operators/types.cps
new file mode 100644
index 0000000..9198da4
--- /dev/null
+++ b/tests/i/multifile-operators/types.cps
@@ -0,0 +1,12 @@
+CLASS Key
+Value : INTEGER
+OVERLOAD FUNCTION OPERATOR=(rhs : Key) RETURNS BOOLEAN
+RETURN Value = rhs.Value
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR>=(rhs : Key) RETURNS BOOLEAN
+RETURN Value >= rhs.Value
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR<=(rhs : Key) RETURNS BOOLEAN
+RETURN Value <= rhs.Value
+ENDFUNCTION
+ENDCLASS
diff --git a/tests/i/operator-kinds/case.json b/tests/i/operator-kinds/case.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/tests/i/operator-kinds/case.json
@@ -0,0 +1 @@
+{}
diff --git a/tests/i/operator-kinds/expected.txt b/tests/i/operator-kinds/expected.txt
new file mode 100644
index 0000000..3edc836
--- /dev/null
+++ b/tests/i/operator-kinds/expected.txt
@@ -0,0 +1,18 @@
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+114
diff --git a/tests/i/operator-kinds/notes.md b/tests/i/operator-kinds/notes.md
new file mode 100644
index 0000000..f4d829e
--- /dev/null
+++ b/tests/i/operator-kinds/notes.md
@@ -0,0 +1,7 @@
+# operator-kinds
+
+Human review: pending. Expected output was independently traced by AI, not captured from cpsc.
+
+Basis: operator overloading is a project extension.
+
+Trace: each binary operator on Choice explicitly returns its own marker 101 through 115 in source order. Unary minus returns 116 and NOT returns 117. The explicit AND call returns 114. In particular /, &, comparisons and logic must use the declared INTEGER result, overriding builtin type inference and enum comparisons.
diff --git a/tests/i/operator-kinds/program.cps b/tests/i/operator-kinds/program.cps
new file mode 100644
index 0000000..b66fa0e
--- /dev/null
+++ b/tests/i/operator-kinds/program.cps
@@ -0,0 +1,70 @@
+TYPE Choice = (First, Second)
+OVERLOAD FUNCTION OPERATOR +(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 101
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR -(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 102
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR *(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 103
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR /(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 104
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR DIV(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 105
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR MOD(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 106
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR &(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 107
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR =(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 108
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR <>(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 109
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR <(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 110
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR <=(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 111
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR >(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 112
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR >=(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 113
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR AND(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 114
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR OR(lhs : Choice, rhs : Choice) RETURNS INTEGER
+RETURN 115
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR-(value : Choice) RETURNS INTEGER
+RETURN 116
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR NOT(value : Choice) RETURNS INTEGER
+RETURN 117
+ENDFUNCTION
+OUTPUT First + Second
+OUTPUT First - Second
+OUTPUT First * Second
+OUTPUT First / Second
+OUTPUT First DIV Second
+OUTPUT First MOD Second
+OUTPUT First & Second
+OUTPUT First = Second
+OUTPUT First <> Second
+OUTPUT First < Second
+OUTPUT First <= Second
+OUTPUT First > Second
+OUTPUT First >= Second
+OUTPUT First AND Second
+OUTPUT First OR Second
+OUTPUT -First
+OUTPUT NOT Second
+OUTPUT OPERATOR AND(First, Second)
diff --git a/tests/iii/operator-result-errors/case.json b/tests/iii/operator-result-errors/case.json
new file mode 100644
index 0000000..67abec2
--- /dev/null
+++ b/tests/iii/operator-result-errors/case.json
@@ -0,0 +1,20 @@
+{
+ "errors": [
+ {
+ "reason": "Cannot implicitly convert STRING to BOOLEAN",
+ "line": 8
+ },
+ {
+ "reason": "Cannot implicitly convert STRING to BOOLEAN",
+ "line": 12
+ },
+ {
+ "reason": "Cannot implicitly convert STRING to BOOLEAN",
+ "line": 17
+ },
+ {
+ "reason": "CASE comparison must return BOOLEAN",
+ "line": 19
+ }
+ ]
+}
diff --git a/tests/iii/operator-result-errors/notes.md b/tests/iii/operator-result-errors/notes.md
new file mode 100644
index 0000000..bb407a2
--- /dev/null
+++ b/tests/iii/operator-result-errors/notes.md
@@ -0,0 +1,3 @@
+# operator-result-errors
+
+The equality operator returns STRING. Reject that result as an IF condition, BOOLEAN return value, BOOLEAN argument and CASE comparison.
diff --git a/tests/iii/operator-result-errors/program.cps b/tests/iii/operator-result-errors/program.cps
new file mode 100644
index 0000000..8cf9ede
--- /dev/null
+++ b/tests/iii/operator-result-errors/program.cps
@@ -0,0 +1,20 @@
+CLASS Box
+Value : INTEGER
+OVERLOAD FUNCTION OPERATOR=(rhs : Box) RETURNS STRING
+RETURN "text"
+ENDFUNCTION
+ENDCLASS
+DECLARE item : Box
+IF item = item THEN
+OUTPUT "wrong"
+ENDIF
+FUNCTION Bad(value : Box) RETURNS BOOLEAN
+RETURN value = value
+ENDFUNCTION
+FUNCTION NeedBool(flag : BOOLEAN) RETURNS INTEGER
+RETURN 0
+ENDFUNCTION
+OUTPUT NeedBool(item = item)
+CASE OF item
+item : OUTPUT "wrong"
+ENDCASE