more tests green

This commit is contained in:
Araq 2014-08-31 17:23:35 +02:00
commit d7d059a686
16 changed files with 79 additions and 79 deletions

View file

@ -1799,11 +1799,11 @@ proc inet_pton*(a1: cint, a2: cstring, a3: pointer): cint {.
importc, header: "<arpa/inet.h>".} importc, header: "<arpa/inet.h>".}
var var
in6addr_any* {.importc, header: "<netinet/in.h>".}: TIn6_addr in6addr_any* {.importc, header: "<netinet/in.h>".}: TIn6Addr
in6addr_loopback* {.importc, header: "<netinet/in.h>".}: TIn6_addr in6addr_loopback* {.importc, header: "<netinet/in.h>".}: TIn6Addr
proc IN6ADDR_ANY_INIT* (): TIn6_addr {.importc, header: "<netinet/in.h>".} proc IN6ADDR_ANY_INIT* (): TIn6Addr {.importc, header: "<netinet/in.h>".}
proc IN6ADDR_LOOPBACK_INIT* (): TIn6_addr {.importc, header: "<netinet/in.h>".} proc IN6ADDR_LOOPBACK_INIT* (): TIn6Addr {.importc, header: "<netinet/in.h>".}
# dirent.h # dirent.h
proc closedir*(a1: ptr TDIR): cint {.importc, header: "<dirent.h>".} proc closedir*(a1: ptr TDIR): cint {.importc, header: "<dirent.h>".}
@ -2518,40 +2518,40 @@ proc if_indextoname*(a1: cint, a2: cstring): cstring {.
proc if_nameindex*(): ptr Tif_nameindex {.importc, header: "<net/if.h>".} proc if_nameindex*(): ptr Tif_nameindex {.importc, header: "<net/if.h>".}
proc if_freenameindex*(a1: ptr Tif_nameindex) {.importc, header: "<net/if.h>".} proc if_freenameindex*(a1: ptr Tif_nameindex) {.importc, header: "<net/if.h>".}
proc IN6_IS_ADDR_UNSPECIFIED* (a1: ptr TIn6_addr): cint {. proc IN6_IS_ADDR_UNSPECIFIED* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".} importc, header: "<netinet/in.h>".}
## Unspecified address. ## Unspecified address.
proc IN6_IS_ADDR_LOOPBACK* (a1: ptr TIn6_addr): cint {. proc IN6_IS_ADDR_LOOPBACK* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".} importc, header: "<netinet/in.h>".}
## Loopback address. ## Loopback address.
proc IN6_IS_ADDR_MULTICAST* (a1: ptr TIn6_addr): cint {. proc IN6_IS_ADDR_MULTICAST* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".} importc, header: "<netinet/in.h>".}
## Multicast address. ## Multicast address.
proc IN6_IS_ADDR_LINKLOCAL* (a1: ptr TIn6_addr): cint {. proc IN6_IS_ADDR_LINKLOCAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".} importc, header: "<netinet/in.h>".}
## Unicast link-local address. ## Unicast link-local address.
proc IN6_IS_ADDR_SITELOCAL* (a1: ptr TIn6_addr): cint {. proc IN6_IS_ADDR_SITELOCAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".} importc, header: "<netinet/in.h>".}
## Unicast site-local address. ## Unicast site-local address.
proc IN6_IS_ADDR_V4MAPPED* (a1: ptr TIn6_addr): cint {. proc IN6_IS_ADDR_V4MAPPED* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".} importc, header: "<netinet/in.h>".}
## IPv4 mapped address. ## IPv4 mapped address.
proc IN6_IS_ADDR_V4COMPAT* (a1: ptr TIn6_addr): cint {. proc IN6_IS_ADDR_V4COMPAT* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".} importc, header: "<netinet/in.h>".}
## IPv4-compatible address. ## IPv4-compatible address.
proc IN6_IS_ADDR_MC_NODELOCAL* (a1: ptr TIn6_addr): cint {. proc IN6_IS_ADDR_MC_NODELOCAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".} importc, header: "<netinet/in.h>".}
## Multicast node-local address. ## Multicast node-local address.
proc IN6_IS_ADDR_MC_LINKLOCAL* (a1: ptr TIn6_addr): cint {. proc IN6_IS_ADDR_MC_LINKLOCAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".} importc, header: "<netinet/in.h>".}
## Multicast link-local address. ## Multicast link-local address.
proc IN6_IS_ADDR_MC_SITELOCAL* (a1: ptr TIn6_addr): cint {. proc IN6_IS_ADDR_MC_SITELOCAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".} importc, header: "<netinet/in.h>".}
## Multicast site-local address. ## Multicast site-local address.
proc IN6_IS_ADDR_MC_ORGLOCAL* (a1: ptr TIn6_addr): cint {. proc IN6_IS_ADDR_MC_ORGLOCAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".} importc, header: "<netinet/in.h>".}
## Multicast organization-local address. ## Multicast organization-local address.
proc IN6_IS_ADDR_MC_GLOBAL* (a1: ptr TIn6_addr): cint {. proc IN6_IS_ADDR_MC_GLOBAL* (a1: ptr TIn6Addr): cint {.
importc, header: "<netinet/in.h>".} importc, header: "<netinet/in.h>".}
## Multicast global address. ## Multicast global address.

View file

@ -262,7 +262,7 @@ else:
else: else:
const iconvDll = "(libc.so.6|libiconv.so)" const iconvDll = "(libc.so.6|libiconv.so)"
when defined(macosx) and defined(powerpc32): when defined(macosx) and defined(powerpc):
const prefix = "lib" const prefix = "lib"
else: else:
const prefix = "" const prefix = ""
@ -281,14 +281,14 @@ else:
var errno {.importc, header: "<errno.h>".}: cint var errno {.importc, header: "<errno.h>".}: cint
proc iconvOpen(tocode, fromcode: cstring): PConverter {. proc iconvOpen(tocode, fromcode: cstring): EncodingConverter {.
importc: prefix & "iconv_open", cdecl, dynlib: iconvDll.} importc: prefix & "iconv_open", cdecl, dynlib: iconvDll.}
proc iconvClose(c: PConverter) {. proc iconvClose(c: EncodingConverter) {.
importc: prefix & "iconv_close", cdecl, dynlib: iconvDll.} importc: prefix & "iconv_close", cdecl, dynlib: iconvDll.}
proc iconv(c: PConverter, inbuf: var cstring, inbytesLeft: var int, proc iconv(c: EncodingConverter, inbuf: var cstring, inbytesLeft: var int,
outbuf: var cstring, outbytesLeft: var int): int {. outbuf: var cstring, outbytesLeft: var int): int {.
importc: prefix & "iconv", cdecl, dynlib: iconvDll.} importc: prefix & "iconv", cdecl, dynlib: iconvDll.}
proc iconv(c: PConverter, inbuf: pointer, inbytesLeft: pointer, proc iconv(c: EncodingConverter, inbuf: pointer, inbytesLeft: pointer,
outbuf: var cstring, outbytesLeft: var int): int {. outbuf: var cstring, outbytesLeft: var int): int {.
importc: prefix & "iconv", cdecl, dynlib: iconvDll.} importc: prefix & "iconv", cdecl, dynlib: iconvDll.}
@ -305,7 +305,7 @@ proc open*(destEncoding = "UTF-8", srcEncoding = "CP1252"): EncodingConverter =
when not defined(windows): when not defined(windows):
result = iconvOpen(destEncoding, srcEncoding) result = iconvOpen(destEncoding, srcEncoding)
if result == nil: if result == nil:
raise newException(EInvalidEncoding, raise newException(EncodingError,
"cannot create encoding converter from " & "cannot create encoding converter from " &
srcEncoding & " to " & destEncoding) srcEncoding & " to " & destEncoding)
else: else:
@ -401,7 +401,7 @@ when defined(windows):
assert(false) # cannot happen assert(false) # cannot happen
else: else:
proc convert*(c: PConverter, s: string): string = proc convert*(c: EncodingConverter, s: string): string =
result = newString(s.len) result = newString(s.len)
var inLen = len(s) var inLen = len(s)
var outLen = len(result) var outLen = len(result)
@ -414,7 +414,7 @@ else:
var lerr = errno var lerr = errno
if lerr == EILSEQ or lerr == EINVAL: if lerr == EILSEQ or lerr == EINVAL:
# unknown char, skip # unknown char, skip
Dst[0] = Src[0] dst[0] = src[0]
src = cast[cstring](cast[int](src) + 1) src = cast[cstring](cast[int](src) + 1)
dst = cast[cstring](cast[int](dst) + 1) dst = cast[cstring](cast[int](dst) + 1)
dec(inLen) dec(inLen)
@ -426,19 +426,19 @@ else:
dst = cast[cstring](cast[int](cstring(result)) + offset) dst = cast[cstring](cast[int](cstring(result)) + offset)
outLen = len(result) - offset outLen = len(result) - offset
else: else:
osError(lerr.TOSErrorCode) raiseOSError(lerr.OSErrorCode)
# iconv has a buffer that needs flushing, specially if the last char is # iconv has a buffer that needs flushing, specially if the last char is
# not '\0' # not '\0'
discard iconv(c, nil, nil, dst, outlen) discard iconv(c, nil, nil, dst, outLen)
if iconvres == cint(-1) and errno == E2BIG: if iconvres == cint(-1) and errno == E2BIG:
var offset = cast[int](dst) - cast[int](cstring(result)) var offset = cast[int](dst) - cast[int](cstring(result))
setLen(result, len(result)+inLen*2+5) setLen(result, len(result)+inLen*2+5)
# 5 is minimally one utf-8 char # 5 is minimally one utf-8 char
dst = cast[cstring](cast[int](cstring(result)) + offset) dst = cast[cstring](cast[int](cstring(result)) + offset)
outLen = len(result) - offset outLen = len(result) - offset
discard iconv(c, nil, nil, dst, outlen) discard iconv(c, nil, nil, dst, outLen)
# trim output buffer # trim output buffer
setLen(result, len(result) - outlen) setLen(result, len(result) - outLen)
proc convert*(s: string, destEncoding = "UTF-8", proc convert*(s: string, destEncoding = "UTF-8",
srcEncoding = "CP1252"): string = srcEncoding = "CP1252"): string =

View file

@ -19,7 +19,7 @@ type
{.deprecated: [EInvalidXml: XmlError].} {.deprecated: [EInvalidXml: XmlError].}
proc raiseInvalidXml(errors: seq[string]) = proc raiseInvalidXml(errors: seq[string]) =
var e: ref EInvalidXml var e: ref XmlError
new(e) new(e)
e.msg = errors[0] e.msg = errors[0]
e.errors = errors e.errors = errors
@ -125,14 +125,14 @@ proc parseXml*(s: Stream): XmlNode =
## errors are turned into an ``EInvalidXML`` exception. ## errors are turned into an ``EInvalidXML`` exception.
var errors: seq[string] = @[] var errors: seq[string] = @[]
result = parseXml(s, "unknown_html_doc", errors) result = parseXml(s, "unknown_html_doc", errors)
if errors.len > 0: raiseInvalidXMl(errors) if errors.len > 0: raiseInvalidXml(errors)
proc loadXml*(path: string, errors: var seq[string]): XmlNode = proc loadXml*(path: string, errors: var seq[string]): XmlNode =
## Loads and parses XML from file specified by ``path``, and returns ## Loads and parses XML from file specified by ``path``, and returns
## a ``PXmlNode``. Every occured parsing error is added to the `errors` ## a ``PXmlNode``. Every occured parsing error is added to the `errors`
## sequence. ## sequence.
var s = newFileStream(path, fmRead) var s = newFileStream(path, fmRead)
if s == nil: raise newException(EIO, "Unable to read file: " & path) if s == nil: raise newException(IOError, "Unable to read file: " & path)
result = parseXml(s, path, errors) result = parseXml(s, path, errors)
proc loadXml*(path: string): XmlNode = proc loadXml*(path: string): XmlNode =
@ -141,7 +141,7 @@ proc loadXml*(path: string): XmlNode =
## exception. ## exception.
var errors: seq[string] = @[] var errors: seq[string] = @[]
result = loadXml(path, errors) result = loadXml(path, errors)
if errors.len > 0: raiseInvalidXMl(errors) if errors.len > 0: raiseInvalidXml(errors)
when isMainModule: when isMainModule:
import os import os

View file

@ -45,7 +45,7 @@ type
PText* = ref Text PText* = ref Text
Text = object of CharacterData Text = object of CharacterData
PComment* = ref comment PComment* = ref Comment
Comment = object of CharacterData Comment = object of CharacterData
PCDataSection* = ref CDataSection PCDataSection* = ref CDataSection

View file

@ -36,7 +36,7 @@ myData.each do (x: int):
type type
ITest = tuple[ ITest = tuple[
setter: proc(v: Int), setter: proc(v: int),
getter: proc(): int] getter: proc(): int]
proc getInterf(): ITest = proc getInterf(): ITest =

View file

@ -38,17 +38,17 @@ template rawInsertImpl() {.dirty.} =
data[h].val = val data[h].val = val
data[h].slot = seFilled data[h].slot = seFilled
template AddImpl() {.dirty.} = template addImpl() {.dirty.} =
if mustRehash(len(t.data), t.counter): Enlarge(t) if mustRehash(len(t.data), t.counter): enlarge(t)
RawInsert(t, t.data, key, val) rawInsert(t, t.data, key, val)
inc(t.counter) inc(t.counter)
template PutImpl() {.dirty.} = template putImpl() {.dirty.} =
var index = RawGet(t, key) var index = rawGet(t, key)
if index >= 0: if index >= 0:
t.data[index].val = val t.data[index].val = val
else: else:
AddImpl() addImpl()
proc len*[A, B](t: TOrderedTable[A, B]): int {.inline.} = proc len*[A, B](t: TOrderedTable[A, B]): int {.inline.} =
## returns the number of keys in `t`. ## returns the number of keys in `t`.
@ -89,7 +89,7 @@ iterator mvalues*[A, B](t: var TOrderedTable[A, B]): var B =
forAllOrderedPairs: forAllOrderedPairs:
yield t.data[h].val yield t.data[h].val
proc RawGet[A, B](t: TOrderedTable[A, B], key: A): int = proc rawGet[A, B](t: TOrderedTable[A, B], key: A): int =
rawGetImpl() rawGetImpl()
proc `[]`*[A, B](t: TOrderedTable[A, B], key: A): B = proc `[]`*[A, B](t: TOrderedTable[A, B], key: A): B =
@ -97,21 +97,21 @@ proc `[]`*[A, B](t: TOrderedTable[A, B], key: A): B =
## default empty value for the type `B` is returned ## default empty value for the type `B` is returned
## and no exception is raised. One can check with ``hasKey`` whether the key ## and no exception is raised. One can check with ``hasKey`` whether the key
## exists. ## exists.
var index = RawGet(t, key) var index = rawGet(t, key)
if index >= 0: result = t.data[index].val if index >= 0: result = t.data[index].val
proc mget*[A, B](t: var TOrderedTable[A, B], key: A): var B = proc mget*[A, B](t: var TOrderedTable[A, B], key: A): var B =
## retrieves the value at ``t[key]``. The value can be modified. ## retrieves the value at ``t[key]``. The value can be modified.
## If `key` is not in `t`, the ``EInvalidKey`` exception is raised. ## If `key` is not in `t`, the ``EInvalidKey`` exception is raised.
var index = RawGet(t, key) var index = rawGet(t, key)
if index >= 0: result = t.data[index].val if index >= 0: result = t.data[index].val
else: raise newException(EInvalidKey, "key not found: " & $key) else: raise newException(KeyError, "key not found: " & $key)
proc hasKey*[A, B](t: TOrderedTable[A, B], key: A): bool = proc hasKey*[A, B](t: TOrderedTable[A, B], key: A): bool =
## returns true iff `key` is in the table `t`. ## returns true iff `key` is in the table `t`.
result = rawGet(t, key) >= 0 result = rawGet(t, key) >= 0
proc RawInsert[A, B](t: var TOrderedTable[A, B], proc rawInsert[A, B](t: var TOrderedTable[A, B],
data: var TOrderedKeyValuePairSeq[A, B], data: var TOrderedKeyValuePairSeq[A, B],
key: A, val: B) = key: A, val: B) =
rawInsertImpl() rawInsertImpl()
@ -120,7 +120,7 @@ proc RawInsert[A, B](t: var TOrderedTable[A, B],
if t.last >= 0: data[t.last].next = h if t.last >= 0: data[t.last].next = h
t.last = h t.last = h
proc Enlarge[A, B](t: var TOrderedTable[A, B]) = proc enlarge[A, B](t: var TOrderedTable[A, B]) =
var n: TOrderedKeyValuePairSeq[A, B] var n: TOrderedKeyValuePairSeq[A, B]
newSeq(n, len(t.data) * growthFactor) newSeq(n, len(t.data) * growthFactor)
var h = t.first var h = t.first
@ -129,7 +129,7 @@ proc Enlarge[A, B](t: var TOrderedTable[A, B]) =
while h >= 0: while h >= 0:
var nxt = t.data[h].next var nxt = t.data[h].next
if t.data[h].slot == seFilled: if t.data[h].slot == seFilled:
RawInsert(t, n, t.data[h].key, t.data[h].val) rawInsert(t, n, t.data[h].key, t.data[h].val)
h = nxt h = nxt
swap(t.data, n) swap(t.data, n)
@ -139,7 +139,7 @@ proc `[]=`*[A, B](t: var TOrderedTable[A, B], key: A, val: B) =
proc add*[A, B](t: var TOrderedTable[A, B], key: A, val: B) = proc add*[A, B](t: var TOrderedTable[A, B], key: A, val: B) =
## puts a new (key, value)-pair into `t` even if ``t[key]`` already exists. ## puts a new (key, value)-pair into `t` even if ``t[key]`` already exists.
AddImpl() addImpl()
proc initOrderedTable*[A, B](initialSize=64): TOrderedTable[A, B] = proc initOrderedTable*[A, B](initialSize=64): TOrderedTable[A, B] =
## creates a new ordered hash table that is empty. `initialSize` needs to be ## creates a new ordered hash table that is empty. `initialSize` needs to be

View file

@ -11,7 +11,7 @@ proc fakeNew[T](x: var ref T, destroy: proc (a: ref T) {.nimcall.}) =
proc destroyDict[TK, TV](a: PDict[TK, TV]) = proc destroyDict[TK, TV](a: PDict[TK, TV]) =
return return
proc newDict[TK, TV](a: TK, b: TV): PDict[TK, TV] = proc newDict[TK, TV](a: TK, b: TV): PDict[TK, TV] =
Fakenew(result, destroyDict[TK, TV]) fakeNew(result, destroyDict[TK, TV])
# Problem: destroyDict is not instantiated when newDict is instantiated! # Problem: destroyDict is not instantiated when newDict is instantiated!

View file

@ -1,7 +1,7 @@
discard """ discard """
line: 2136 line: 2136
file: "system.nim" file: "system.nim"
errormsg: "can raise an unlisted exception: ref EIO" errormsg: "can raise an unlisted exception: ref IOError"
""" """
type type
@ -9,13 +9,13 @@ type
TObjB = object of TObj TObjB = object of TObj
a, b, c: string a, b, c: string
EIO2 = ref object of EIO IO2Error = ref object of IOError
proc forw: int {. .} proc forw: int {. .}
proc lier(): int {.raises: [EIO2].} = proc lier(): int {.raises: [IO2Error].} =
writeln stdout, "arg" writeln stdout, "arg"
proc forw: int = proc forw: int =
raise newException(EIO, "arg") raise newException(IOError, "arg")

View file

@ -1,6 +1,6 @@
discard """ discard """
line: 19 line: 19
errormsg: "can raise an unlisted exception: ref EIO" errormsg: "can raise an unlisted exception: ref IOError"
""" """
type type
@ -8,13 +8,13 @@ type
TObjB = object of TObj TObjB = object of TObj
a, b, c: string a, b, c: string
EIO2 = ref object of EIO EIO2 = ref object of IOError
proc forw: int {.raises: [].} proc forw: int {.raises: [].}
proc lier(): int {.raises: [EIO].} = proc lier(): int {.raises: [IOError].} =
writeln stdout, "arg" writeln stdout, "arg"
proc forw: int = proc forw: int =
raise newException(EIO, "arg") raise newException(IOError, "arg")

View file

@ -2,8 +2,8 @@ discard """
outputsub: "-6" outputsub: "-6"
""" """
type type
ESomething = object of E_Base ESomething = object of Exception
ESomeOtherErr = object of E_Base ESomeOtherErr = object of Exception
proc genErrors(s: string) = proc genErrors(s: string) =
if s == "error!": if s == "error!":

View file

@ -10,8 +10,8 @@ proc test1() =
finally: echo "A" finally: echo "A"
try: try:
raise newException(EOS, "Problem") raise newException(OSError, "Problem")
except EOS: except OSError:
return return
test1() test1()
@ -23,7 +23,7 @@ proc test2() =
try: try:
return return
except EOS: except OSError:
discard discard
test2() test2()
@ -31,8 +31,8 @@ test2()
proc test3() = proc test3() =
try: try:
try: try:
raise newException(EOS, "Problem") raise newException(OSError, "Problem")
except EOS: except OSError:
return return
finally: finally:
echo "C" echo "C"

View file

@ -1,14 +1,14 @@
discard """ discard """
file: "tnestedreturn.nim" file: "tnestedreturn2.nim"
outputsub: "Error: unhandled exception: Problem [EOS]" outputsub: "Error: unhandled exception: Problem [OSError]"
exitcode: "1" exitcode: "1"
""" """
proc test4() = proc test4() =
try: try:
try: try:
raise newException(EOS, "Problem") raise newException(OSError, "Problem")
except EOS: except OSError:
return return
finally: finally:
discard discard
@ -17,4 +17,4 @@ proc test4() =
# but could cause segmentation fault if # but could cause segmentation fault if
# exceptions are not handled properly. # exceptions are not handled properly.
test4() test4()
raise newException(EOS, "Problem") raise newException(OSError, "Problem")

View file

@ -4,8 +4,8 @@ discard """
exitcode: "1" exitcode: "1"
""" """
type type
ESomething = object of E_Base ESomething = object of Exception
ESomeOtherErr = object of E_Base ESomeOtherErr = object of Exception
proc genErrors(s: string) = proc genErrors(s: string) =
if s == "error!": if s == "error!":
@ -13,7 +13,7 @@ proc genErrors(s: string) =
else: else:
raise newException(EsomeotherErr, "bla") raise newException(EsomeotherErr, "bla")
when True: when true:
try: try:
genErrors("errssor!") genErrors("errssor!")
except ESomething: except ESomething:

View file

@ -1,11 +1,11 @@
discard """ discard """
file: "twrongexc.nim" file: "twrongexc.nim"
outputsub: "Error: unhandled exception: [EInvalidValue]" outputsub: "Error: unhandled exception: [ValueError]"
exitcode: "1" exitcode: "1"
""" """
try: try:
raise newException(EInvalidValue, "") raise newException(ValueError, "")
except EOverflow: except OverflowError:
echo("Error caught") echo("Error caught")

View file

@ -3,9 +3,9 @@ discard """
errormsg: "'name' cannot be assigned to" errormsg: "'name' cannot be assigned to"
""" """
Echo("What's your name? ") echo("What's your name? ")
let name = readLine(stdin) let name = readLine(stdin)
while name == "": while name == "":
Echo("Please tell me your name: ") echo("Please tell me your name: ")
name = readLine(stdin) name = readLine(stdin)

View file

@ -1,7 +1,7 @@
import db_sqlite import db_sqlite
var db: TDbConn var db: DbConn
Exec(db, sql"create table blabla()") exec(db, sql"create table blabla()")