make more tests green
This commit is contained in:
parent
dae5450947
commit
7f49364fd0
16 changed files with 39 additions and 102 deletions
|
|
@ -267,7 +267,7 @@ proc `[]`*(pattern: Captures, i: int): string =
|
|||
let bounds = bounds.get
|
||||
return pattern.str.substr(bounds.a, bounds.b)
|
||||
else:
|
||||
return nil
|
||||
return ""
|
||||
|
||||
proc match*(pattern: RegexMatch): string =
|
||||
return pattern.captures[-1]
|
||||
|
|
@ -291,9 +291,9 @@ template toTableImpl(cond: untyped) {.dirty.} =
|
|||
else:
|
||||
result[key] = nextVal
|
||||
|
||||
proc toTable*(pattern: Captures, default: string = nil): Table[string, string] =
|
||||
proc toTable*(pattern: Captures, default: string = ""): Table[string, string] =
|
||||
result = initTable[string, string]()
|
||||
toTableImpl(nextVal == nil)
|
||||
toTableImpl(nextVal.len == 0)
|
||||
|
||||
proc toTable*(pattern: CaptureBounds, default = none(HSlice[int, int])):
|
||||
Table[string, Option[HSlice[int, int]]] =
|
||||
|
|
@ -312,13 +312,13 @@ template itemsImpl(cond: untyped) {.dirty.} =
|
|||
iterator items*(pattern: CaptureBounds, default = none(HSlice[int, int])): Option[HSlice[int, int]] =
|
||||
itemsImpl(nextVal.isNone)
|
||||
|
||||
iterator items*(pattern: Captures, default: string = nil): string =
|
||||
itemsImpl(nextVal == nil)
|
||||
iterator items*(pattern: Captures, default: string = ""): string =
|
||||
itemsImpl(nextVal.len == 0)
|
||||
|
||||
proc toSeq*(pattern: CaptureBounds, default = none(HSlice[int, int])): seq[Option[HSlice[int, int]]] =
|
||||
accumulateResult(pattern.items(default))
|
||||
|
||||
proc toSeq*(pattern: Captures, default: string = nil): seq[string] =
|
||||
proc toSeq*(pattern: Captures, default: string = ""): seq[string] =
|
||||
accumulateResult(pattern.items(default))
|
||||
|
||||
proc `$`*(pattern: RegexMatch): string =
|
||||
|
|
|
|||
|
|
@ -10,11 +10,7 @@ proc fget*[K, V](self: Table[K, V], key: K): V =
|
|||
const Ident = {'a'..'z', 'A'..'Z', '0'..'9', '_', '\128'..'\255'}
|
||||
const StartIdent = Ident - {'0'..'9'}
|
||||
|
||||
proc checkNil(arg: string): string =
|
||||
if arg == nil:
|
||||
raise newException(ValueError, "Cannot use nil capture")
|
||||
else:
|
||||
return arg
|
||||
template checkNil(arg: string): string = arg
|
||||
|
||||
template formatStr*(howExpr, namegetter, idgetter): untyped =
|
||||
let how = howExpr
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue