[fix] tests
This commit is contained in:
parent
bebbf38686
commit
23fc83f295
3 changed files with 33 additions and 24 deletions
18
src/doci.xqm
18
src/doci.xqm
|
|
@ -97,23 +97,29 @@ return if(empty($change?range))
|
|||
|
||||
(: string from start line before insert :)
|
||||
let $head:= substring( $doci?lines[$sline+1] ,1, $range?start?character )
|
||||
=>trace("$head")
|
||||
|
||||
(: string from edit end to end of line :)
|
||||
let $head:= substring( $doci?lines[$sline+1] ,1, $range?start?character )
|
||||
let $last := substring( $doci?lines[$eline+1] , $range?end?character +1)
|
||||
=>trace("$last")
|
||||
|
||||
let $ulines := (
|
||||
subsequence($doci?lines, 1, $sline) (: lines before edit :)
|
||||
=>trace("before")
|
||||
,
|
||||
if($sline eq $eline)
|
||||
then ($head || $lines[1] || $last)
|
||||
|
||||
else (
|
||||
$head || $lines[1],
|
||||
subsequence( $lines,2, count( $lines - 2)),
|
||||
$lines[last()] ||$last
|
||||
),
|
||||
else if(1=count($lines))
|
||||
then $head || $lines[1] || $last
|
||||
else (
|
||||
$head || $lines[1],
|
||||
subsequence( $lines,2, count( $lines - 2)),
|
||||
$lines[last()] ||$last
|
||||
),
|
||||
|
||||
subsequence($doci?lines, $eline+2) (: lines after edit :)
|
||||
=>trace("after")
|
||||
)
|
||||
return doci:doci($ulines,$doci?separator)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ declare %unit:test function test:update-start() {
|
|||
return ()
|
||||
};
|
||||
|
||||
(:~ we can create update from string :)
|
||||
(:~ we can update the end of a line :)
|
||||
declare %unit:test function test:update-end() {
|
||||
let $doc:="a
|
||||
123456789
|
||||
|
|
@ -57,6 +57,19 @@ b"
|
|||
return unit:assert-equals($doc,doci:text($update))
|
||||
};
|
||||
|
||||
(:~ we can update to remove a line :)
|
||||
declare %unit:test function test:update-lines() {
|
||||
let $doc:="a
|
||||
123456789
|
||||
b"
|
||||
let $doci:= doci:build($doc)
|
||||
let $_:=test:expected($doci,$doc,3)
|
||||
let $change:=test:def-change("",0,1,2,0)
|
||||
let $doci2:=doci:update($doci,$change)
|
||||
let $_:=test:expected($doci2,"ab",1)
|
||||
return true()
|
||||
};
|
||||
|
||||
(: 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),
|
||||
|
|
|
|||
|
|
@ -1,22 +1,12 @@
|
|||
import module namespace doci = 'urn:quodatum:text:doci' at "../src/doci.xqm";
|
||||
import module namespace test = 'test:doci' at "simple.xqm";
|
||||
|
||||
declare variable $long:=
|
||||
file:read-text("C:\Users\mrwhe\git\quodatum\basex-lsp\test\sample.docs\pdfbox.xqm");
|
||||
declare variable $text:="123456789";
|
||||
|
||||
(: create a change description:)
|
||||
declare function local: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))
|
||||
)
|
||||
};
|
||||
let $doc:="a
|
||||
123456789
|
||||
b"
|
||||
|
||||
|
||||
|
||||
doci:build($text)
|
||||
=>doci:update(local:change("*",0,0,0,0))
|
||||
return doci:build($doc)
|
||||
=>doci:update(test:def-change("",0,1,2,0))
|
||||
Loading…
Add table
Reference in a new issue