diff options
author | Simon Hafner <hafnersimon@gmail.com> | 2013-02-21 15:11:48 -0600 |
---|---|---|
committer | Simon Hafner <hafnersimon@gmail.com> | 2013-02-21 15:11:48 -0600 |
commit | bf82f79f1e27b4580672af457a95f3d85ea781a4 (patch) | |
tree | c436d3d577fea84621b9afd9aa40a6d370c37605 | |
parent | 7fc9dfcb2400aa0a97cad85ee0d16713e30fec8b (diff) | |
download | Nim-bf82f79f1e27b4580672af457a95f3d85ea781a4.tar.gz |
added tests, actually implemented $ and ==
-rwxr-xr-x | lib/system.nim | 4 | ||||
-rw-r--r-- | tests/run/tobject.nim | 3 |
2 files changed, 4 insertions, 3 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 index b6a2461ac..246f2862b 100644 --- a/tests/run/tobject.nim +++ b/tests/run/tobject.nim @@ -13,7 +13,8 @@ proc initObject(x: int): Obj = suite "object basic methods": test "it should convert an objcet to a string": var obj = makeObj(1) - discard $obj + # 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": |