|
1
|
package require rl_json |
|
2
|
package require tdom |
|
3
|
|
|
4
|
set f [open "commonmark_tests.json"] |
|
5
|
fconfigure $f -encoding utf-8 |
|
6
|
set data [read $f] |
|
7
|
close $f |
|
8
|
|
|
9
|
set tests [rl_json::json parse $data] |
|
10
|
|
|
11
|
proc normalize {html} { |
|
12
|
if {![catch {[[dom parse -html "<html>$html</html>"] documentElement] asHTML} res]} { |
|
13
|
return [string range $res 6 end-7] |
|
14
|
} else { |
|
15
|
return $html |
|
16
|
} |
|
17
|
} |
|
18
|
|
|
19
|
set errored 0 |
|
20
|
set failed 0 |
|
21
|
set passed 0 |
|
22
|
foreach test $tests { |
|
23
|
dict with test { |
|
24
|
puts --------------- |
|
25
|
puts -nonewline "Test: $example" |
|
26
|
set f [open "in.md" w+] |
|
27
|
fconfigure $f -encoding utf-8 |
|
28
|
puts $f [subst -nocommands -novariable $markdown]\n |
|
29
|
close $f |
|
30
|
set expected [normalize [subst -nocommands -novariables [string trim $html]]] |
|
31
|
if {[catch { |
|
32
|
set data [exec ../fossil test-markdown-render in.md] |
|
33
|
|
|
34
|
# remove pre/post amble |
|
35
|
set data [split $data \n] |
|
36
|
set data [lrange $data 1 end-2] |
|
37
|
set result [normalize [string trim [join $data \n]]] |
|
38
|
} err]} { |
|
39
|
incr errored |
|
40
|
set result "crashed" |
|
41
|
puts stderr $err |
|
42
|
puts "crashed" |
|
43
|
} elseif {$result ne $expected} { |
|
44
|
incr failed |
|
45
|
puts " failed, -: expected, +: actual:" |
|
46
|
foreach line [split $expected \n] { puts "-:$line" } |
|
47
|
foreach line [split $result \n] { puts "+:$line" } |
|
48
|
} else { |
|
49
|
incr passed |
|
50
|
puts " passed" |
|
51
|
foreach line [split $expected \n] { puts "-:$line" } |
|
52
|
foreach line [split $result \n] { puts "+:$line" } |
|
53
|
} |
|
54
|
} |
|
55
|
} |
|
56
|
|
|
57
|
puts "Passed: $passed, failed: $failed, errored: $errored" |
|
58
|
file delete in.md |
|
59
|
|