fennel-ls/test/string-processing-test.fnl
2022-08-19 09:43:58 -05:00

67 lines
2.0 KiB
Fennel

(import-macros {: is-matching : describe : it} :test)
(local is (require :luassert))
(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
;; (it "can handle unicode"
;; (local uri (.. ROOT-URI "test_document"))
;; (local my-document (document.create uri ""))
;; (document.replace my-document 0 0 0 0 "どれみふぁそらてぃど")
;; (document.replace my-document 0 1 0 3 "😀")
;; (document.replace my-document 0 11 0 11 "end")
;; (is-matching my-document {:text "ど😀ふぁそらてぃどend"})))
(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"))))