diff options
author | Araq <rumpf_a@web.de> | 2015-02-10 16:19:32 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-02-10 20:19:48 +0100 |
commit | c2da0e9b3db54597fc35b65a23d67aa3c5714e82 (patch) | |
tree | 767eb5491d11cc3b149531bc4c5e522e61e138b5 /tests | |
parent | eec18896b760059af62a7cb63a151339f44c5f66 (diff) | |
download | Nim-c2da0e9b3db54597fc35b65a23d67aa3c5714e82.tar.gz |
cleanup index generation
Diffstat (limited to 'tests')
-rw-r--r-- | tests/objects/trefobjsyntax.nim | 27 | ||||
-rw-r--r-- | tests/objvariant/treassign.nim | 27 |
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/objects/trefobjsyntax.nim b/tests/objects/trefobjsyntax.nim new file mode 100644 index 000000000..9b48de718 --- /dev/null +++ b/tests/objects/trefobjsyntax.nim @@ -0,0 +1,27 @@ +discard """ + output: '''wohoo +baz''' +""" + +# Test to ensure the popular 'ref T' syntax works everywhere + +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)) + diff --git a/tests/objvariant/treassign.nim b/tests/objvariant/treassign.nim new file mode 100644 index 000000000..2938b30a3 --- /dev/null +++ b/tests/objvariant/treassign.nim @@ -0,0 +1,27 @@ +discard """ + output: "SUCCESS" +""" + +type + BasicNumber = object of RootObj + value: float32 + RefChild* = ref object + curr*: TokenObject + Token* {.pure.} = enum + foo, + bar, + TokenObject = object + case kind*: Token + of Token.foo: + foo*: string + of Token.bar: + bar*: BasicNumber + + +var t = RefChild() + +t.curr = TokenObject(kind: Token.bar, bar: BasicNumber(value: 12.34)) + +t.curr = TokenObject(kind: Token.foo, foo: "foo") + +echo "SUCCESS" |