aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-17 10:32:30 +0000
committer_ov4 <ov4@ov4.org>2026-10-17 10:32:30 +0000
commit377a1fd2eadd2a70cd27f13e2fee6e96c8706a51 (patch)
treec05665f26b3434359cf4ae7720e8f9111a322522 /tests
parentf5246db6d045ffb86d6717e1b1c37f03bcb2b75b (diff)
feat(codegen): overload global functions and procedures
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/i/multifile-overloads/case.json7
-rw-r--r--tests/i/multifile-overloads/expected.txt2
-rw-r--r--tests/i/multifile-overloads/integer.cps3
-rw-r--r--tests/i/multifile-overloads/notes.md7
-rw-r--r--tests/i/multifile-overloads/program.cps4
-rw-r--r--tests/i/multifile-overloads/real.cps3
-rw-r--r--tests/i/overload-functions/case.json1
-rw-r--r--tests/i/overload-functions/expected.txt10
-rw-r--r--tests/i/overload-functions/notes.md9
-rw-r--r--tests/i/overload-functions/program.cps49
-rw-r--r--tests/iii/multifile-overload-duplicate/case.json14
-rw-r--r--tests/iii/multifile-overload-duplicate/first.cps2
-rw-r--r--tests/iii/multifile-overload-duplicate/program.cps1
-rw-r--r--tests/iii/multifile-overload-duplicate/second.cps2
-rw-r--r--tests/iii/multifile-overload-visibility/case.json14
-rw-r--r--tests/iii/multifile-overload-visibility/integer.cps3
-rw-r--r--tests/iii/multifile-overload-visibility/program.cps2
-rw-r--r--tests/iii/multifile-overload-visibility/real.cps3
-rw-r--r--tests/iii/overload-errors/case.json36
-rw-r--r--tests/iii/overload-errors/program.cps29
-rw-r--r--tests/iii/overload-main/case.json8
-rw-r--r--tests/iii/overload-main/program.cps3
22 files changed, 212 insertions, 0 deletions
diff --git a/tests/i/multifile-overloads/case.json b/tests/i/multifile-overloads/case.json
new file mode 100644
index 0000000..dcbd7a4
--- /dev/null
+++ b/tests/i/multifile-overloads/case.json
@@ -0,0 +1,7 @@
+{
+ "sources": [
+ "program.cps",
+ "integer.cps",
+ "real.cps"
+ ]
+}
diff --git a/tests/i/multifile-overloads/expected.txt b/tests/i/multifile-overloads/expected.txt
new file mode 100644
index 0000000..6cf72e1
--- /dev/null
+++ b/tests/i/multifile-overloads/expected.txt
@@ -0,0 +1,2 @@
+6
+TRUE
diff --git a/tests/i/multifile-overloads/integer.cps b/tests/i/multifile-overloads/integer.cps
new file mode 100644
index 0000000..d2fd6d4
--- /dev/null
+++ b/tests/i/multifile-overloads/integer.cps
@@ -0,0 +1,3 @@
+OVERLOAD FUNCTION Area(x : INTEGER) RETURNS INTEGER
+RETURN x * 2
+ENDFUNCTION
diff --git a/tests/i/multifile-overloads/notes.md b/tests/i/multifile-overloads/notes.md
new file mode 100644
index 0000000..9a13837
--- /dev/null
+++ b/tests/i/multifile-overloads/notes.md
@@ -0,0 +1,7 @@
+# multifile-overloads
+
+Human review: pending. Expected output was independently traced by AI, not captured from cpsc.
+
+Basis: OVERLOAD is a project extension.
+
+Trace: Both libraries are visible: INTEGER 3 doubles to 6; REAL 2.0 compares greater than 1.0 and returns TRUE.
diff --git a/tests/i/multifile-overloads/program.cps b/tests/i/multifile-overloads/program.cps
new file mode 100644
index 0000000..35a9555
--- /dev/null
+++ b/tests/i/multifile-overloads/program.cps
@@ -0,0 +1,4 @@
+INCLUDE "integer.cps"
+INCLUDE "real.cps"
+OUTPUT Area(3)
+OUTPUT Area(2.0)
diff --git a/tests/i/multifile-overloads/real.cps b/tests/i/multifile-overloads/real.cps
new file mode 100644
index 0000000..3b5116a
--- /dev/null
+++ b/tests/i/multifile-overloads/real.cps
@@ -0,0 +1,3 @@
+OVERLOAD FUNCTION Area(x : REAL) RETURNS BOOLEAN
+RETURN x > 1.0
+ENDFUNCTION
diff --git a/tests/i/overload-functions/case.json b/tests/i/overload-functions/case.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/tests/i/overload-functions/case.json
@@ -0,0 +1 @@
+{}
diff --git a/tests/i/overload-functions/expected.txt b/tests/i/overload-functions/expected.txt
new file mode 100644
index 0000000..65c760e
--- /dev/null
+++ b/tests/i/overload-functions/expected.txt
@@ -0,0 +1,10 @@
+3
+TRUE
+pair
+text
+7
+9
+TRUE
+3
+5
+TRUE
diff --git a/tests/i/overload-functions/notes.md b/tests/i/overload-functions/notes.md
new file mode 100644
index 0000000..dcfdde3
--- /dev/null
+++ b/tests/i/overload-functions/notes.md
@@ -0,0 +1,9 @@
+# overload-functions
+
+Human review: pending. Expected output was independently traced by AI, not captured from cpsc.
+
+Basis: OVERLOAD is a project extension.
+
+Trace: INTEGER adds one; positive REAL returns TRUE; two INTEGERs return pair; STRING prints text. Rank-one INTEGER, rank-two INTEGER and REAL arrays select distinct overloads and yield 7, 9 and TRUE. Nested Pick(1) returns INTEGER 2, so the outer call yields 3.
+
+Bump selects INTEGER and mutates 4 to 5 through BYREF. The ordinary Legacy function still converts INTEGER 1 to REAL and returns TRUE.
diff --git a/tests/i/overload-functions/program.cps b/tests/i/overload-functions/program.cps
new file mode 100644
index 0000000..e76637d
--- /dev/null
+++ b/tests/i/overload-functions/program.cps
@@ -0,0 +1,49 @@
+OVERLOAD FUNCTION Pick(x : INTEGER) RETURNS INTEGER
+RETURN x + 1
+ENDFUNCTION
+OVERLOAD FUNCTION Pick(x : REAL) RETURNS BOOLEAN
+RETURN x > 0
+ENDFUNCTION
+OVERLOAD FUNCTION Pick(x : INTEGER, y : INTEGER) RETURNS STRING
+RETURN "pair"
+ENDFUNCTION
+OVERLOAD PROCEDURE Pick(x : STRING)
+OUTPUT x
+ENDPROCEDURE
+OVERLOAD FUNCTION Pick(a : ARRAY OF INTEGER) RETURNS INTEGER
+RETURN a[1]
+ENDFUNCTION
+OVERLOAD FUNCTION Pick(a : ARRAY[1:2,1:2] OF INTEGER) RETURNS INTEGER
+RETURN a[2,2]
+ENDFUNCTION
+OVERLOAD FUNCTION Pick(a : ARRAY OF REAL) RETURNS BOOLEAN
+RETURN a[1] > 0
+ENDFUNCTION
+DECLARE a : ARRAY[1:2] OF INTEGER
+DECLARE b : ARRAY[1:2,1:2] OF INTEGER
+DECLARE c : ARRAY[1:2] OF REAL
+a[1] <- 7
+b[2,2] <- 9
+c[1] <- 1.0
+OUTPUT pIcK(2)
+OUTPUT Pick(2.0)
+OUTPUT Pick(1, 2)
+CALL Pick("text")
+OUTPUT Pick(a)
+OUTPUT Pick(b)
+OUTPUT Pick(c)
+OUTPUT Pick(Pick(1))
+OVERLOAD PROCEDURE Bump(BYREF x : INTEGER)
+x <- x + 1
+ENDPROCEDURE
+OVERLOAD PROCEDURE Bump(BYREF x : REAL)
+x <- x + 2.0
+ENDPROCEDURE
+FUNCTION Legacy(x : REAL) RETURNS BOOLEAN
+RETURN x > 0
+ENDFUNCTION
+DECLARE n : INTEGER
+n <- 4
+CALL Bump(n)
+OUTPUT n
+OUTPUT Legacy(1)
diff --git a/tests/iii/multifile-overload-duplicate/case.json b/tests/iii/multifile-overload-duplicate/case.json
new file mode 100644
index 0000000..bb02048
--- /dev/null
+++ b/tests/iii/multifile-overload-duplicate/case.json
@@ -0,0 +1,14 @@
+{
+ "errors": [
+ {
+ "reason": "(?i)Duplicate definition Same in",
+ "line": 1,
+ "file": "second.cps"
+ }
+ ],
+ "sources": [
+ "program.cps",
+ "first.cps",
+ "second.cps"
+ ]
+}
diff --git a/tests/iii/multifile-overload-duplicate/first.cps b/tests/iii/multifile-overload-duplicate/first.cps
new file mode 100644
index 0000000..4ec6b09
--- /dev/null
+++ b/tests/iii/multifile-overload-duplicate/first.cps
@@ -0,0 +1,2 @@
+OVERLOAD PROCEDURE Same(a : ARRAY[1:2] OF INTEGER)
+ENDPROCEDURE
diff --git a/tests/iii/multifile-overload-duplicate/program.cps b/tests/iii/multifile-overload-duplicate/program.cps
new file mode 100644
index 0000000..e5d0515
--- /dev/null
+++ b/tests/iii/multifile-overload-duplicate/program.cps
@@ -0,0 +1 @@
+OUTPUT 0
diff --git a/tests/iii/multifile-overload-duplicate/second.cps b/tests/iii/multifile-overload-duplicate/second.cps
new file mode 100644
index 0000000..f26810a
--- /dev/null
+++ b/tests/iii/multifile-overload-duplicate/second.cps
@@ -0,0 +1,2 @@
+OVERLOAD PROCEDURE same(BYREF a : ARRAY[3:4] OF INTEGER)
+ENDPROCEDURE
diff --git a/tests/iii/multifile-overload-visibility/case.json b/tests/iii/multifile-overload-visibility/case.json
new file mode 100644
index 0000000..6c60472
--- /dev/null
+++ b/tests/iii/multifile-overload-visibility/case.json
@@ -0,0 +1,14 @@
+{
+ "errors": [
+ {
+ "reason": "No matching overload for Area\\(REAL\\)",
+ "line": 2,
+ "file": "program.cps"
+ }
+ ],
+ "sources": [
+ "program.cps",
+ "integer.cps",
+ "real.cps"
+ ]
+}
diff --git a/tests/iii/multifile-overload-visibility/integer.cps b/tests/iii/multifile-overload-visibility/integer.cps
new file mode 100644
index 0000000..b87740a
--- /dev/null
+++ b/tests/iii/multifile-overload-visibility/integer.cps
@@ -0,0 +1,3 @@
+OVERLOAD FUNCTION Area(x : INTEGER) RETURNS INTEGER
+RETURN x
+ENDFUNCTION
diff --git a/tests/iii/multifile-overload-visibility/program.cps b/tests/iii/multifile-overload-visibility/program.cps
new file mode 100644
index 0000000..8f47c4a
--- /dev/null
+++ b/tests/iii/multifile-overload-visibility/program.cps
@@ -0,0 +1,2 @@
+INCLUDE "integer.cps"
+OUTPUT Area(2.0)
diff --git a/tests/iii/multifile-overload-visibility/real.cps b/tests/iii/multifile-overload-visibility/real.cps
new file mode 100644
index 0000000..a16261a
--- /dev/null
+++ b/tests/iii/multifile-overload-visibility/real.cps
@@ -0,0 +1,3 @@
+OVERLOAD FUNCTION Area(x : REAL) RETURNS REAL
+RETURN x
+ENDFUNCTION
diff --git a/tests/iii/overload-errors/case.json b/tests/iii/overload-errors/case.json
new file mode 100644
index 0000000..b31c666
--- /dev/null
+++ b/tests/iii/overload-errors/case.json
@@ -0,0 +1,36 @@
+{
+ "errors": [
+ {
+ "reason": "every overload must be declared OVERLOAD",
+ "line": 4
+ },
+ {
+ "reason": "Function Ret cannot be redefined",
+ "line": 10
+ },
+ {
+ "reason": "Function Mode cannot be redefined",
+ "line": 15
+ },
+ {
+ "reason": "No matching overload for Exact\\(INTEGER\\)",
+ "line": 20
+ },
+ {
+ "reason": "Function Bounds cannot be redefined",
+ "line": 23
+ },
+ {
+ "reason": "built-in function and cannot be redefined",
+ "line": 25
+ },
+ {
+ "reason": "No matching overload for Exact\\(STRING\\)",
+ "line": 28
+ },
+ {
+ "reason": "No matching overload for Exact\\(\\)",
+ "line": 29
+ }
+ ]
+}
diff --git a/tests/iii/overload-errors/program.cps b/tests/iii/overload-errors/program.cps
new file mode 100644
index 0000000..13d4692
--- /dev/null
+++ b/tests/iii/overload-errors/program.cps
@@ -0,0 +1,29 @@
+OVERLOAD FUNCTION Mixed(x : INTEGER) RETURNS INTEGER
+RETURN x
+ENDFUNCTION
+FUNCTION Mixed(x : REAL) RETURNS REAL
+RETURN x
+ENDFUNCTION
+OVERLOAD FUNCTION Ret(x : INTEGER) RETURNS INTEGER
+RETURN x
+ENDFUNCTION
+OVERLOAD FUNCTION Ret(x : INTEGER) RETURNS REAL
+RETURN x
+ENDFUNCTION
+OVERLOAD PROCEDURE Mode(BYREF x : INTEGER)
+ENDPROCEDURE
+OVERLOAD PROCEDURE Mode(BYVAL x : INTEGER)
+ENDPROCEDURE
+OVERLOAD FUNCTION Exact(x : REAL) RETURNS REAL
+RETURN x
+ENDFUNCTION
+OUTPUT Exact(1)
+OVERLOAD PROCEDURE Bounds(a : ARRAY[1:2] OF INTEGER)
+ENDPROCEDURE
+OVERLOAD PROCEDURE Bounds(a : ARRAY[3:4] OF INTEGER)
+ENDPROCEDURE
+OVERLOAD FUNCTION LENGTH(x : INTEGER) RETURNS INTEGER
+RETURN x
+ENDFUNCTION
+OUTPUT Exact("text")
+OUTPUT Exact()
diff --git a/tests/iii/overload-main/case.json b/tests/iii/overload-main/case.json
new file mode 100644
index 0000000..c2ffe3f
--- /dev/null
+++ b/tests/iii/overload-main/case.json
@@ -0,0 +1,8 @@
+{
+ "errors": [
+ {
+ "reason": "MAIN cannot be declared OVERLOAD",
+ "line": 1
+ }
+ ]
+}
diff --git a/tests/iii/overload-main/program.cps b/tests/iii/overload-main/program.cps
new file mode 100644
index 0000000..709c905
--- /dev/null
+++ b/tests/iii/overload-main/program.cps
@@ -0,0 +1,3 @@
+OVERLOAD FUNCTION MAIN() RETURNS INTEGER
+RETURN 0
+ENDFUNCTION