AtlatestRepositorysigil-lsp
1
(import (sigil test)2
(sigil lsp positions))4
(test-group "line-col->offset"5
(test "line 0 column 0 → offset 0"6
(assert-equal 0 (line-col->offset "hello\nworld" 0 0)))8
(test "line 0 column 3 → offset 3"9
(assert-equal 3 (line-col->offset "hello\nworld" 0 3)))11
(test "line 1 column 0 → offset 6 (past \\n)"12
(assert-equal 6 (line-col->offset "hello\nworld" 1 0)))14
(test "line 1 column 2 → offset 8"15
(assert-equal 8 (line-col->offset "hello\nworld" 1 2))))17
(test-group "word-at-position"18
(test "identifier under cursor"19
(assert-equal "define" (word-at-position "(define x 1)" 0 3)))21
(test "returns #f in leading whitespace"22
(assert-false (word-at-position " (foo)" 0 1)))24
(test "picks the word to the left when in adjacent whitespace"25
;; Editor-style behavior: hovering just past `a` should still resolve to `a`.26
(assert-equal "a" (word-at-position "(a b)" 0 2)))28
(test "identifier on second line"29
(assert-equal "map" (word-at-position "(import (sigil core))\n(map +)" 1 2))))31
(test-group "line/col->position"32
(test "converts 1-based to 0-based"33
(let ((p (line/col->position 3 5)))34
(assert-equal 2 (cdr (assq 'line p)))35
(assert-equal 4 (cdr (assq 'character p)))))37
(test "clamps zero/one at bottom"38
(let ((p (line/col->position 1 1)))39
(assert-equal 0 (cdr (assq 'line p)))40
(assert-equal 0 (cdr (assq 'character p))))))