aboutsummaryrefslogtreecommitdiff
path: root/tests/i
diff options
context:
space:
mode:
Diffstat (limited to 'tests/i')
-rw-r--r--tests/i/implicit-constructors/case.json1
-rw-r--r--tests/i/implicit-constructors/expected.txt5
-rw-r--r--tests/i/implicit-constructors/notes.md3
-rw-r--r--tests/i/implicit-constructors/program.cps63
4 files changed, 72 insertions, 0 deletions
diff --git a/tests/i/implicit-constructors/case.json b/tests/i/implicit-constructors/case.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/tests/i/implicit-constructors/case.json
@@ -0,0 +1 @@
+{}
diff --git a/tests/i/implicit-constructors/expected.txt b/tests/i/implicit-constructors/expected.txt
new file mode 100644
index 0000000..d360ce8
--- /dev/null
+++ b/tests/i/implicit-constructors/expected.txt
@@ -0,0 +1,5 @@
+7:8:201:6:9
+9
+TRUE
+0
+0
diff --git a/tests/i/implicit-constructors/notes.md b/tests/i/implicit-constructors/notes.md
new file mode 100644
index 0000000..cdcab87
--- /dev/null
+++ b/tests/i/implicit-constructors/notes.md
@@ -0,0 +1,3 @@
+# Implicit constructors
+
+Pending human review. Box counts constructions, copies and destruction. Assignments, BYVAL arguments, RETURN, operators and CASE use its INTEGER conversion. Pick selects its exact INTEGER overload. Exercise releases all objects; a later failing argument releases the pending converted Box before CATCH.
diff --git a/tests/i/implicit-constructors/program.cps b/tests/i/implicit-constructors/program.cps
new file mode 100644
index 0000000..d13236e
--- /dev/null
+++ b/tests/i/implicit-constructors/program.cps
@@ -0,0 +1,63 @@
+GLOBAL
+ DECLARE Alive : INTEGER
+ENDGLOBAL
+CLASS Box
+ Value : INTEGER
+ OVERLOAD PROCEDURE NEW()
+ Alive <- Alive + 1
+ ENDPROCEDURE
+ OVERLOAD IMPLICIT PROCEDURE NEW(Number : INTEGER)
+ Value <- Number
+ Alive <- Alive + 1
+ ENDPROCEDURE
+ OVERLOAD PROCEDURE NEW(BYREF Other : Box)
+ Value <- Other.Value
+ Alive <- Alive + 1
+ ENDPROCEDURE
+ PROCEDURE DELETE()
+ Alive <- Alive - 1
+ ENDPROCEDURE
+ENDCLASS
+FUNCTION Read(Value : Box) RETURNS INTEGER
+ RETURN Value.Value
+ENDFUNCTION
+OVERLOAD FUNCTION Pick(Value : Box) RETURNS INTEGER
+ RETURN 100 + Value.Value
+ENDFUNCTION
+OVERLOAD FUNCTION Pick(Value : INTEGER) RETURNS INTEGER
+ RETURN 200 + Value
+ENDFUNCTION
+OVERLOAD FUNCTION Only(Value : Box) RETURNS INTEGER
+ RETURN Value.Value
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR+(A : Box, B : Box) RETURNS INTEGER
+ RETURN A.Value + B.Value
+ENDFUNCTION
+OVERLOAD FUNCTION OPERATOR=(A : Box, B : Box) RETURNS BOOLEAN
+ RETURN A.Value = B.Value
+ENDFUNCTION
+FUNCTION Make() RETURNS Box
+ RETURN 9
+ENDFUNCTION
+PROCEDURE Exercise()
+ DECLARE B : Box
+ B <- 7
+ OUTPUT B.Value, ":", Read(8), ":", Pick(1), ":", Only(6), ":", B + 2
+ OUTPUT Read(Make())
+ CASE OF B
+ 7 : OUTPUT TRUE
+ OTHERWISE : OUTPUT FALSE
+ ENDCASE
+ENDPROCEDURE
+FUNCTION Fail() RETURNS INTEGER
+ THROW
+ENDFUNCTION
+PROCEDURE Pair(Value : Box, Number : INTEGER)
+ENDPROCEDURE
+CALL Exercise()
+OUTPUT Alive
+TRY
+ CALL Pair(1, Fail())
+CATCH
+ OUTPUT Alive
+ENDTRY