Test rework, and more file tests

This commit is contained in:
XeroOl 2022-07-29 00:08:14 -05:00
parent 792713ab2a
commit 9815dae79d
No known key found for this signature in database
GPG Key ID: 9DD4B4B4DAED0322
7 changed files with 87 additions and 39 deletions

View File

@ -9,6 +9,5 @@ fennel-ls: $(SOURCES)
fennel --compile-binary main.fnl fennel-ls $(STATIC_LUA_LIB) $(LUA_INCLUDE_PATH)
test:
@echo testing
fennel test.fnl

View File

@ -17,6 +17,13 @@
(icollect [line (file:lines)]
line))))
{: make-file
: make-file-from-disk}
(λ sub [self start-line start-char end-line end-char replacement]
(local index (+ 1 start-line))
(tset self.lines index
(.. (string.sub (. self.lines index) 1 start-char)
replacement
(string.sub (. self.lines index) (+ 1 end-char)))))
{: make-file
: make-file-from-disk
: sub}

View File

@ -2,7 +2,8 @@
(local fls (require :fls))
(local {: run} (require :fennel-ls))
(λ main-loop [in out state]
(λ main-loop [in out]
(var state {})
(while
(let [msg (fls.protocol.read in)]
(fls.log.log msg)
@ -14,7 +15,6 @@
(λ main []
(main-loop
(io.input)
(io.output)
(fls.state.new-state)))
(io.output)))
(main)

View File

@ -1,11 +1,10 @@
(import-macros {: it! : describe!} :test.macros)
(import-macros {: assert-matches : describe : it} :test.macros)
(local assert (require :luassert))
(local fennel (require :fennel))
(local fls (require :fls))
(local stringx (require :pl.stringx))
(local ROOT-URI
(.. "file://"
(-> (io.popen "pwd")
@ -13,19 +12,49 @@
(stringx.strip))
"/"))
(describe! "File Loading"
(it! "can open files from disk"
(local FILE-URI (.. ROOT-URI "test_file"))
(describe "File Loading"
(it "can open files from disk"
(local uri (.. ROOT-URI "test.fnl"))
(local test-fnl-file (fls.file.make-file-from-disk uri))
(assert.equal (. test-fnl-file.lines 1)
"((require :busted.runner))"))
(it! "can have files with fixed contents"
(local uri (.. ROOT-URI "test.fnl"))
(it "can open files from fixed contents"
(local uri (.. ROOT-URI "test_file"))
(local my-file (fls.file.make-file uri ["line 1" "line 2" "line 3"]))
(assert
(match my-file
{:lines ["line 1" "line 2" "line 3"]}
true
otherwise (values false (fennel.view otherwise))))))
otherwise (values false (fennel.view otherwise)))))
(it "can update the start of a line"
(local my-file (fls.file.make-file FILE-URI ["replace beginning"]))
(fls.file.sub my-file 0 0 0 7 "the")
(assert-matches my-file {:lines ["the beginning"]}))
(it "can update the end of a line"
(local my-file (fls.file.make-file FILE-URI ["replace end"]))
(fls.file.sub my-file 0 7 0 11 "ment")
(assert-matches my-file {:lines ["replacement"]}))
(it "can replace a line"
(local my-file (fls.file.make-file FILE-URI ["replace all"]))
(fls.file.sub my-file 0 0 0 11 "new string")
(assert-matches my-file {:lines ["new string"]})))
;; next steps:
;; 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_file"))
;; (local my-file (fls.file.make-file uri [""]))
;; (fls.file.sub my-file 0 0 0 0 "どれみふぁそらてぃど")
;; (fls.file.sub my-file 0 1 0 3 "😀")
;; (fls.file.sub my-file 0 11 0 11 "end")
;; (assert-matches my-file {:lines ["ど😀ふぁそらてぃどend"]})))

View File

@ -1,12 +1,12 @@
(import-macros {: it! : describe!} :test.macros)
(import-macros {: assert-matches : describe : it} :test.macros)
(local assert (require :luassert))
(local {: run} (require :fennel-ls))
(local fennel (require :fennel))
(describe! "initialization"
(describe "initialization"
;; TODO get rid of hardcoded paths here
(it! "responds to initialize"
(it "responds to initialize"
(local initialize
{:id 1
:jsonrpc "2.0"
@ -21,12 +21,9 @@
:trace "off"
:workspaceFolders [{:name "/home/xerool/Documents/projects/fennel-ls"
:uri "file:///home/xerool/Documents/projects/fennel-ls"}]}})
(assert
(match (run [] initialize)
{:id 1
:jsonrpc "2.0"
:result {:capabilities {}
:serverInfo {:name "fennel-ls" : version}}}
true
otherwise (values false (fennel.view otherwise))))))
(assert-matches
(run [] initialize)
{:id 1
:jsonrpc "2.0"
:result {:capabilities {}
:serverInfo {:name "fennel-ls" : version}}})))

View File

@ -1,4 +1,22 @@
(fn it! [title ...] `((. (require :busted) :it) ,title (fn [] ,...)))
(fn describe! [title ...] `((. (require :busted) :describe) ,title (fn [] ,...)))
(fn it [title ...]
`((. (require :busted) :it)
,title (fn [] ,...)))
{: it! : describe!}
(fn describe [title ...]
`((. (require :busted) :describe)
,title (fn [] ,...)))
(fn assert-matches [item pattern]
`(match ,item
,pattern nil
?otherwise#
(error
(.. "Pattern did not match:\n"
(let [fennel# (require :fennel)]
(fennel#.view ?otherwise#))
"\ndid not match pattern:\n"
,(view pattern)))))
{: it
: describe
: assert-matches}

View File

@ -1,4 +1,4 @@
(import-macros {: it! : describe!} :test.macros)
(import-macros {: assert-matches : describe : it} :test.macros)
(local assert (require :luassert))
(local fennel (require :fennel))
@ -6,19 +6,19 @@
(local fls (require :fls))
(local {: run} (require :fennel-ls))
(describe! "fls.protocol"
(it! "parses incoming messages"
(describe "fls.protocol"
(it "parses incoming messages"
(let [out (stringio.open "Content-Length: 29\r\n\r\n{\"my json content\":\"is cool\"}")]
(assert.same {"my json content" "is cool"}
(fls.protocol.read out))))
(it! "serializes outgoing messages"
(it "serializes outgoing messages"
(let [in (stringio.create)]
(fls.protocol.write in {"my json content" "is cool"})
(assert.same "Content-Length: 29\r\n\r\n{\"my json content\":\"is cool\"}"
(in:value))))
(it! "can read multiple incoming messages"
(it "can read multiple incoming messages"
(let [out (stringio.open "Content-Length: 29\r\n\r\n{\"my json content\":\"is cool\"}Content-Length: 29\r\n\r\n{\"my json content\":\"is cool\"}")]
(assert.same {"my json content" "is cool"}
(fls.protocol.read out))
@ -27,10 +27,8 @@
(assert.same nil
(fls.protocol.read out))))
(it! "can report the ParseError code"
(it "can report the ParseError code"
(let [out (stringio.open "Content-Length: 9\r\n\r\n{{{{{}}}}")]
(assert
(match (run [] (fls.protocol.read out))
{:error {:code -32700} :jsonrpc "2.0"}
true
otherwise (values false (fennel.view otherwise)))))))
(assert-matches
(run [] (fls.protocol.read out))
{:error {:code -32700} :jsonrpc "2.0"}))))