[fix] positions

This commit is contained in:
Andy Bunce 2025-08-19 12:43:04 +01:00
parent 1483a807f4
commit 77bc1e524c
5 changed files with 40 additions and 23 deletions

View file

@ -12,7 +12,7 @@ import module namespace pos="lsp/position" at "../webapp/lsp/position.xqm";
(:~ count lines. :)
declare %unit:test function test:line-count() {
let $text:=unparsed-text("sample.docs/pdfbox.xqm")
let $nl:= index-of(string-to-codepoints($text),10)=>trace("SSS ")
let $nl:= index-of(string-to-codepoints($text),10)
return unit:assert-equals(count($nl),521)
};
@ -23,8 +23,21 @@ declare %unit:test function test:resolvePosition() {
return unit:assert-equals($p,18751)
};
(:~ convert position. :)
declare %unit:test("expected", "pos:range")
function test:toPosition() {
let $text:="1+2 a"
return pos:toPosition($text,5)
};
(:~ convert position. :)
declare %unit:test
function test:toPosition2() {
let $text:="1+2 a"
return unit:assert-equals(pos:toPosition($text,4),{"line":0,"character":4})
};
(:~ convert all position. :)
declare %unit:test function test:toPosition() {
declare %unit:test %unit:ignore function test:toPositionAll() {
let $text:=unparsed-text("sample.docs/pdfbox.xqm")
return for $i in 0 to string-length($text)-1
let $pos:=pos:toPosition($text,$i)

View file

@ -1,7 +1,5 @@
import module namespace pos="lsp/position" at "../webapp/lsp/position.xqm";
let $text:=unparsed-text("sample.docs/pdfbox.xqm")
let $nl:= index-of(string-to-codepoints($text),10)
let $text:="1+2 a"
return (
pos:toPosition($text,10744),pos:toPosition($text,10745)
)
return pos:toPosition($text,5)