basex-lsp/position-tests.xqm

64 lines
No EOL
1.8 KiB
Text

xquery version '3.1';
(:~
tests for position test
@author: Andy Bunce
@date: 2025/08/11
:)
module namespace test = 'lsp/test/position';
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)
return unit:assert-equals(count($nl),521)
};
(:~ convert position. :)
declare %unit:test function test:resolvePosition() {
let $text:=unparsed-text("sample.docs/pdfbox.xqm")
let $p:= pos:resolvePosition($text,pos:Position(518,33))
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 %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)
return unit:assert-equals($i,pos:resolvePosition($text,$pos))
};
(:~ convert position. :)
declare %unit:test function test:line() {
let $text:=unparsed-text("sample.docs/pdfbox.xqm")
let $nl:= index-of(string-to-codepoints($text),10)
let $p:= pos:lineAt($nl,18752)=>trace("AA")
return unit:assert-equals($p,518)
};
(:~ convert position. :)
declare %unit:test function test:apply-change() {
let $text:=`11111111,
22222222,
33333333`
let $ch:= {"text":`11111111,
A22222222,
33333333`};
pos:apply-change($text,$ch)