89 lines
2.6 KiB
Text
89 lines
2.6 KiB
Text
(:tests for doci :)
|
|
module namespace test = 'test:doci';
|
|
import module namespace doci = 'urn:quodatum:text: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($doci,$doc,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($doci, $doc, 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($doci,$doc,2)
|
|
|
|
};
|
|
(:~ we can create update from string :)
|
|
declare %unit:test function test:update-start() {
|
|
let $doc:="123456789"
|
|
let $doci:= doci:build($doc)
|
|
let $_:= test:expected($doci,$doc,1)
|
|
|
|
let $change:=test:def-change("*",0,0,0,0)
|
|
let $doci2:=doci:update($doci,$change)
|
|
let $_:= test:expected($doci2,"*" || $doc,1)
|
|
|
|
let $change2:=test:def-change("",0,0,0,1)
|
|
let $update:=doci:update($doci2,$change2)=>trace("b")
|
|
let $_:= doci:text($update)=>trace("test:update1")
|
|
return ()
|
|
};
|
|
|
|
(:~ we can create update from string :)
|
|
declare %unit:test function test:update-end() {
|
|
let $doc:="a
|
|
123456789
|
|
b"
|
|
let $doci:= doci:build($doc)
|
|
let $_:=test:expected($doci,$doc,3)
|
|
let $change:=test:def-change("*",1,9,1,9)
|
|
let $doci2:=doci:update($doci,$change)
|
|
|
|
let $change2:=test:def-change("",1,9,1,10)
|
|
let $update:=doci:update($doci2,$change2)
|
|
return unit:assert-equals($doc,doci:text($update))
|
|
};
|
|
|
|
(: test $doci properties as expected :)
|
|
declare function test:expected($doci as doci:doci, $doc as xs:string, $lines as xs:integer){
|
|
unit:assert-equals(doci:lines($doci),$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()
|
|
};
|
|
|
|
(: create a change description:)
|
|
declare function test:def-change($text as xs:string,
|
|
$sline as xs:integer,$schar as xs:integer,
|
|
$eline as xs:integer,$echar as xs:integer
|
|
)
|
|
as doci:TextDocumentContentChangeEvent{
|
|
doci:TextDocumentContentChangeEvent(
|
|
$text,
|
|
doci:Range(doci:Position($sline,$schar),doci:Position($eline,$echar))
|
|
)
|
|
};
|