summary refs log tree commit diff stats
path: root/tests/objects
diff options
context:
space:
mode:
authorMiran <narimiran@users.noreply.github.com>2018-10-16 10:50:10 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-10-16 10:50:10 +0200
commit749dbce4c69224f5464908d8f714291f17aa60fa (patch)
treecc91326ef536f15d8d9aa97efab4fc8473d093c7 /tests/objects
parentf04c93b5dd1ee5e185f6849ad8116d08a687026d (diff)
downloadNim-749dbce4c69224f5464908d8f714291f17aa60fa.tar.gz
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
Diffstat (limited to 'tests/objects')
-rw-r--r--tests/objects/tinherentedvalues.nim53
-rw-r--r--tests/objects/tinherit_from_generic.nim13
-rw-r--r--tests/objects/tissues.nim117
-rw-r--r--tests/objects/tobject2.nim21
-rw-r--r--tests/objects/tobjloop.nim15
-rw-r--r--tests/objects/tofopr.nim26
-rw-r--r--tests/objects/toop.nim21
-rw-r--r--tests/objects/trefobjsyntax.nim27
-rw-r--r--tests/objects/trefobjsyntax2.nim19
-rw-r--r--tests/objects/trefobjsyntax3.nim28
-rw-r--r--tests/objects/tvarious.nim87
11 files changed, 204 insertions, 223 deletions
diff --git a/tests/objects/tinherentedvalues.nim b/tests/objects/tinherentedvalues.nim
deleted file mode 100644
index 7d4d7d23e..000000000
--- a/tests/objects/tinherentedvalues.nim
+++ /dev/null
@@ -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)
diff --git a/tests/objects/tinherit_from_generic.nim b/tests/objects/tinherit_from_generic.nim
deleted file mode 100644
index 6e0e929ce..000000000
--- a/tests/objects/tinherit_from_generic.nim
+++ /dev/null
@@ -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'
diff --git a/tests/objects/tissues.nim b/tests/objects/tissues.nim
new file mode 100644
index 000000000..fddfff7d5
--- /dev/null
+++ b/tests/objects/tissues.nim
@@ -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
diff --git a/tests/objects/tobject2.nim b/tests/objects/tobject2.nim
deleted file mode 100644
index a49296843..000000000
--- a/tests/objects/tobject2.nim
+++ /dev/null
@@ -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)
diff --git a/tests/objects/tobjloop.nim b/tests/objects/tobjloop.nim
deleted file mode 100644
index 9fea1e2fb..000000000
--- a/tests/objects/tobjloop.nim
+++ /dev/null
@@ -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)
diff --git a/tests/objects/tofopr.nim b/tests/objects/tofopr.nim
deleted file mode 100644
index ab2854571..000000000
--- a/tests/objects/tofopr.nim
+++ /dev/null
@@ -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
-
-
diff --git a/tests/objects/toop.nim b/tests/objects/toop.nim
deleted file mode 100644
index 4bd3998f3..000000000
--- a/tests/objects/toop.nim
+++ /dev/null
@@ -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)
-
diff --git a/tests/objects/trefobjsyntax.nim b/tests/objects/trefobjsyntax.nim
deleted file mode 100644
index 9b48de718..000000000
--- a/tests/objects/trefobjsyntax.nim
+++ /dev/null
@@ -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))
-
diff --git a/tests/objects/trefobjsyntax2.nim b/tests/objects/trefobjsyntax2.nim
deleted file mode 100644
index 8ee209cc7..000000000
--- a/tests/objects/trefobjsyntax2.nim
+++ /dev/null
@@ -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)
diff --git a/tests/objects/trefobjsyntax3.nim b/tests/objects/trefobjsyntax3.nim
deleted file mode 100644
index 2d466eeda..000000000
--- a/tests/objects/trefobjsyntax3.nim
+++ /dev/null
@@ -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
diff --git a/tests/objects/tvarious.nim b/tests/objects/tvarious.nim
new file mode 100644
index 000000000..504681b99
--- /dev/null
+++ b/tests/objects/tvarious.nim
@@ -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))