* add test * add changelod entry Co-authored-by: cooldome <ariabushenko@bk.ru>
This commit is contained in:
parent
b6f99409a9
commit
9295251e68
9 changed files with 292 additions and 108 deletions
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue