new tester; all tests categorized
This commit is contained in:
parent
51ee524109
commit
20b5f31c03
481 changed files with 794 additions and 2506 deletions
10
tests/bind/mbind3.nim
Normal file
10
tests/bind/mbind3.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Module A
|
||||
var
|
||||
lastId = 0
|
||||
|
||||
template genId*: expr =
|
||||
bind lastId
|
||||
inc(lastId)
|
||||
lastId
|
||||
|
||||
|
||||
21
tests/bind/tbind1.nim
Normal file
21
tests/bind/tbind1.nim
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
discard """
|
||||
file: "tbind1.nim"
|
||||
output: "3"
|
||||
"""
|
||||
# Test the new ``bind`` keyword for templates
|
||||
|
||||
proc p1(x: int8, y: int): int = return x + y
|
||||
|
||||
template tempBind(x, y: expr): expr =
|
||||
bind p1
|
||||
p1(x, y)
|
||||
|
||||
proc p1(x: int, y: int8): int = return x - y
|
||||
|
||||
# This is tricky: the call to ``p1(1'i8, 2'i8)`` should not fail in line 6,
|
||||
# because it is not ambiguous there. But it is ambiguous after line 8.
|
||||
|
||||
echo tempBind(1'i8, 2'i8) #OUT 3
|
||||
|
||||
|
||||
|
||||
17
tests/bind/tbind2.nim
Normal file
17
tests/bind/tbind2.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
discard """
|
||||
file: "tbind2.nim"
|
||||
line: 14
|
||||
errormsg: "ambiguous call"
|
||||
"""
|
||||
# Test the new ``bind`` keyword for templates
|
||||
|
||||
proc p1(x: int8, y: int): int = return x + y
|
||||
proc p1(x: int, y: int8): int = return x - y
|
||||
|
||||
template tempBind(x, y: expr): expr =
|
||||
(bind p1(x, y)) #ERROR_MSG ambiguous call
|
||||
|
||||
echo tempBind(1'i8, 2'i8)
|
||||
|
||||
|
||||
|
||||
11
tests/bind/tbind3.nim
Normal file
11
tests/bind/tbind3.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
discard """
|
||||
file: "tbind3.nim"
|
||||
output: "1"
|
||||
"""
|
||||
# Module B
|
||||
import mbind3
|
||||
|
||||
echo genId() #OUT 1
|
||||
|
||||
|
||||
|
||||
12
tests/bind/tbindoverload.nim
Normal file
12
tests/bind/tbindoverload.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import strtabs
|
||||
|
||||
template t*() =
|
||||
block:
|
||||
bind newStringTable
|
||||
discard {"Content-Type": "text/html"}.newStringTable()
|
||||
|
||||
discard {:}.newStringTable
|
||||
|
||||
#discard {"Content-Type": "text/html"}.newStringTable()
|
||||
|
||||
t()
|
||||
12
tests/bind/tbindtypedesc.nim
Normal file
12
tests/bind/tbindtypedesc.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
discard """
|
||||
line: 11
|
||||
file: "tbindtypedesc.nim"
|
||||
errormsg: "type mismatch: got (typedesc[float], string)"
|
||||
"""
|
||||
|
||||
proc foo(T: typedesc; some: T) =
|
||||
echo($some)
|
||||
|
||||
foo int, 4
|
||||
foo float, "bad"
|
||||
|
||||
95
tests/bind/tdatabind.nim
Normal file
95
tests/bind/tdatabind.nim
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
import events
|
||||
type
|
||||
TProperty*[T] = object of TObject
|
||||
getProc: proc(property: TProperty[T]): T {.nimcall.}
|
||||
setProc: proc(property: var TProperty[T], value: T) {.nimcall.}
|
||||
value: T
|
||||
ValueChanged*: TEventHandler
|
||||
Binders: seq[TProperty[T]]
|
||||
EEmitter: TEventEmitter
|
||||
# Not a descriptive name but it was that or TPropertyValueChangeEventArgs.
|
||||
TValueEventArgs[T] = object of TEventArgs
|
||||
Property*: TProperty[T]
|
||||
|
||||
|
||||
proc newProperty*[T](value: T): TProperty[T] =
|
||||
var prop: TProperty[T]
|
||||
|
||||
prop.EEmitter = initEventEmitter()
|
||||
prop.Binders = @[]
|
||||
prop.ValueChanged = initEventHandler("ValueChanged")
|
||||
prop.value = value
|
||||
|
||||
proc getter(property: TProperty[T]): T =
|
||||
return property.value
|
||||
|
||||
prop.getProc = getter
|
||||
|
||||
proc setter(property: var TProperty[T], v: T) =
|
||||
property.value = v
|
||||
|
||||
# fire event here
|
||||
var args: TValueEventArgs[T]
|
||||
args.Property = property
|
||||
property.EEmitter.emit(property.ValueChanged, args)
|
||||
|
||||
prop.setProc = setter
|
||||
|
||||
return prop
|
||||
|
||||
proc `prop`[T] (p: TProperty[T]): T =
|
||||
# I'm assuming this is trying to get a value from the property.
|
||||
# i.e. myVar = myProperty
|
||||
return p.getProc(p)
|
||||
|
||||
proc `~=`[T] (p: var TProperty[T], v: T) =
|
||||
# Assuming this is setting the value.
|
||||
p.setProc(p, v)
|
||||
|
||||
proc `$`[T] (p: TProperty[T]): string =
|
||||
var value = p.getProc(p)
|
||||
return $value
|
||||
|
||||
proc propertyBind*[T](p1: var TProperty[T], p2: var TProperty[T]) =
|
||||
p1.Binders.add(p2)
|
||||
|
||||
# make handler -> handler[T] so trigger even more generics bugs ...
|
||||
proc handler(e: TEventArgs) =
|
||||
type TEA = TValueEventArgs[T]
|
||||
var args = TEA(e)
|
||||
var val = args.Property.getProc(p1)
|
||||
for i in countup(0, len(e.Property.ValueChanged.Binders) -1):
|
||||
var binded = e.Property.ValueChanged.Binders[i]
|
||||
binded.setProc(binded, val)
|
||||
|
||||
echo("Property 1 has changed to " & $val)
|
||||
|
||||
if p1.ValueChanged.containsHandler(handler) == false:
|
||||
addHandler(p1.ValueChanged, handler)
|
||||
|
||||
proc `->`[T](p1: var TProperty[T], p2: var TProperty[T]) =
|
||||
propertyBind(p2,p1)
|
||||
|
||||
when isMainModule:
|
||||
# Initial value testing
|
||||
var myProp = newProperty(5)
|
||||
|
||||
echo(myProp)
|
||||
|
||||
myProp ~= 7 # Temp operator until overloading of '=' is implemented.
|
||||
echo(myProp)
|
||||
|
||||
# Binding testing
|
||||
|
||||
var prop1 = newProperty(9)
|
||||
var prop2: TProperty[int]
|
||||
|
||||
prop2 -> prop1 # Binds prop2 to prop1
|
||||
|
||||
prop1 ~= 7
|
||||
echo(prop2) # Output: 7
|
||||
|
||||
27
tests/bind/tmixin.nim
Normal file
27
tests/bind/tmixin.nim
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
discard """
|
||||
output: "1\n2"
|
||||
"""
|
||||
|
||||
type
|
||||
TFoo1 = object of TObject
|
||||
v: int
|
||||
TFoo2 = object of TFoo1
|
||||
v2: int
|
||||
|
||||
proc test(f: TFoo1) =
|
||||
echo "1"
|
||||
|
||||
proc Foo[T](f: T) =
|
||||
mixin test
|
||||
test(f)
|
||||
|
||||
var
|
||||
a: TFoo1
|
||||
b: TFoo2
|
||||
|
||||
|
||||
proc test(f: TFoo2) =
|
||||
echo "2"
|
||||
|
||||
Foo(a)
|
||||
Foo(b)
|
||||
18
tests/bind/tnicerrorforsymchoice.nim
Normal file
18
tests/bind/tnicerrorforsymchoice.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
discard """
|
||||
line: 18
|
||||
errormsg: "type mismatch: got (proc (TScgi) | proc (PAsyncSocket, PStringTable, string))"
|
||||
"""
|
||||
|
||||
#bug #442
|
||||
import scgi, sockets, asyncio, strtabs
|
||||
proc handleSCGIRequest[TScgi: TScgiState | PAsyncScgiState](s: TScgi) =
|
||||
nil
|
||||
proc handleSCGIRequest(client: PAsyncSocket, headers: PStringTable,
|
||||
input: string) =
|
||||
nil
|
||||
|
||||
proc test(handle: proc (client: PAsyncSocket, headers: PStringTable,
|
||||
input: string), b: int) =
|
||||
nil
|
||||
|
||||
test(handleSCGIRequest)
|
||||
Loading…
Add table
Add a link
Reference in a new issue