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
This commit is contained in:
Miran
2018-10-16 10:50:10 +02:00
committed by Andreas Rumpf
parent f04c93b5dd
commit 749dbce4c6
96 changed files with 1763 additions and 1815 deletions

View File

@@ -1,53 +0,0 @@
discard """
output: '''tbObj of TC true
true
5'''
"""
# bug #1053
type
TA = object of RootObj
a: int
TB = object of TA
b: int
TC = object of TB
c: int
proc test(p: TA) =
#echo "p of TB ", p of TB
if p of TB:
#var tbObj = TB(p)
# tbObj is actually no longer compatible with TC:
echo "tbObj of TC ", p of TC
var v = TC()
v.a = 1
v.b = 2
v.c = 3
test(v)
# bug #924
type
MyObject = object of RootObj
x: int
var
asd: MyObject
proc isMyObject(obj: RootObj) =
echo obj of MyObject
if obj of MyObject:
let a = MyObject(obj)
echo a.x
asd.x = 5
#var asdCopy = RootObj(asd)
#echo asdCopy of MyObject
isMyObject(asd)
#isMyObject(asdCopy)

View File

@@ -1,13 +0,0 @@
discard """
output: '''true'''
"""
# bug #4673
type
BaseObj[T] = ref object of RootObj
SomeObj = ref object of BaseObj[int]
proc doSomething[T](o: BaseObj[T]) =
echo "true"
var o = new(SomeObj)
o.doSomething() # Error: cannot instantiate: 'T'

117
tests/objects/tissues.nim Normal file
View File

@@ -0,0 +1,117 @@
discard """
output: '''
tbObj of TC true
true
5
true
is Nil false
'''
"""
block t1053:
type
TA = object of RootObj
a: int
TB = object of TA
b: int
TC = object of TB
c: int
proc test(p: TA) =
if p of TB:
echo "tbObj of TC ", p of TC
var v = TC()
v.a = 1
v.b = 2
v.c = 3
test(v)
block t924:
type
MyObject = object of RootObj
x: int
var asd: MyObject
proc isMyObject(obj: RootObj) =
echo obj of MyObject
if obj of MyObject:
let a = MyObject(obj)
echo a.x
asd.x = 5
isMyObject(asd)
block t4673:
type
BaseObj[T] = ref object of RootObj
SomeObj = ref object of BaseObj[int]
proc doSomething[T](o: BaseObj[T]) =
echo "true"
var o = new(SomeObj)
o.doSomething() # Error: cannot instantiate: 'T'
block t1658:
type
Loop = ref object
onBeforeSelect: proc (L: Loop)
var L: Loop
new L
L.onBeforeSelect = proc (bar: Loop) =
echo "is Nil ", bar.isNil
L.onBeforeSelect(L)
block t2508:
type
GenericNodeObj[T] = ref object
obj: T
Node = ref object
children: seq[Node]
parent: Node
nodeObj: GenericNodeObj[int]
proc newNode(nodeObj: GenericNodeObj): Node =
result = Node(nodeObj: nodeObj)
newSeq(result.children, 10)
var genericObj = GenericNodeObj[int]()
var myNode = newNode(genericObj)
block t2540:
type
BaseSceneNode[T] = ref object of RootObj
children: seq[BaseSceneNode[T]]
parent: BaseSceneNode[T]
SceneNode[T] = ref object of BaseSceneNode[T]
SomeObj = ref object
proc newSceneNode[T](): SceneNode[T] =
new result
result.children = @[]
var aNode = newSceneNode[SomeObj]()
block t3038:
type
Data[T] = ref object of RootObj
data: T
Type = ref object of RootObj
SubType[T] = ref object of Type
data: Data[T]
SubSubType = ref object of SubType
SubSubSubType = ref object of SubSubType

View File

@@ -1,21 +0,0 @@
# 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)

View File

@@ -1,15 +0,0 @@
discard """
output: "is Nil false"
"""
# bug #1658
type
Loop* = ref object
onBeforeSelect*: proc (L: Loop)
var L: Loop
new L
L.onBeforeSelect = proc (bar: Loop) =
echo "is Nil ", bar.isNil
L.onBeforeSelect(L)

View File

@@ -1,26 +0,0 @@
discard """
file: "tofopr.nim"
output: "falsetrue"
"""
# Test is operator
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
write(stdout, p(m))
write(stdout, p(n))
#OUT falsetrue

View File

@@ -1,21 +0,0 @@
discard """
output: "b"
"""
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)

View File

@@ -1,27 +0,0 @@
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))

View File

@@ -1,19 +0,0 @@
# bug #2508
type
GenericNodeObj[T] = ref object
obj: T
Node* = ref object
children*: seq[Node]
parent*: Node
nodeObj*: GenericNodeObj[int]
proc newNode*(nodeObj: GenericNodeObj): Node =
result = Node(nodeObj: nodeObj)
newSeq(result.children, 10)
var genericObj = GenericNodeObj[int]()
var myNode = newNode(genericObj)

View File

@@ -1,28 +0,0 @@
# bug #2540
type
BaseSceneNode[T] = ref object of RootObj
children*: seq[BaseSceneNode[T]]
parent*: BaseSceneNode[T]
SceneNode[T] = ref object of BaseSceneNode[T]
SomeObj = ref object
proc newSceneNode[T](): SceneNode[T] =
new result
result.children = @[]
var aNode = newSceneNode[SomeObj]()
# bug #3038
type
Data[T] = ref object of RootObj
data: T
Type = ref object of RootObj
SubType[T] = ref object of Type
data: Data[T]
SubSubType = ref object of SubType
SubSubSubType = ref object of SubSubType

View File

@@ -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))