diff options
author | Miran <narimiran@users.noreply.github.com> | 2018-10-16 10:50:10 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-10-16 10:50:10 +0200 |
commit | 749dbce4c69224f5464908d8f714291f17aa60fa (patch) | |
tree | cc91326ef536f15d8d9aa97efab4fc8473d093c7 /tests/objects/tvarious.nim | |
parent | f04c93b5dd1ee5e185f6849ad8116d08a687026d (diff) | |
download | Nim-749dbce4c69224f5464908d8f714291f17aa60fa.tar.gz |
Merge tests into a larger file (part 5 of ∞) (#9368)
* merge magics * merge metatype tests * merge method tests * merge objects tests * change `import future` to `import sugar` Nim in Action tests are left with `import future`, to ensure compatibility. * merge overload tests * merge proc tests * merge procvar tests * merge range tests * merge seq tests * merge sets tests * remove wrong assert from `tsets3` * fix `jsTests` * better fix
Diffstat (limited to 'tests/objects/tvarious.nim')
-rw-r--r-- | tests/objects/tvarious.nim | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/objects/tvarious.nim b/tests/objects/tvarious.nim new file mode 100644 index 000000000..504681b99 --- /dev/null +++ b/tests/objects/tvarious.nim @@ -0,0 +1,87 @@ +discard """ + output: ''' +34 +b +wohoo +baz +''' +""" + + +block tobject2: + # Tests the object implementation + type + TPoint2d {.inheritable.} = object + x, y: int + TPoint3d = object of TPoint2d + z: int # added a field + + proc getPoint( p: var TPoint2d) = + {.breakpoint.} + writeLine(stdout, p.x) + + var p: TPoint3d + + TPoint2d(p).x = 34 + p.y = 98 + p.z = 343 + + getPoint(p) + + + +block tofopr: + type + TMyType = object {.inheritable.} + len: int + data: string + + TOtherType = object of TMyType + + proc p(x: TMyType): bool = + return x of TOtherType + + var + m: TMyType + n: TOtherType + + doAssert p(m) == false + doAssert p(n) + + + +block toop: + type + TA = object of RootObj + x, y: int + TB = object of TA + z: int + TC = object of TB + whatever: string + + proc p(a: var TA) = echo "a" + proc p(b: var TB) = echo "b" + + var c: TC + p(c) + + + +block tfefobjsyntax: + type + Foo = object + a, b: int + s: string + FooBar = object of RootObj + n, m: string + Baz = object of FooBar + + proc invoke(a: ref Baz) = + echo "baz" + + # check object construction: + let x = (ref Foo)(a: 0, b: 45, s: "wohoo") + echo x.s + + var y: ref FooBar = (ref Baz)(n: "n", m: "m") + invoke((ref Baz)(y)) |