new tester; all tests categorized

This commit is contained in:
Araq 2014-01-13 02:10:03 +01:00
commit 20b5f31c03
481 changed files with 794 additions and 2506 deletions

12
tests/method/mmultim3.nim Normal file
View file

@ -0,0 +1,12 @@
type
TObj* = object {.inheritable.}
var myObj* : ref TObj
method test123(a : ref TObj) =
echo("Hi base!")
proc testMyObj*() =
test123(myObj)

8
tests/method/tmethod.nim Normal file
View file

@ -0,0 +1,8 @@
discard """
file: "tmethod.nim"
line: 7
errormsg: "\'method\' needs a parameter that has an object type"
"""
method m(i: int): int =
return 5

View file

@ -0,0 +1,22 @@
discard """
output: "do nothing"
"""
method somethin(obj: TObject) =
echo "do nothing"
type
TNode* = object {.inheritable.}
PNode* = ref TNode
PNodeFoo* = ref object of TNode
TSomethingElse = object
PSomethingElse = ref TSomethingElse
method foo(a: PNode, b: PSomethingElse) = nil
method foo(a: PNodeFoo, b: PSomethingElse) = nil
var o: TObject
o.somethin()

29
tests/method/tmultim1.nim Normal file
View file

@ -0,0 +1,29 @@
discard """
file: "tmultim1.nim"
output: "7"
"""
# Test multi methods
type
Expression = ref object {.inheritable.}
Literal = ref object of Expression
x: int
PlusExpr = ref object of Expression
a, b: Expression
method eval(e: Expression): int = quit "to override!"
method eval(e: Literal): int = return e.x
method eval(e: PlusExpr): int = return eval(e.a) + eval(e.b)
proc newLit(x: int): Literal =
new(result)
result.x = x
proc newPlus(a, b: Expression): PlusExpr =
new(result)
result.a = a
result.b = b
echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) #OUT 7

36
tests/method/tmultim2.nim Normal file
View file

@ -0,0 +1,36 @@
discard """
file: "tmultim2.nim"
output: "collide: unit, thing collide: unit, thing collide: thing, unit"
"""
# Test multi methods
type
TThing = object {.inheritable.}
TUnit = object of TThing
x: int
TParticle = object of TThing
a, b: int
method collide(a, b: TThing) {.inline.} =
quit "to override!"
method collide(a: TThing, b: TUnit) {.inline.} =
write stdout, "collide: thing, unit "
method collide(a: TUnit, b: TThing) {.inline.} =
write stdout, "collide: unit, thing "
proc test(a, b: TThing) {.inline.} =
collide(a, b)
var
a: TThing
b, c: TUnit
collide(b, c) # ambiguous (unit, thing) or (thing, unit)? -> prefer unit, thing!
test(b, c)
collide(a, b)
#OUT collide: unit, thing collide: unit, thing collide: thing, unit

20
tests/method/tmultim3.nim Normal file
View file

@ -0,0 +1,20 @@
discard """
file: "tmultim3.nim"
output: "Hi derived!"
"""
import mmultim3
type
TBObj* = object of TObj
method test123(a : ref TBObj) =
echo("Hi derived!")
var a : ref TBObj
new(a)
myObj = a
testMyObj()

47
tests/method/tmultim4.nim Normal file
View file

@ -0,0 +1,47 @@
discard """
file: "tmultim4.nim"
output: "hello"
"""
type
Test = object of TObject
method doMethod(a: ref TObject) {.raises: [EIO].} =
quit "override"
method doMethod(a: ref Test) =
echo "hello"
if a == nil:
raise newException(EIO, "arg")
proc doProc(a: ref Test) =
echo "hello"
proc newTest(): ref Test =
new(result)
var s:ref Test = newTest()
#doesn't work
for z in 1..4:
s.doMethod()
break
#works
#for z in 1..4:
# s.doProc()
# break
#works
#while true:
# s.doMethod()
# break
#works
#while true:
# s.doProc()
# break

30
tests/method/tmultim6.nim Normal file
View file

@ -0,0 +1,30 @@
discard """
output: "collide: unit, thing | collide: unit, thing | collide: thing, unit |"
"""
# Test multi methods
type
TThing = object {.inheritable.}
TUnit[T] = object of TThing
x: T
TParticle = object of TThing
a, b: int
method collide(a, b: TThing) {.inline.} =
quit "to override!"
method collide[T](a: TThing, b: TUnit[T]) {.inline.} =
write stdout, "collide: thing, unit | "
method collide[T](a: TUnit[T], b: TThing) {.inline.} =
write stdout, "collide: unit, thing | "
proc test(a, b: TThing) {.inline.} =
collide(a, b)
var
a: TThing
b, c: TUnit[string]
collide(b, TThing(c))
test(b, c)
collide(a, b)

14
tests/method/tsimmeth.nim Normal file
View file

@ -0,0 +1,14 @@
discard """
file: "tsimmeth.nim"
output: "HELLO WORLD!"
"""
# Test method simulation
import strutils
var x = "hello world!".toLower.toUpper
x.echo()
#OUT HELLO WORLD!