summaryrefslogtreecommitdiff
path: root/tests/resolve.test
diff options
context:
space:
mode:
authorLudovic Courtès2009-05-26 18:28:11 +0200
committerLudovic Courtès2009-05-26 18:29:49 +0200
commit9a8581b9b056efed763fb6beff15f9d36cf07ee0 (patch)
treedcd4c129335a5130927029b21d2260d035b2e91a /tests/resolve.test
parentf698471f9de9a5b0f853a014fccba1f2aff1b4dd (diff)
downloadskribilo-9a8581b9b056efed763fb6beff15f9d36cf07ee0.tar.gz
skribilo-9a8581b9b056efed763fb6beff15f9d36cf07ee0.tar.lz
skribilo-9a8581b9b056efed763fb6beff15f9d36cf07ee0.zip
resolve: Clarify node bindings in nested documents.
* src/guile/skribilo/ast.scm (document-bind-nodes!): Bind nodes in the innermost document, which may or may not be the root document. * tests/resolve.test ("root document has no parent", "nested document has a parent", "nested document is its own `ast-document'", "nested document bindings"): New tests.
Diffstat (limited to 'tests/resolve.test')
-rw-r--r--tests/resolve.test49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/resolve.test b/tests/resolve.test
index 0e29614..bfbdd27 100644
--- a/tests/resolve.test
+++ b/tests/resolve.test
@@ -46,6 +46,36 @@
(eq? (ast-parent sec) ch)
(eq? (ast-parent par) sec))))))
+(test-assert "root document has no parent"
+ (let ((doc (document #:title "Doc")))
+ (resolve! doc %engine '())
+ (and (not (ast-parent doc))
+ (eq? doc (ast-document doc)))))
+
+(test-assert "nested document has a parent"
+ ;; Nested documents are sometimes used in the manual.
+ (let* ((doc (document #:title "Doc"
+ (document #:title "Nested Doc"
+ (chapter #:title "C"))))
+ (sub (car (markup-body doc)))
+ (ch (car (markup-body sub))))
+ (resolve! doc %engine '())
+ (and (not (ast-parent doc))
+ (document? sub)
+ (eq? doc (ast-document doc))
+ (eq? doc (ast-parent sub)))))
+
+(test-assert "nested document is its own `ast-document'"
+ (let* ((doc (document #:title "Doc"
+ (document #:title "Nested Doc"
+ (chapter #:title "C"))))
+ (sub (car (markup-body doc)))
+ (ch (car (markup-body sub))))
+ (resolve! doc %engine '())
+ (and (document? sub)
+ (eq? sub (ast-document sub))
+ (eq? sub (ast-document ch)))))
+
(test-assert "unresolved node in body"
(let* ((resolved? #f)
(doc (document #:title "Doc"
@@ -125,6 +155,25 @@
(and (is-markup? (document-lookup-node doc "c") 'chapter)
(is-markup? (document-lookup-node doc "s") 'section))))))
+(test-assert "nested document bindings"
+ ;; Bindings in nested documents are scoped. This was not the case prior
+ ;; to 0.9.2.
+ (let* ((doc (document #:title "Doc"
+ (chapter #:ident "outer")
+ (document #:title "Nested Doc"
+ (chapter #:ident "inner"))))
+ (out (car (markup-body doc)))
+ (sub (cadr (markup-body doc)))
+ (in (car (markup-body sub))))
+ (resolve! doc %engine '())
+ (and (let ((x (document-lookup-node doc "outer")))
+ (and (is-markup? x 'chapter)
+ (eq? (ast-document x) doc)))
+ (not (document-lookup-node doc "inner"))
+ (let ((x (document-lookup-node sub "inner")))
+ (and (is-markup? x 'chapter)
+ (eq? (ast-document x) sub))))))
+
(test-end "resolve")