diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/i/operator-members/case.json | 1 | ||||
| -rw-r--r-- | tests/i/operator-members/expected.txt | 12 | ||||
| -rw-r--r-- | tests/i/operator-members/notes.md | 7 | ||||
| -rw-r--r-- | tests/i/operator-members/program.cps | 66 | ||||
| -rw-r--r-- | tests/iii/operator-member-errors/case.json | 20 | ||||
| -rw-r--r-- | tests/iii/operator-member-errors/notes.md | 3 | ||||
| -rw-r--r-- | tests/iii/operator-member-errors/program.cps | 18 |
7 files changed, 127 insertions, 0 deletions
diff --git a/tests/i/operator-members/case.json b/tests/i/operator-members/case.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/i/operator-members/case.json @@ -0,0 +1 @@ +{} diff --git a/tests/i/operator-members/expected.txt b/tests/i/operator-members/expected.txt new file mode 100644 index 0000000..24ab52b --- /dev/null +++ b/tests/i/operator-members/expected.txt @@ -0,0 +1,12 @@ +9 +-3 +negated +3! +8 +8 +8 +6 +make +number +6 +caught diff --git a/tests/i/operator-members/notes.md b/tests/i/operator-members/notes.md new file mode 100644 index 0000000..2b741c9 --- /dev/null +++ b/tests/i/operator-members/notes.md @@ -0,0 +1,7 @@ +# operator-members + +Human review: pending. Expected output was independently traced by AI, not captured from cpsc. + +Basis: operator overloading is a project extension; arguments match exact types. + +Trace: chained additions produce 3 + 2 + 4 = 9. Unary minus returns -3; NOT deliberately returns negated. A method can use its private concatenation operator, yielding 3!. Box addition modifies the original receiver from 3 to 8. Explicit member addition then global subtraction yields 8; explicit global subtraction yields 6. Discarded unary/global calls produce no output. MakeBox prints make exactly once, then Number prints number exactly once; their result has value 4 + 2 = 6. A throwing global multiplication reaches CATCH. diff --git a/tests/i/operator-members/program.cps b/tests/i/operator-members/program.cps new file mode 100644 index 0000000..d17184c --- /dev/null +++ b/tests/i/operator-members/program.cps @@ -0,0 +1,66 @@ +CLASS Box +Value : INTEGER +OVERLOAD FUNCTION OPERATOR+(rhs : INTEGER) RETURNS Box +DECLARE result : Box +result.Value <- Value + rhs +RETURN result +ENDFUNCTION +OVERLOAD FUNCTION OPERATOR+(rhs : Box) RETURNS INTEGER +Value <- Value + rhs.Value +RETURN Value +ENDFUNCTION +OVERLOAD FUNCTION OPERATOR-() RETURNS INTEGER +RETURN -Value +ENDFUNCTION +OVERLOAD FUNCTION OPERATOR NOT() RETURNS STRING +RETURN "negated" +ENDFUNCTION +PRIVATE OVERLOAD FUNCTION OPERATOR&(rhs : STRING) RETURNS STRING +RETURN NUM_TO_STR(Value) & rhs +ENDFUNCTION +FUNCTION Describe() RETURNS STRING +RETURN this & "!" +ENDFUNCTION +ENDCLASS +OVERLOAD FUNCTION OPERATOR-(lhs : Box, rhs : INTEGER) RETURNS INTEGER +RETURN lhs.Value - rhs +ENDFUNCTION +OVERLOAD FUNCTION OPERATOR*(lhs : Box, rhs : Box) RETURNS INTEGER +THROW +RETURN 0 +ENDFUNCTION +FUNCTION MakeBox() RETURNS Box +OUTPUT "make" +DECLARE result : Box +result.Value <- 4 +RETURN result +ENDFUNCTION +FUNCTION Number() RETURNS INTEGER +OUTPUT "number" +RETURN 2 +ENDFUNCTION +DECLARE a : Box +DECLARE b : Box +DECLARE result : Box +a.Value <- 3 +b.Value <- 5 +result <- (a + 2) + 4 +OUTPUT result.Value +OUTPUT -a +OUTPUT NOT a +OUTPUT a.Describe() +OUTPUT a + b +OUTPUT a.Value +OUTPUT a.OPERATOR+(1) - 1 +OUTPUT OPERATOR-(a, 2) +CALL a.OPERATOR-( ) +a.OPERATOR-( ) +CALL OPERATOR-(a, 1) +OPERATOR-(a, 1) +result <- MakeBox() + Number() +OUTPUT result.Value +TRY +OUTPUT a * b +CATCH +OUTPUT "caught" +ENDTRY diff --git a/tests/iii/operator-member-errors/case.json b/tests/iii/operator-member-errors/case.json new file mode 100644 index 0000000..1e8f8ae --- /dev/null +++ b/tests/iii/operator-member-errors/case.json @@ -0,0 +1,20 @@ +{ + "errors": [ + { + "reason": "Ambiguous overload", + "line": 14 + }, + { + "reason": "Cannot access private method", + "line": 15 + }, + { + "reason": "Cannot access private method", + "line": 16 + }, + { + "reason": "whole array cannot be used as an operand", + "line": 18 + } + ] +} diff --git a/tests/iii/operator-member-errors/notes.md b/tests/iii/operator-member-errors/notes.md new file mode 100644 index 0000000..204ab43 --- /dev/null +++ b/tests/iii/operator-member-errors/notes.md @@ -0,0 +1,3 @@ +# operator-member-errors + +Reject equally matching member/global candidates, implicit and explicit private access, and unary operations on whole arrays. diff --git a/tests/iii/operator-member-errors/program.cps b/tests/iii/operator-member-errors/program.cps new file mode 100644 index 0000000..9b48135 --- /dev/null +++ b/tests/iii/operator-member-errors/program.cps @@ -0,0 +1,18 @@ +CLASS Box +Value : INTEGER +OVERLOAD FUNCTION OPERATOR+(rhs : Box) RETURNS INTEGER +RETURN 1 +ENDFUNCTION +PRIVATE OVERLOAD FUNCTION OPERATOR&(rhs : STRING) RETURNS STRING +RETURN rhs +ENDFUNCTION +ENDCLASS +OVERLOAD FUNCTION OPERATOR+(lhs : Box, rhs : Box) RETURNS INTEGER +RETURN 2 +ENDFUNCTION +DECLARE a : Box +OUTPUT a + a +OUTPUT a & "x" +OUTPUT a.OPERATOR&("x") +DECLARE items : ARRAY[1:2] OF Box +OUTPUT NOT items |
