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