* 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()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
discard """
|
||||
cmd: "nim c --gc:arc --exceptions:goto --panics:off $file"
|
||||
output: '''field error prevented
|
||||
prevented!
|
||||
output: '''prevented!
|
||||
caught
|
||||
AssertionError
|
||||
900'''
|
||||
|
|
@ -26,11 +25,8 @@ proc helper = doAssert(false)
|
|||
|
||||
proc main(i: int) =
|
||||
var obj = Obj(kind: kindA, s: "abc")
|
||||
try:
|
||||
obj.kind = kindB
|
||||
except FieldError:
|
||||
echo "field error prevented"
|
||||
|
||||
obj.kind = kindB
|
||||
obj.i = 2
|
||||
try:
|
||||
var objA = ObjA()
|
||||
bplease(ObjB(objA))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue