mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-10 05:38:10 +00:00
more tests green
This commit is contained in:
@@ -1799,11 +1799,11 @@ proc inet_pton*(a1: cint, a2: cstring, a3: pointer): cint {.
|
||||
importc, header: "<arpa/inet.h>".}
|
||||
|
||||
var
|
||||
in6addr_any* {.importc, header: "<netinet/in.h>".}: TIn6_addr
|
||||
in6addr_loopback* {.importc, header: "<netinet/in.h>".}: TIn6_addr
|
||||
in6addr_any* {.importc, header: "<netinet/in.h>".}: TIn6Addr
|
||||
in6addr_loopback* {.importc, header: "<netinet/in.h>".}: TIn6Addr
|
||||
|
||||
proc IN6ADDR_ANY_INIT* (): TIn6_addr {.importc, header: "<netinet/in.h>".}
|
||||
proc IN6ADDR_LOOPBACK_INIT* (): TIn6_addr {.importc, header: "<netinet/in.h>".}
|
||||
proc IN6ADDR_ANY_INIT* (): TIn6Addr {.importc, header: "<netinet/in.h>".}
|
||||
proc IN6ADDR_LOOPBACK_INIT* (): TIn6Addr {.importc, header: "<netinet/in.h>".}
|
||||
|
||||
# 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_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>".}
|
||||
## 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>".}
|
||||
## 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>".}
|
||||
## 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>".}
|
||||
## 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>".}
|
||||
## 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>".}
|
||||
## 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>".}
|
||||
## 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>".}
|
||||
## 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>".}
|
||||
## 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>".}
|
||||
## 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>".}
|
||||
## 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>".}
|
||||
## Multicast global address.
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ else:
|
||||
else:
|
||||
const iconvDll = "(libc.so.6|libiconv.so)"
|
||||
|
||||
when defined(macosx) and defined(powerpc32):
|
||||
when defined(macosx) and defined(powerpc):
|
||||
const prefix = "lib"
|
||||
else:
|
||||
const prefix = ""
|
||||
@@ -281,14 +281,14 @@ else:
|
||||
|
||||
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.}
|
||||
proc iconvClose(c: PConverter) {.
|
||||
proc iconvClose(c: EncodingConverter) {.
|
||||
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 {.
|
||||
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 {.
|
||||
importc: prefix & "iconv", cdecl, dynlib: iconvDll.}
|
||||
|
||||
@@ -305,7 +305,7 @@ proc open*(destEncoding = "UTF-8", srcEncoding = "CP1252"): EncodingConverter =
|
||||
when not defined(windows):
|
||||
result = iconvOpen(destEncoding, srcEncoding)
|
||||
if result == nil:
|
||||
raise newException(EInvalidEncoding,
|
||||
raise newException(EncodingError,
|
||||
"cannot create encoding converter from " &
|
||||
srcEncoding & " to " & destEncoding)
|
||||
else:
|
||||
@@ -401,7 +401,7 @@ when defined(windows):
|
||||
assert(false) # cannot happen
|
||||
|
||||
else:
|
||||
proc convert*(c: PConverter, s: string): string =
|
||||
proc convert*(c: EncodingConverter, s: string): string =
|
||||
result = newString(s.len)
|
||||
var inLen = len(s)
|
||||
var outLen = len(result)
|
||||
@@ -414,7 +414,7 @@ else:
|
||||
var lerr = errno
|
||||
if lerr == EILSEQ or lerr == EINVAL:
|
||||
# unknown char, skip
|
||||
Dst[0] = Src[0]
|
||||
dst[0] = src[0]
|
||||
src = cast[cstring](cast[int](src) + 1)
|
||||
dst = cast[cstring](cast[int](dst) + 1)
|
||||
dec(inLen)
|
||||
@@ -426,19 +426,19 @@ else:
|
||||
dst = cast[cstring](cast[int](cstring(result)) + offset)
|
||||
outLen = len(result) - offset
|
||||
else:
|
||||
osError(lerr.TOSErrorCode)
|
||||
raiseOSError(lerr.OSErrorCode)
|
||||
# iconv has a buffer that needs flushing, specially if the last char is
|
||||
# not '\0'
|
||||
discard iconv(c, nil, nil, dst, outlen)
|
||||
discard iconv(c, nil, nil, dst, outLen)
|
||||
if iconvres == cint(-1) and errno == E2BIG:
|
||||
var offset = cast[int](dst) - cast[int](cstring(result))
|
||||
setLen(result, len(result)+inLen*2+5)
|
||||
# 5 is minimally one utf-8 char
|
||||
dst = cast[cstring](cast[int](cstring(result)) + offset)
|
||||
outLen = len(result) - offset
|
||||
discard iconv(c, nil, nil, dst, outlen)
|
||||
discard iconv(c, nil, nil, dst, outLen)
|
||||
# trim output buffer
|
||||
setLen(result, len(result) - outlen)
|
||||
setLen(result, len(result) - outLen)
|
||||
|
||||
proc convert*(s: string, destEncoding = "UTF-8",
|
||||
srcEncoding = "CP1252"): string =
|
||||
|
||||
@@ -19,7 +19,7 @@ type
|
||||
{.deprecated: [EInvalidXml: XmlError].}
|
||||
|
||||
proc raiseInvalidXml(errors: seq[string]) =
|
||||
var e: ref EInvalidXml
|
||||
var e: ref XmlError
|
||||
new(e)
|
||||
e.msg = errors[0]
|
||||
e.errors = errors
|
||||
@@ -125,14 +125,14 @@ proc parseXml*(s: Stream): XmlNode =
|
||||
## errors are turned into an ``EInvalidXML`` exception.
|
||||
var errors: seq[string] = @[]
|
||||
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 =
|
||||
## Loads and parses XML from file specified by ``path``, and returns
|
||||
## a ``PXmlNode``. Every occured parsing error is added to the `errors`
|
||||
## sequence.
|
||||
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)
|
||||
|
||||
proc loadXml*(path: string): XmlNode =
|
||||
@@ -141,7 +141,7 @@ proc loadXml*(path: string): XmlNode =
|
||||
## exception.
|
||||
var errors: seq[string] = @[]
|
||||
result = loadXml(path, errors)
|
||||
if errors.len > 0: raiseInvalidXMl(errors)
|
||||
if errors.len > 0: raiseInvalidXml(errors)
|
||||
|
||||
when isMainModule:
|
||||
import os
|
||||
|
||||
@@ -45,7 +45,7 @@ type
|
||||
PText* = ref Text
|
||||
Text = object of CharacterData
|
||||
|
||||
PComment* = ref comment
|
||||
PComment* = ref Comment
|
||||
Comment = object of CharacterData
|
||||
|
||||
PCDataSection* = ref CDataSection
|
||||
|
||||
@@ -36,7 +36,7 @@ myData.each do (x: int):
|
||||
|
||||
type
|
||||
ITest = tuple[
|
||||
setter: proc(v: Int),
|
||||
setter: proc(v: int),
|
||||
getter: proc(): int]
|
||||
|
||||
proc getInterf(): ITest =
|
||||
|
||||
@@ -38,17 +38,17 @@ template rawInsertImpl() {.dirty.} =
|
||||
data[h].val = val
|
||||
data[h].slot = seFilled
|
||||
|
||||
template AddImpl() {.dirty.} =
|
||||
if mustRehash(len(t.data), t.counter): Enlarge(t)
|
||||
RawInsert(t, t.data, key, val)
|
||||
template addImpl() {.dirty.} =
|
||||
if mustRehash(len(t.data), t.counter): enlarge(t)
|
||||
rawInsert(t, t.data, key, val)
|
||||
inc(t.counter)
|
||||
|
||||
template PutImpl() {.dirty.} =
|
||||
var index = RawGet(t, key)
|
||||
template putImpl() {.dirty.} =
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0:
|
||||
t.data[index].val = val
|
||||
else:
|
||||
AddImpl()
|
||||
addImpl()
|
||||
|
||||
proc len*[A, B](t: TOrderedTable[A, B]): int {.inline.} =
|
||||
## returns the number of keys in `t`.
|
||||
@@ -89,7 +89,7 @@ iterator mvalues*[A, B](t: var TOrderedTable[A, B]): var B =
|
||||
forAllOrderedPairs:
|
||||
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()
|
||||
|
||||
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
|
||||
## and no exception is raised. One can check with ``hasKey`` whether the key
|
||||
## exists.
|
||||
var index = RawGet(t, key)
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0: result = t.data[index].val
|
||||
|
||||
proc mget*[A, B](t: var TOrderedTable[A, B], key: A): var B =
|
||||
## retrieves the value at ``t[key]``. The value can be modified.
|
||||
## 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
|
||||
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 =
|
||||
## returns true iff `key` is in the table `t`.
|
||||
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],
|
||||
key: A, val: B) =
|
||||
rawInsertImpl()
|
||||
@@ -120,7 +120,7 @@ proc RawInsert[A, B](t: var TOrderedTable[A, B],
|
||||
if t.last >= 0: data[t.last].next = 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]
|
||||
newSeq(n, len(t.data) * growthFactor)
|
||||
var h = t.first
|
||||
@@ -129,7 +129,7 @@ proc Enlarge[A, B](t: var TOrderedTable[A, B]) =
|
||||
while h >= 0:
|
||||
var nxt = t.data[h].next
|
||||
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
|
||||
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) =
|
||||
## 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] =
|
||||
## creates a new ordered hash table that is empty. `initialSize` needs to be
|
||||
|
||||
@@ -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]) =
|
||||
return
|
||||
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!
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
discard """
|
||||
line: 2136
|
||||
file: "system.nim"
|
||||
errormsg: "can raise an unlisted exception: ref EIO"
|
||||
errormsg: "can raise an unlisted exception: ref IOError"
|
||||
"""
|
||||
|
||||
type
|
||||
@@ -9,13 +9,13 @@ type
|
||||
TObjB = object of TObj
|
||||
a, b, c: string
|
||||
|
||||
EIO2 = ref object of EIO
|
||||
IO2Error = ref object of IOError
|
||||
|
||||
proc forw: int {. .}
|
||||
|
||||
proc lier(): int {.raises: [EIO2].} =
|
||||
proc lier(): int {.raises: [IO2Error].} =
|
||||
writeln stdout, "arg"
|
||||
|
||||
proc forw: int =
|
||||
raise newException(EIO, "arg")
|
||||
raise newException(IOError, "arg")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
discard """
|
||||
line: 19
|
||||
errormsg: "can raise an unlisted exception: ref EIO"
|
||||
errormsg: "can raise an unlisted exception: ref IOError"
|
||||
"""
|
||||
|
||||
type
|
||||
@@ -8,13 +8,13 @@ type
|
||||
TObjB = object of TObj
|
||||
a, b, c: string
|
||||
|
||||
EIO2 = ref object of EIO
|
||||
EIO2 = ref object of IOError
|
||||
|
||||
proc forw: int {.raises: [].}
|
||||
|
||||
proc lier(): int {.raises: [EIO].} =
|
||||
proc lier(): int {.raises: [IOError].} =
|
||||
writeln stdout, "arg"
|
||||
|
||||
proc forw: int =
|
||||
raise newException(EIO, "arg")
|
||||
raise newException(IOError, "arg")
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ discard """
|
||||
outputsub: "-6"
|
||||
"""
|
||||
type
|
||||
ESomething = object of E_Base
|
||||
ESomeOtherErr = object of E_Base
|
||||
ESomething = object of Exception
|
||||
ESomeOtherErr = object of Exception
|
||||
|
||||
proc genErrors(s: string) =
|
||||
if s == "error!":
|
||||
|
||||
@@ -10,8 +10,8 @@ proc test1() =
|
||||
finally: echo "A"
|
||||
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
raise newException(OSError, "Problem")
|
||||
except OSError:
|
||||
return
|
||||
|
||||
test1()
|
||||
@@ -23,7 +23,7 @@ proc test2() =
|
||||
|
||||
try:
|
||||
return
|
||||
except EOS:
|
||||
except OSError:
|
||||
discard
|
||||
|
||||
test2()
|
||||
@@ -31,8 +31,8 @@ test2()
|
||||
proc test3() =
|
||||
try:
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
raise newException(OSError, "Problem")
|
||||
except OSError:
|
||||
return
|
||||
finally:
|
||||
echo "C"
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
discard """
|
||||
file: "tnestedreturn.nim"
|
||||
outputsub: "Error: unhandled exception: Problem [EOS]"
|
||||
file: "tnestedreturn2.nim"
|
||||
outputsub: "Error: unhandled exception: Problem [OSError]"
|
||||
exitcode: "1"
|
||||
"""
|
||||
|
||||
proc test4() =
|
||||
try:
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
raise newException(OSError, "Problem")
|
||||
except OSError:
|
||||
return
|
||||
finally:
|
||||
discard
|
||||
@@ -17,4 +17,4 @@ proc test4() =
|
||||
# but could cause segmentation fault if
|
||||
# exceptions are not handled properly.
|
||||
test4()
|
||||
raise newException(EOS, "Problem")
|
||||
raise newException(OSError, "Problem")
|
||||
|
||||
@@ -4,8 +4,8 @@ discard """
|
||||
exitcode: "1"
|
||||
"""
|
||||
type
|
||||
ESomething = object of E_Base
|
||||
ESomeOtherErr = object of E_Base
|
||||
ESomething = object of Exception
|
||||
ESomeOtherErr = object of Exception
|
||||
|
||||
proc genErrors(s: string) =
|
||||
if s == "error!":
|
||||
@@ -13,7 +13,7 @@ proc genErrors(s: string) =
|
||||
else:
|
||||
raise newException(EsomeotherErr, "bla")
|
||||
|
||||
when True:
|
||||
when true:
|
||||
try:
|
||||
genErrors("errssor!")
|
||||
except ESomething:
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
discard """
|
||||
file: "twrongexc.nim"
|
||||
outputsub: "Error: unhandled exception: [EInvalidValue]"
|
||||
outputsub: "Error: unhandled exception: [ValueError]"
|
||||
exitcode: "1"
|
||||
"""
|
||||
try:
|
||||
raise newException(EInvalidValue, "")
|
||||
except EOverflow:
|
||||
raise newException(ValueError, "")
|
||||
except OverflowError:
|
||||
echo("Error caught")
|
||||
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ discard """
|
||||
errormsg: "'name' cannot be assigned to"
|
||||
"""
|
||||
|
||||
Echo("What's your name? ")
|
||||
echo("What's your name? ")
|
||||
let name = readLine(stdin)
|
||||
while name == "":
|
||||
Echo("Please tell me your name: ")
|
||||
echo("Please tell me your name: ")
|
||||
name = readLine(stdin)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
import db_sqlite
|
||||
|
||||
var db: TDbConn
|
||||
Exec(db, sql"create table blabla()")
|
||||
var db: DbConn
|
||||
exec(db, sql"create table blabla()")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user