AtlatestRepositorysigil-markdown
sigil-markdown / tree / benchcheck.sgl
1
;;; Correctness gate for (sigil markdown).2
;;;3
;;; Usage: sigil bench/check.sgl4
;;;5
;;; For each corpus doc, serializes (markdown->sxml text) with ~s and6
;;; compares to a golden snapshot under bench/golden/. On first run (no7
;;; golden) it WRITES the golden; on later runs it VERIFIES byte-identity.8
;;; Prints PASS/FAIL per doc and a summary. This is the byte-identical9
;;; render-output gate: goldens are generated from the baseline parser and10
;;; must remain unchanged across the optimization.12
(import (sigil markdown)13
(sigil fs)14
(sigil io)15
(sigil string))17
(define corpus18
(list "mixed" "inline-edge" "elements" "emphasis-edge" "code-link-edge"19
"block-edge"))21
(ensure-directory "bench/golden")23
(define (check name)24
(let* ((src (read-file-string (string-append "bench/corpus/" name ".md")))25
(sxml (markdown->sxml src))26
(repr (format "~s" sxml))27
(golden-path (string-append "bench/golden/" name ".sxml")))28
(if (file-exists? golden-path)29
(let ((golden (read-file-string golden-path)))30
(if (string=? repr golden)31
(begin (println "PASS ~a" name) #t)32
(begin33
(println "FAIL ~a (len new=~a golden=~a)"34
name (string-length repr) (string-length golden))35
(write-file-string (string-append golden-path ".actual") repr)36
#f)))37
(begin38
(write-file-string golden-path repr)39
(println "WROTE ~a (~a bytes)" name (string-length repr))40
#t))))42
(let loop ((names corpus) (ok #t))43
(if (null? names)44
(begin45
(println "----")46
(println (if ok "ALL PASS" "SOME FAILED")))47
(loop (cdr names) (and (check (car names)) ok))))