add html example

This commit is contained in:
Antonis Geralis 2022-09-05 12:34:27 +03:00
parent 79d70f6235
commit 1363f2b32a
3 changed files with 62 additions and 2 deletions

View File

@ -69,7 +69,6 @@ proc mutate[M, N: static[int]](value: var Matrix32[M, N]; sizeIncreaseHint: int;
repeatMutate(mutateMatrix32(move value, r))
func fuzzTarget(x: Matrix32[2, 1]) =
let data = ones(2, 1)
doAssert x != data
doAssert x != ones(2, 1)
defaultMutator(fuzzTarget)

60
tests/trefs2.nim Normal file
View File

@ -0,0 +1,60 @@
# Example excerpt from the "Mastering Nim" book
type
Tag = enum
text, html, head, body, table, tr, th, td
TagWithKids = range[html..high(Tag)]
HtmlNode = ref object
case tag: Tag
of text: s: string
else: kids: seq[HtmlNode]
proc newTextNode(s: sink string): HtmlNode =
HtmlNode(tag: text, s: s)
proc newTree(tag: TagWithKids; kids: varargs[HtmlNode]): HtmlNode =
HtmlNode(tag: tag, kids: @kids)
proc add(parent: HtmlNode; kid: sink HtmlNode) = parent.kids.add kid
from std/xmltree import addEscaped
proc toString(n: HtmlNode; result: var string) =
if n.isNil: return
case n.tag
of text:
result.addEscaped n.s
else:
result.add "<" & $n.tag
if n.kids.len == 0:
result.add " />"
else:
result.add ">\n"
for k in items(n.kids): toString(k, result)
result.add "\n</" & $n.tag & ">"
proc `$`(n: HtmlNode): string =
result = newStringOfCap(1000)
toString n, result
import drchaos
func `==`(a, b: HtmlNode): bool =
if a.isNil:
if b.isNil: return true
return false
elif b.isNil or a.tag != b.tag:
return false
else:
case a.tag
of text: return a.s == b.s
else: return a.kids == b.kids
func fuzzTarget(x: HtmlNode) =
if x.isNil: return
let data = HtmlNode(tag: head, kids: @[
HtmlNode(tag: text, s: "mychild"),
HtmlNode(tag: body)
])
doAssert $x != $data
defaultMutator(fuzzTarget)

1
tests/trefs2.nims Normal file
View File

@ -0,0 +1 @@
--define: fuzzerUtf8Strings