use doAssert in tests (#16486)
This commit is contained in:
parent
f9a15dbae9
commit
6d442a40a6
78 changed files with 1056 additions and 1056 deletions
|
|
@ -55,8 +55,8 @@ block t88:
|
|||
|
||||
let c = ChildClass[string].new("Base", "Child")
|
||||
|
||||
assert c.baseMethod == "Base"
|
||||
assert c.overriddenMethod == "Child"
|
||||
doAssert c.baseMethod == "Base"
|
||||
doAssert c.overriddenMethod == "Child"
|
||||
|
||||
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ block t1789:
|
|||
bar: array[N, T]
|
||||
|
||||
proc `[]`[N, T](f: Bar[N, T], n: range[0..(N - 1)]): T =
|
||||
assert high(n) == N-1
|
||||
doAssert high(n) == N-1
|
||||
result = f.bar[n]
|
||||
|
||||
var b: Bar[3, int]
|
||||
|
|
@ -734,7 +734,7 @@ block t1684:
|
|||
proc newDerived(idx: int): DerivedType {.inline.} = DerivedType(idx: idx)
|
||||
|
||||
let d = newDerived(2)
|
||||
assert(d.index == 2)
|
||||
doAssert(d.index == 2)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -58,23 +58,23 @@ block tgenericdefaults:
|
|||
var x1: TFoo[int, float]
|
||||
|
||||
static:
|
||||
assert type(x1.x) is int
|
||||
assert type(x1.y) is float
|
||||
assert type(x1.z) is int
|
||||
doAssert type(x1.x) is int
|
||||
doAssert type(x1.y) is float
|
||||
doAssert type(x1.z) is int
|
||||
|
||||
var x2: TFoo[string, R = float, U = seq[int]]
|
||||
|
||||
static:
|
||||
assert type(x2.x) is string
|
||||
assert type(x2.y) is seq[int]
|
||||
assert type(x2.z) is float
|
||||
doAssert type(x2.x) is string
|
||||
doAssert type(x2.y) is seq[int]
|
||||
doAssert type(x2.z) is float
|
||||
|
||||
var x3: TBar[float]
|
||||
|
||||
static:
|
||||
assert type(x3.x) is float
|
||||
assert type(x3.y) is array[4, float]
|
||||
assert type(x3.z) is float
|
||||
doAssert type(x3.x) is float
|
||||
doAssert type(x3.y) is array[4, float]
|
||||
doAssert type(x3.z) is float
|
||||
|
||||
|
||||
|
||||
|
|
@ -150,31 +150,31 @@ block tsharedcases:
|
|||
doAssert high(f2.data2) == 3 # int8.len - 1 == 3
|
||||
|
||||
static:
|
||||
assert high(f1.data1) == ord(C)
|
||||
assert high(f1.data2) == 5 # length of MyEnum minus one, because we used T.high
|
||||
doAssert high(f1.data1) == ord(C)
|
||||
doAssert high(f1.data2) == 5 # length of MyEnum minus one, because we used T.high
|
||||
|
||||
assert high(f2.data1) == 126
|
||||
assert high(f2.data2) == 3
|
||||
doAssert high(f2.data1) == 126
|
||||
doAssert high(f2.data2) == 3
|
||||
|
||||
assert high(f1.data3) == 6 # length of MyEnum
|
||||
assert high(f2.data3) == 4 # length of int8
|
||||
doAssert high(f1.data3) == 6 # length of MyEnum
|
||||
doAssert high(f2.data3) == 4 # length of int8
|
||||
|
||||
assert f2.data3[0] is float
|
||||
doAssert f2.data3[0] is float
|
||||
|
||||
|
||||
|
||||
block tmap_auto:
|
||||
let x = map(@[1, 2, 3], x => x+10)
|
||||
assert x == @[11, 12, 13]
|
||||
doAssert x == @[11, 12, 13]
|
||||
|
||||
let y = map(@[(1,"a"), (2,"b"), (3,"c")], x => $x[0] & x[1])
|
||||
assert y == @["1a", "2b", "3c"]
|
||||
doAssert y == @["1a", "2b", "3c"]
|
||||
|
||||
proc eatsTwoArgProc[T,S,U](a: T, b: S, f: proc(t: T, s: S): U): U =
|
||||
f(a,b)
|
||||
|
||||
let z = eatsTwoArgProc(1, "a", (t,s) => $t & s)
|
||||
assert z == "1a"
|
||||
doAssert z == "1a"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ proc literal*[N, T, P](pattern: P, kind: N): Rule[N, T] =
|
|||
let parser = proc (text: T, start: int, nodes: var seq[Node[N]]): int =
|
||||
if start == len(text):
|
||||
return -1
|
||||
assert(len(text)>start, "Attempting to match at $#, string length is $# " % [$start, $len(text)])
|
||||
doAssert(len(text)>start, "Attempting to match at $#, string length is $# " % [$start, $len(text)])
|
||||
when P is string or P is seq[N]:
|
||||
debug(debugLex, "Literal[" & $kind & "]: testing " & $pattern & " at " & $start & ": " & $text[start..start+len(pattern)-1])
|
||||
if text.continuesWith(pattern, start):
|
||||
|
|
@ -177,7 +177,7 @@ proc token[N, T](pattern: T, kind: N): Rule[N, T] =
|
|||
debug(debugLex, "Token[" & $kind & "]: testing " & pattern & " at " & $start)
|
||||
if start == len(text):
|
||||
return -1
|
||||
assert(len(text)>start, "Attempting to match at $#, string length is $# " % [$start, $len(text)])
|
||||
doAssert(len(text)>start, "Attempting to match at $#, string length is $# " % [$start, $len(text)])
|
||||
let m = text.match(re(pattern), start)
|
||||
if m.isSome:
|
||||
let node = initNode(start, len(m.get.match), kind)
|
||||
|
|
@ -192,7 +192,7 @@ proc chartest[N, T, S](testfunc: proc(s: S): bool, kind: N): Rule[N, T] =
|
|||
let parser = proc (text: T, start: int, nodes: var seq[Node[N]]): int =
|
||||
if start == len(text):
|
||||
return -1
|
||||
assert(len(text)>start, "Attempting to match at $#, string length is $# " % [$start, $len(text)])
|
||||
doAssert(len(text)>start, "Attempting to match at $#, string length is $# " % [$start, $len(text)])
|
||||
if testfunc(text[start]):
|
||||
nodes.add(initNode(start, 1, kind))
|
||||
result = 1
|
||||
|
|
@ -252,11 +252,11 @@ proc fail*[N, T](message: string, kind: N): Rule[N, T] =
|
|||
proc `+`*[N, T](left: Rule[N, T], right: Rule[N, T]): Rule[N, T] =
|
||||
let parser = proc (text: T, start: int, nodes: var seq[Node[N]]): int =
|
||||
var mynodes = newSeq[Node[N]]()
|
||||
assert(not isNil(left.parser), "Left hand side parser is nil")
|
||||
doAssert(not isNil(left.parser), "Left hand side parser is nil")
|
||||
let leftlength = left.parser(text, start, mynodes)
|
||||
if leftlength == -1:
|
||||
return leftlength
|
||||
assert(not isNil(right.parser), "Right hand side parser is nil")
|
||||
doAssert(not isNil(right.parser), "Right hand side parser is nil")
|
||||
let rightlength = right.parser(text, start+leftlength, mynodes)
|
||||
if rightlength == -1:
|
||||
return rightlength
|
||||
|
|
@ -267,13 +267,13 @@ proc `+`*[N, T](left: Rule[N, T], right: Rule[N, T]): Rule[N, T] =
|
|||
proc `/`*[N, T](left: Rule[N, T], right: Rule[N, T]): Rule[N, T] =
|
||||
let parser = proc (text: T, start: int, nodes: var seq[Node[N]]): int =
|
||||
var mynodes = newSeq[Node[N]]()
|
||||
assert(not isNil(left.parser), "Left hand side of / is not fully defined")
|
||||
doAssert(not isNil(left.parser), "Left hand side of / is not fully defined")
|
||||
let leftlength = left.parser(text, start, mynodes)
|
||||
if leftlength != -1:
|
||||
nodes.add(mynodes)
|
||||
return leftlength
|
||||
mynodes = newSeq[Node[N]]()
|
||||
assert(not isNil(right.parser), "Right hand side of / is not fully defined")
|
||||
doAssert(not isNil(right.parser), "Right hand side of / is not fully defined")
|
||||
let rightlength = right.parser(text, start, mynodes)
|
||||
if rightlength == -1:
|
||||
return rightlength
|
||||
|
|
@ -360,7 +360,7 @@ proc `/`*[N, T](rule: Rule[N, T]): Rule[N, T] =
|
|||
result = newRule[N, T](parser, rule.kind)
|
||||
|
||||
proc `->`*(rule: Rule, production: Rule) =
|
||||
assert(not isnil(production.parser), "Right hand side of -> is nil - has the rule been defined yet?")
|
||||
doAssert(not isnil(production.parser), "Right hand side of -> is nil - has the rule been defined yet?")
|
||||
rule.parser = production.parser
|
||||
|
||||
template grammar*[K](Kind, Text, Symbol: typedesc; default: K, code: untyped): typed {.hint[XDeclaredButNotUsed]: off.} =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue