about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-01-26 15:52:28 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-01-26 15:52:28 +0100
commit6bead0e4ccfa65a89bee8db6d4587e297fba1a57 (patch)
treec50c451789f8c0227ff0f5a38b3b39d078d0f7e8 /src/test
parent3aed4b04cee15408536e9d89b866dc16447d1afb (diff)
Use operator names for operator methods
The methods used to implement operators now simply use
the name of the operator itself, except for unary -, which is called
min to not clash with binary -. Index is called [].

Closes #1520
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/operator-overloading.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/test/run-pass/operator-overloading.rs b/src/test/run-pass/operator-overloading.rs
index 55761548f14..412e1fd538c 100644
--- a/src/test/run-pass/operator-overloading.rs
+++ b/src/test/run-pass/operator-overloading.rs
@@ -1,20 +1,24 @@
 type point = {x: int, y: int};
 
-impl add_point for point {
-    fn op_add(other: point) -> point {
+impl point_ops for point {
+    fn +(other: point) -> point {
         {x: self.x + other.x, y: self.y + other.y}
     }
-    fn op_neg() -> point {
+    fn -(other: point) -> point {
+        {x: self.x - other.x, y: self.y - other.y}
+    }
+    fn neg() -> point {
         {x: -self.x, y: -self.y}
     }
-    fn op_index(x: bool) -> int {
+    fn [](x: bool) -> int {
         x ? self.x : self.y
     }
 }
 
 fn main() {
     let p = {x: 10, y: 20};
-    p += {x: 1, y: 2};
+    p += {x: 101, y: 102};
+    p -= {x: 100, y: 100};
     assert p + {x: 5, y: 5} == {x: 16, y: 27};
     assert -p == {x: -11, y: -22};
     assert p[true] == 11;