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

@ -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

View file

@ -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 =

View file

@ -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

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]) =
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!

View file

@ -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")

View file

@ -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")

View file

@ -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!":

View file

@ -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"

View file

@ -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")

View file

@ -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:

View file

@ -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")

View file

@ -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)

View file

@ -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()")