diff options
author | cooldome <cdome@bk.ru> | 2020-04-16 20:04:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-16 21:04:05 +0200 |
commit | 9295251e68ee86b512de51a2f650729ac6893104 (patch) | |
tree | 93c1889f1d76cd99e9f7ea7a2040fe24a16947d3 /tests/arc | |
parent | b6f99409a967baebfda056a46f236643837e483b (diff) | |
download | Nim-9295251e68ee86b512de51a2f650729ac6893104.tar.gz |
Implements RFCs #209 (#13995)
* add test * add changelod entry Co-authored-by: cooldome <ariabushenko@bk.ru>
Diffstat (limited to 'tests/arc')
-rw-r--r-- | tests/arc/tcaseobj.nim | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/arc/tcaseobj.nim b/tests/arc/tcaseobj.nim index 44daa5979..71f3960ef 100644 --- a/tests/arc/tcaseobj.nim +++ b/tests/arc/tcaseobj.nim @@ -8,6 +8,7 @@ A B begin end +prevented myobj destroyed ''' """ @@ -144,3 +145,51 @@ when true: let x = sequence([charSet({'a'..'z', 'A'..'Z', '_'})]) echo "end" testSubObjAssignment() + + +#------------------------------------------------ + +type + MyObject = object + x1: string + case kind1: bool + of false: y1: string + of true: + y2: seq[string] + case kind2: bool + of true: z1: string + of false: + z2: seq[string] + flag: bool + x2: string + +proc test_myobject = + var x: MyObject + x.x1 = "x1" + x.x2 = "x2" + x.y1 = "ljhkjhkjh" + x.kind1 = true + x.y2 = @["1", "2"] + x.kind2 = true + x.z1 = "yes" + x.kind2 = false + x.z2 = @["1", "2"] + x.kind2 = true + x.z1 = "yes" + x.kind2 = true # should be no effect + doAssert(x.z1 == "yes") + x.kind2 = false + x.kind1 = x.kind2 # support self assignment with effect + + try: + x.kind1 = x.flag # flag is not accesible + except FieldError: + echo "prevented" + + doAssert(x.x1 == "x1") + doAssert(x.x2 == "x2") + + +test_myobject() + + |