aboutsummaryrefslogtreecommitdiff
path: root/tests/i/multifile-operators
diff options
context:
space:
mode:
Diffstat (limited to 'tests/i/multifile-operators')
-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
6 files changed, 56 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