diff options
author | Simon Hafner <hafnersimon@gmail.com> | 2013-02-21 16:31:35 -0600 |
---|---|---|
committer | Simon Hafner <hafnersimon@gmail.com> | 2013-02-21 16:31:35 -0600 |
commit | e366eeaafc0b834cd57d0aa4bc16925271c4a79f (patch) | |
tree | 901ca0d33bb9a08d0a4f0b920a054a2761622693 | |
parent | bf82f79f1e27b4580672af457a95f3d85ea781a4 (diff) | |
download | Nim-e366eeaafc0b834cd57d0aa4bc16925271c4a79f.tar.gz |
added $ for refs and removed == for ref test
== in refs should use the pointer to compare
-rwxr-xr-x | lib/system.nim | 2 | ||||
-rw-r--r-- | tests/run/tobject.nim | 20 |
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/system.nim b/lib/system.nim index db78d2740..3f15dbeaf 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -1557,6 +1557,8 @@ proc `<`*[T: tuple](x, y: T): bool = if c > 0: return false return false +proc `$`*[T: ref](x: T): string = $x[] + 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 index 246f2862b..b2fd21236 100644 --- a/tests/run/tobject.nim +++ b/tests/run/tobject.nim @@ -7,15 +7,19 @@ proc makeObj(x: int): ref Obj = new(result) result.foo = x -proc initObject(x: int): Obj = +proc initObj(x: int): Obj = result.foo = x -suite "object basic methods": - test "it should convert an objcet to a string": - var obj = makeObj(1) +template stringTest(init: expr) = + test "it should convert an object to a string": + var obj = `init`(1) # Should be "obj: (foo: 1)" or similar. check($obj == "(foo: 1)") - test "it should test equality based on fields": - check(initObj(1) == initObj(1)) - test "it should test equality based on fields for refs too": - check(makeObj(1) == makeObj(1)) + +suite "object basic methods": + suite "ref": + stringTest(makeObj) + suite "value": + stringTest(initObj) + test "it should test equality based on fields": + check(initObj(1) == initObj(1)) |