(:tests for doci :) module namespace test = 'test:doci'; import module namespace doci = 'urn:doci' at "../src/doci.xqm"; (:~ we can create record from file :) declare %unit:test function test:from-file() { let $doc:=test:read("resources/doc1.txt") let $doci:= doci:build($doc) return test:expected($doc,$doci,530) }; (:~ we can create record from string :) declare %unit:test function test:from-string1() { let $doc:="a one line string" let $doci:= doci:build($doc) return test:expected($doc,$doci,1) }; (:~ we can create record from string :) declare %unit:test function test:from-string2() { let $doc:="a two line string second line" let $doci:= doci:build($doc) return test:expected($doc,$doci,2) }; (:~ we can create record from string :) declare %unit:test function test:update1() { let $doc:="123456789" let $doci:= doci:build($doc) let $change:=doci:TextDocumentContentChangeEvent( "*", doci:Range(doci:Position(0,0),doci:Position(0,0)) ) let $doci2:=doci:change($doci,$change)=>trace("A") let $change2:=doci:TextDocumentContentChangeEvent( "", doci:Range(doci:Position(0,0),doci:Position(0,1)) ) let $update:=doci:change($doci2,$change2)=>trace("b") return () }; (: test $doci properties as expected :) declare function test:expected($doc as xs:string, $doci as doci:doci, $lines as xs:integer){ unit:assert-equals($doci?lines=>count(),$lines), unit:assert($doci?separator!string-length(.)>0), unit:assert-equals($doc,doci:text($doci)) }; (:~ we can create record. :) declare %unit:test function test:lines() { test:read("resources/doc1.txt")!doci:build(.)?lines=>count() }; (:~ utils :) declare function test:read($path as xs:string) as xs:string{ file:resolve-path($path,file:base-dir())=>file:read-text() };