summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-02-21 15:05:11 -0800
committerAraq <rumpf_a@web.de>2013-02-21 15:05:11 -0800
commitdad664ca714ee681d22fb93344388fde2c9ff472 (patch)
treea08304713bf4703895f3dfe22a89fd08f16521ec
parent45c9975e9c9fe063d68aa5eb6df0457ca9ac7457 (diff)
parent7168ceb5e1ec6686b13f5da1f2c9a4db07ac90ec (diff)
downloadNim-dad664ca714ee681d22fb93344388fde2c9ff472.tar.gz
Merge pull request #341 from Tass/master
Basic logic for objects
-rwxr-xr-xlib/system.nim4
-rw-r--r--tests/run/tobject.nim15
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/system.nim b/lib/system.nim
index 5f9a24ba9..db78d2740 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1532,7 +1532,7 @@ iterator fieldPairs*[S: tuple|object, T: tuple|object](x: S, y: T): tuple[
   ## The current implementation also has a bug that affects symbol binding
   ## in the loop body.
 
-proc `==`*[T: tuple](x, y: T): bool = 
+proc `==`*[T: tuple|object](x, y: T): bool = 
   ## generic ``==`` operator for tuples that is lifted from the components
   ## of `x` and `y`.
   for a, b in fields(x, y):
@@ -1557,7 +1557,7 @@ proc `<`*[T: tuple](x, y: T): bool =
     if c > 0: return false
   return false
 
-proc `$`*[T: tuple](x: T): string = 
+proc `$`*[T: tuple|object](x: T): string = 
   ## generic ``$`` operator for tuples that is lifted from the components
   ## of `x`. Example:
   ##
diff --git a/tests/run/tobject.nim b/tests/run/tobject.nim
new file mode 100644
index 000000000..5fec84441
--- /dev/null
+++ b/tests/run/tobject.nim
@@ -0,0 +1,15 @@
+import unittest
+
+type Obj = object
+  foo: int
+
+proc makeObj(x: int): Obj = 
+  result.foo = x
+
+suite "object basic methods":
+  test "it should convert an object to a string":
+    var obj = makeObj(1)
+    # Should be "obj: (foo: 1)" or similar.
+    check($obj == "(foo: 1)")
+  test "it should test equality based on fields":
+    check(makeObj(1) == makeObj(1))