AtlatestRepositorysigil-doc
1
(import (sigil test) (sigil string) (sigil doc) (sigil doc print)2
(sigil doc publication) (sigil doc render html) (sigil doc render typst))4
(load "test/fixtures/semantic-structures.sgd")5
(define children (document-children document))6
(define list-node (car children))7
(define table-node (cadr children))8
(define video-node (caddr children))9
(define publication-document (make-publication-document "semantic-structures" document))10
(define publication-index (build-publication-index (list publication-document)))11
(define context12
(make-html-render-context publication-index "semantic-structures" (lambda (target) "#") '() 1))13
(define html (document->html-fragment document context))14
(define print-publication15
(make-print-publication "Semantic Structures" #f '("Course Author") (list publication-document) '()))16
(define typst (print-publication->typst print-publication))17
(define loc (make-srcloc "semantic-test.sgd" 1 1 0 1))18
(define empty-cell (make-table-cell '() loc))19
(define one-cell-row (make-table-row #f (list empty-cell) loc))20
(define linked-video21
(make-video "https://example.com/demo?a=1&b=2" 'url22
(list (make-text "Linked demonstration" loc)) 'link loc))23
(define linked-video-document24
(make-document 'chapter "Linked Video" '() (list linked-video) loc))25
(define linked-video-publication26
(make-publication-document "linked-video" linked-video-document))27
(define linked-video-typst28
(print-publication->typst29
(make-print-publication "Linked Video" #f '()30
(list linked-video-publication) '())))32
(test "semantic list preserves nesting, order, and start"33
(assert-true (item-list? list-node))34
(assert-false (item-list-ordered? list-node))35
(let* ((second (cadr (item-list-items list-node)))36
(nested (cadr (list-item-children second))))37
(assert-true (item-list? nested))38
(assert-true (item-list-ordered? nested))39
(assert-equal 3 (item-list-start nested)))40
(let ((plain (document->plain document)))41
(assert-true (string-contains? plain "3. Nested three"))42
(assert-true (string-contains? plain "4. Nested four"))))44
(test "semantic table preserves header and column shape"45
(assert-true (table? table-node))46
(assert-equal 2 (length (table-columns table-node)))47
(assert-equal 2 (length (table-rows table-node)))48
(assert-true (table-row-header? (car (table-rows table-node))))49
(assert-error (make-table #f '(left right) (list one-cell-row) loc))50
(assert-error (make-table #f '(left)51
(list one-cell-row (make-table-row #t (list empty-cell) loc)) loc)))53
(test "video is semantic and omitted from print by policy"54
(assert-true (video? video-node))55
(assert-equal 'omit (video-print-policy video-node))56
(assert-error (make-video "id" 'unknown #f 'omit loc))57
(assert-false (string-contains? typst "Video:"))58
(assert-true (string-contains? linked-video-typst "Linked demonstration"))59
(assert-true60
(string-contains? linked-video-typst61
"#link(\"https://example.com/demo?a=1&b=2\")")))63
(test "HTML is accessible and Typst uses native structures"64
(assert-true (string-contains? html "<ul>"))65
(assert-true (string-contains? html "<ol start=\"3\">"))66
(assert-true (string-contains? html "<table>"))67
(assert-true (string-contains? html "<thead>"))68
(assert-true (string-contains? html "scope=\"col\""))69
(assert-true (string-contains? html "data-video-source=\"demo-video-id\""))70
(assert-true (string-contains? typst "#list("))71
(assert-true (string-contains? typst "#enum(start: 3"))72
(assert-true (string-contains? typst "table(columns: 2")))