@@ 125,12 125,15 @@ proc newDbm*[T: DBM](path: string; rw: RW; options: set[OpenOption] = {}): T =
result = construct[T]()
result.Open(path, rw == writeable, opts)
+proc newDbm*[T: MemoryDBM](): T =
+ construct[T]()
+
template declareNewFile(T: untyped): untyped =
proc `new T`*(path: string; rw: RW; options: set[OpenOption] = {}): T =
newDBM[T](path, rw, options)
template declareNewMem(T: untyped): untyped =
- proc `new T`*(): T = construct[T]()
+ proc `new T`*(): T = newDBM[T]()
declareNewFile(HashDBM)
declareNewFile(TreeDBM)
@@ 2,14 2,14 @@ import std/[os, unittest]
import tkrzw
-template testEx1(newProc: untyped; isFile: static[bool]): untyped =
+template testEx1(T: untyped; isFile: static[bool]): untyped =
test "ex1":
const path = "casket.test"
- when isFile:
- var dbm = newProc(path, writeable, {ooTruncate})
- # newHashDBM(…), etc
- else:
- var dbm = newProc()
+ var dbm =
+ when isFile:
+ newDbm[T](path, writeable, {ooTruncate})
+ else:
+ newDbm[T]()
dbm["foo"] = "hop"
dbm["bar"] = "step"
@@ 34,19 34,19 @@ template testEx1(newProc: untyped; isFile: static[bool]): untyped =
removeFile(path)
suite "HashDBM":
- testEx1(newHashDBM, true)
+ testEx1(HashDBM, true)
suite "TreeDBM":
- testEx1(newTreeDBM, true)
+ testEx1(TreeDBM, true)
suite "SkipDBM":
- testEx1(newSkipDBM, true)
+ testEx1(SkipDBM, true)
suite "TinyDBM":
- testEx1(newTinyDBM, false)
+ testEx1(TinyDBM, false)
suite "BabyDBM":
- testEx1(newBabyDBM, false)
+ testEx1(BabyDBM, false)
suite "CacheDBM":
- testEx1(newCacheDBM, false)
+ testEx1(CacheDBM, false)