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

16
tests/types/tfinalobj.nim Normal file
View file

@ -0,0 +1,16 @@
discard """
output: "abc"
"""
type
TA = object {.pure, final.}
x: string
var
a: TA
a.x = "abc"
doAssert TA.sizeof == string.sizeof
echo a.x

9
tests/types/tforwty.nim Normal file
View file

@ -0,0 +1,9 @@
# Test 13: forward types
type
PSym = ref TSym
TSym = object
next: PSym
var s: PSym

22
tests/types/tforwty2.nim Normal file
View file

@ -0,0 +1,22 @@
# Test for a hard to fix internal error
# occured in the SDL library
{.push dynlib: "SDL.dll", callconv: cdecl.}
type
PSDL_semaphore = ptr TSDL_semaphore
TSDL_semaphore {.final.} = object
sem: Pointer #PSem_t;
when not defined(USE_NAMED_SEMAPHORES):
sem_data: int
when defined(BROKEN_SEMGETVALUE):
# This is a little hack for MacOS X -
# It's not thread-safe, but it's better than nothing
sem_value: cint
type
PSDL_Sem = ptr TSDL_Sem
TSDL_Sem = TSDL_Semaphore
proc SDL_CreateSemaphore(initial_value: Int32): PSDL_Sem {.
importc: "SDL_CreateSemaphore".}

View file

@ -0,0 +1,66 @@
discard """
cmd: "nimrod c --threads:on $# $#"
errormsg: "illegal recursion in type 'TIRC'"
line: 16
"""
import events
import sockets
import strutils
import os
type
TMessageReceivedEventArgs = object of TEventArgs
Nick*: string
Message*: string
TIRC = object
EventEmitter: TEventEmitter
MessageReceivedHandler*: TEventHandler
Socket: TSocket
Thread: TThread[TIRC]
proc initIRC*(): TIRC =
result.Socket = socket()
result.EventEmitter = initEventEmitter()
result.MessageReceivedHandler = initEventHandler("MessageReceived")
proc IsConnected*(irc: var TIRC): bool =
return running(irc.Thread)
proc sendRaw*(irc: var TIRC, message: string) =
irc.Socket.send(message & "\r\L")
proc handleData(irc: TIRC) {.thread.} =
var connected = False
while connected:
var tup = @[irc.Socket]
var o = select(tup, 200)
echo($o)
echo($len(tup))
if len(tup) == 1:
#Connected
connected = True
#Parse data here
else:
#Disconnected
connected = False
return
proc Connect*(irc: var TIRC, nick: string, host: string, port: int = 6667) =
connect(irc.Socket ,host ,TPort(port),TDomain.AF_INET)
send(irc.Socket,"USER " & nick & " " & nick & " " & nick & " " & nick &"\r\L")
send(irc.Socket,"NICK " & nick & "\r\L")
var thread: TThread[TIRC]
createThread(thread, handleData, irc)
irc.Thread = thread
when isMainModule:
var irc = initIRC()
irc.Connect("AmryBot[Nim]","irc.freenode.net",6667)
irc.sendRaw("JOIN #nimrod")
os.Sleep(4000)

16
tests/types/tillrec.nim Normal file
View file

@ -0,0 +1,16 @@
discard """
file: "tillrec.nim"
line: 13
errormsg: "illegal recursion in type \'TIllegal\'"
"""
# test illegal recursive types
type
TLegal {.final.} = object
x: int
kids: seq[TLegal]
TIllegal {.final.} = object #ERROR_MSG illegal recursion in type 'TIllegal'
y: Int
x: array[0..3, TIllegal]

View file

@ -0,0 +1,27 @@
discard """
output: "23"
"""
# bug #554, #179
type T[E] =
ref object
elem: E
var ob: T[int]
ob = T[int](elem: 23)
echo ob.elem
type
TTreeIteratorA* = ref object {.inheritable.}
TKeysIteratorA* = ref object of TTreeIteratorA #compiles
TTreeIterator* [T,D] = ref object {.inheritable.}
TKeysIterator* [T,D] = ref object of TTreeIterator[T,D] #this not
var
it: TKeysIterator[int, string] = nil

42
tests/types/tisop.nim Normal file
View file

@ -0,0 +1,42 @@
import typetraits
type
TRecord = (tuple) or (object)
TFoo[T, U] = object
x: int
when T is string:
y: float
else:
y: string
when U is TRecord:
z: float
E = enum A, B, C
macro m(t: typedesc): typedesc =
if t is enum:
result = string
else:
result = int
var f: TFoo[int, int]
static: assert(f.y.type.name == "string")
when compiles(f.z):
{.error: "Foo should not have a `z` field".}
proc p(a, b) =
when a.type is int:
static: assert false
var f: TFoo[m(a.type), b.type]
static:
assert f.x.type.name == "int"
assert f.y.type.name == "float"
assert f.z.type.name == "float"
p(A, f)

13
tests/types/tisopr.nim Normal file
View file

@ -0,0 +1,13 @@
discard """
output: "true true false yes"
"""
proc IsVoid[T](): string =
when T is void:
result = "yes"
else:
result = "no"
const x = int is int
echo x, " ", float is float, " ", float is string, " ", IsVoid[void]()