new tester; all tests categorized
This commit is contained in:
parent
51ee524109
commit
20b5f31c03
481 changed files with 794 additions and 2506 deletions
13
tests/overload/toverl.nim
Normal file
13
tests/overload/toverl.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
discard """
|
||||
file: "toverl.nim"
|
||||
line: 11
|
||||
errormsg: "redefinition of \'TNone\'"
|
||||
"""
|
||||
# Test for overloading
|
||||
|
||||
type
|
||||
TNone {.exportc: "_NONE", final.} = object
|
||||
|
||||
proc TNone(a, b: int) = nil #ERROR_MSG attempt to redefine 'TNone'
|
||||
|
||||
|
||||
33
tests/overload/toverl2.nim
Normal file
33
tests/overload/toverl2.nim
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
discard """
|
||||
file: "toverl2.nim"
|
||||
output: "true012innertrue"
|
||||
"""
|
||||
# Test new overloading resolution rules
|
||||
|
||||
import strutils
|
||||
|
||||
proc toverl2(x: int): string = return $x
|
||||
proc toverl2(x: bool): string = return $x
|
||||
|
||||
iterator toverl2(x: int): int =
|
||||
var res = 0
|
||||
while res < x:
|
||||
yield res
|
||||
inc(res)
|
||||
|
||||
var
|
||||
pp: proc (x: bool): string {.nimcall.} = toverl2
|
||||
|
||||
stdout.write(pp(true))
|
||||
|
||||
for x in toverl2(3):
|
||||
stdout.write(toverl2(x))
|
||||
|
||||
block:
|
||||
proc toverl2(x: int): string = return "inner"
|
||||
stdout.write(toverl2(5))
|
||||
stdout.write(true)
|
||||
|
||||
stdout.write("\n")
|
||||
#OUT true012innertrue
|
||||
|
||||
20
tests/overload/toverl3.nim
Normal file
20
tests/overload/toverl3.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
discard """
|
||||
file: "toverl3.nim"
|
||||
output: '''m1
|
||||
tup1'''
|
||||
"""
|
||||
|
||||
# Tests more specific generic match:
|
||||
|
||||
proc m[T](x: T) = echo "m2"
|
||||
proc m[T](x: var ref T) = echo "m1"
|
||||
|
||||
proc tup[S, T](x: tuple[a: S, b: ref T]) = echo "tup1"
|
||||
proc tup[S, T](x: tuple[a: S, b: T]) = echo "tup2"
|
||||
|
||||
var
|
||||
obj: ref int
|
||||
tu: tuple[a: int, b: ref bool]
|
||||
|
||||
m(obj)
|
||||
tup(tu)
|
||||
39
tests/overload/toverprc.nim
Normal file
39
tests/overload/toverprc.nim
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# Test overloading of procs when used as function pointers
|
||||
|
||||
import strutils
|
||||
|
||||
proc parseInt(x: float): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: bool): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: float32): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: int8): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: TFile): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: char): int {.noSideEffect.} = nil
|
||||
proc parseInt(x: int16): int {.noSideEffect.} = nil
|
||||
|
||||
proc parseInt[T](x: T): int = echo x; 34
|
||||
|
||||
type
|
||||
TParseInt = proc (x: string): int {.noSideEffect.}
|
||||
|
||||
var
|
||||
q = TParseInt(parseInt)
|
||||
p: TParseInt = parseInt
|
||||
|
||||
proc takeParseInt(x: proc (y: string): int {.noSideEffect.}): int =
|
||||
result = x("123")
|
||||
|
||||
echo "Give a list of numbers (separated by spaces): "
|
||||
var x = stdin.readline.split.map(parseInt).max
|
||||
echo x, " is the maximum!"
|
||||
echo "another number: ", takeParseInt(parseInt)
|
||||
|
||||
|
||||
type
|
||||
TFoo[a,b] = object
|
||||
lorem: a
|
||||
ipsum: b
|
||||
|
||||
proc bar[a,b](f: TFoo[a,b], x: a) = echo(x, " ", f.lorem, f.ipsum)
|
||||
proc bar[a,b](f: TFoo[a,b], x: b) = echo(x, " ", f.lorem, f.ipsum)
|
||||
|
||||
discard parseInt[string]("yay")
|
||||
13
tests/overload/toverwr.nim
Normal file
13
tests/overload/toverwr.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
discard """
|
||||
file: "toverwr.nim"
|
||||
output: "hello"
|
||||
"""
|
||||
# Test the overloading resolution in connection with a qualifier
|
||||
|
||||
proc write(t: TFile, s: string) =
|
||||
nil # a nop
|
||||
|
||||
system.write(stdout, "hello")
|
||||
#OUT hello
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue