}
proc tclmark::cmd::b content {
node tree [node html <b>] [msubst $content] [node html </b>]
}
proc tclmark::cmd::i content {
node tree [node html <i>] [msubst $content] [node html </i>]
}
proc tclmark::cmd::1 args {
node tree \
[node html <nl>] \
{*}[msubst-and-wrap li $args] \
[node html </nl>] \
}
proc tclmark::cmd::* args {
node tree \
[node html <ol>] \
{*}[msubst-and-wrap li $args] \
[node html </ol>] \
}
proc tclmark::msubst-and-wrap {tag items} {
lmap item $items {
node tree [node html <$tag>] [msubst $item] [node html </$tag>]
}
}
proc tclmark::run-tests {} {
set stats [dict create total 0 passed 0 failed 0]
proc test {name script arrow expected} {
upvar stats stats
dict incr stats total
catch $script result
set matched [switch -- $arrow {
-> { expr {$result eq $expected} }
->* { string match $expected $result }
->$ { regexp -- $expected $result }
default {
return -code error \
-errorcode {JIMLIB TEST BAD-ARROW} \
[list unknown arrow: $arrow]
}
}]
if {!$matched} {
set error {}
append error "\n>>>>> $name failed: [list $script]\n"
append error " got: [list $result]\n"
append error " expected: [list $expected]"
if {$arrow ne {->}} {
append error "\n match: $arrow"
}
dict incr stats failed
puts stderr $error
return
}
dict incr stats passed
}
test basic-1 {
tclmark::render Test
} -> Test
test basic-2 {
tclmark::render {[b Test]}
} -> <b>Test</b>
test basic-3 {
tclmark::render {[i {Hello, world!}]}
} -> {<i>Hello, world!</i>}
test basic-4 {
tclmark::render {[b [i Test]]}
} -> <b><i>Test</i></b>
test basic-5 {
tclmark::render {[b {[i Test]}]}
} -> <b><i>Test</i></b>
test basic-6 {
tclmark::render {[}
} -> \[
test html-1 {
tclmark::render {<b><i>Test</i></b>}
} -> {<b><i>Test</i></b>}
test html-2 {
tclmark::render {[b <script>alert('Hello!')</script>]}
} -> {<b><script>alert('Hello!')</script></b>}
test list-1 {
tclmark::render {[* first second third]}
} -> {<ol><li>first</li><li>second</li><li>third</li></ol>}
test list-2 {
tclmark::render {[1 first second third]}
} -> {<nl><li>first</li><li>second</li><li>third</li></nl>}
puts stderr $stats
return [expr {[dict get $stats failed] > 0}]