AtlatestRepositorysigil-lsp

sigil-lsp / tree / testtest-documents.sgl

1(import (sigil test)
2 (sigil lsp documents))
3
4(test-group "doc-store"
5 (test "open and retrieve a document"
6 (let* ((store (doc-store))
7 (d (doc-store-open! store "file:///tmp/a.sgl" "sigil" 1 "hello")))
8 (assert-equal "hello" (document-text (doc-store-get store "file:///tmp/a.sgl")))
9 (assert-equal 1 (document-version (doc-store-get store "file:///tmp/a.sgl")))))
11 (test "update replaces text and bumps version"
12 (let ((store (doc-store)))
13 (doc-store-open! store "file:///tmp/b.sgl" "sigil" 1 "one")
14 (doc-store-update! store "file:///tmp/b.sgl" 2 "two")
15 (assert-equal "two" (document-text (doc-store-get store "file:///tmp/b.sgl")))
16 (assert-equal 2 (document-version (doc-store-get store "file:///tmp/b.sgl")))))
18 (test "close removes the document"
19 (let ((store (doc-store)))
20 (doc-store-open! store "file:///tmp/c.sgl" "sigil" 1 "x")
21 (doc-store-close! store "file:///tmp/c.sgl")
22 (assert-false (doc-store-get store "file:///tmp/c.sgl")))))
24(test-group "uri <-> path"
25 (test "file uri roundtrip on simple path"
26 (assert-equal "file:///tmp/foo.sgl"
27 (path->uri (uri->path "file:///tmp/foo.sgl"))))
29 (test "uri->path decodes percent-encoded spaces"
30 (assert-equal "/tmp/my file.sgl"
31 (uri->path "file:///tmp/my%20file.sgl")))
33 (test "path->uri encodes spaces"
34 (assert-equal "file:///tmp/my%20file.sgl"
35 (path->uri "/tmp/my file.sgl"))))