Merge pull request #341 from Tass/master

Basic logic for objects
This commit is contained in:
Araq
2013-02-21 15:05:11 -08:00
2 changed files with 17 additions and 2 deletions

View File

@@ -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:
##

15
tests/run/tobject.nim Normal file
View File

@@ -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))