fennel-ls/test/string-processing-test.fnl
2023-07-07 13:40:12 -05:00

61 lines
1.6 KiB
Fennel

(import-macros {: is-matching : describe : it} :test)
(local is (require :test.is))
(local fennel (require :fennel))
(local utils (require :fennel-ls.utils))
(describe "utils"
;; fixme:
;; test for errors on out of bounds
;; test for multiline edits
;; test for unicode utf8 utf16 nightmare
(describe "apply-changes"
(fn range [start-line start-col end-line end-col]
{:start {:line start-line :character start-col}
:end {:line end-line :character end-col}})
(it "updates the start of a line"
(is.equal
(utils.apply-changes
"replace beginning"
[{:range (range 0 0 0 7)
:text "the"}])
"the beginning"))
(it "updates the end of a line"
(is.equal
(utils.apply-changes
"first line\nsecond line\nreplace end"
[{:range (range 2 7 2 11)
:text "ment"}])
"first line\nsecond line\nreplacement"))
(it "replaces a line"
(is.equal
(utils.apply-changes
"replace all"
[{:range (range 0 0 0 11)
:text "new string"}])
"new string"))
(it "can handle substituting things"
(is.equal
(utils.apply-changes
"replace beginning"
[{:range {:start {:line 0 :character 0}
:end {:line 0 :character 7}}
:text "the"}])
"the beginning"))
(it "can handle replacing everything"
(is.equal
(utils.apply-changes
"this is the\nold file"
[{:text "And this is the\nnew file"}])
"And this is the\nnew file"))))
;; (it "can substitute multiple ranges")