Test rework, and more file tests
This commit is contained in:
parent
792713ab2a
commit
9815dae79d
1
Makefile
1
Makefile
@ -9,6 +9,5 @@ fennel-ls: $(SOURCES)
|
|||||||
fennel --compile-binary main.fnl fennel-ls $(STATIC_LUA_LIB) $(LUA_INCLUDE_PATH)
|
fennel --compile-binary main.fnl fennel-ls $(STATIC_LUA_LIB) $(LUA_INCLUDE_PATH)
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@echo testing
|
|
||||||
fennel test.fnl
|
fennel test.fnl
|
||||||
|
|
||||||
|
|||||||
11
fls/file.fnl
11
fls/file.fnl
@ -17,6 +17,13 @@
|
|||||||
(icollect [line (file:lines)]
|
(icollect [line (file:lines)]
|
||||||
line))))
|
line))))
|
||||||
|
|
||||||
{: make-file
|
(λ sub [self start-line start-char end-line end-char replacement]
|
||||||
: make-file-from-disk}
|
(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}
|
||||||
|
|||||||
6
main.fnl
6
main.fnl
@ -2,7 +2,8 @@
|
|||||||
(local fls (require :fls))
|
(local fls (require :fls))
|
||||||
(local {: run} (require :fennel-ls))
|
(local {: run} (require :fennel-ls))
|
||||||
|
|
||||||
(λ main-loop [in out state]
|
(λ main-loop [in out]
|
||||||
|
(var state {})
|
||||||
(while
|
(while
|
||||||
(let [msg (fls.protocol.read in)]
|
(let [msg (fls.protocol.read in)]
|
||||||
(fls.log.log msg)
|
(fls.log.log msg)
|
||||||
@ -14,7 +15,6 @@
|
|||||||
(λ main []
|
(λ main []
|
||||||
(main-loop
|
(main-loop
|
||||||
(io.input)
|
(io.input)
|
||||||
(io.output)
|
(io.output)))
|
||||||
(fls.state.new-state)))
|
|
||||||
|
|
||||||
(main)
|
(main)
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
(import-macros {: it! : describe!} :test.macros)
|
(import-macros {: assert-matches : describe : it} :test.macros)
|
||||||
(local assert (require :luassert))
|
(local assert (require :luassert))
|
||||||
|
|
||||||
(local fennel (require :fennel))
|
(local fennel (require :fennel))
|
||||||
(local fls (require :fls))
|
(local fls (require :fls))
|
||||||
(local stringx (require :pl.stringx))
|
(local stringx (require :pl.stringx))
|
||||||
|
|
||||||
|
|
||||||
(local ROOT-URI
|
(local ROOT-URI
|
||||||
(.. "file://"
|
(.. "file://"
|
||||||
(-> (io.popen "pwd")
|
(-> (io.popen "pwd")
|
||||||
@ -13,19 +12,49 @@
|
|||||||
(stringx.strip))
|
(stringx.strip))
|
||||||
"/"))
|
"/"))
|
||||||
|
|
||||||
(describe! "File Loading"
|
(local FILE-URI (.. ROOT-URI "test_file"))
|
||||||
(it! "can open files from disk"
|
|
||||||
|
(describe "File Loading"
|
||||||
|
(it "can open files from disk"
|
||||||
(local uri (.. ROOT-URI "test.fnl"))
|
(local uri (.. ROOT-URI "test.fnl"))
|
||||||
|
|
||||||
(local test-fnl-file (fls.file.make-file-from-disk uri))
|
(local test-fnl-file (fls.file.make-file-from-disk uri))
|
||||||
(assert.equal (. test-fnl-file.lines 1)
|
(assert.equal (. test-fnl-file.lines 1)
|
||||||
"((require :busted.runner))"))
|
"((require :busted.runner))"))
|
||||||
|
|
||||||
(it! "can have files with fixed contents"
|
(it "can open files from fixed contents"
|
||||||
(local uri (.. ROOT-URI "test.fnl"))
|
(local uri (.. ROOT-URI "test_file"))
|
||||||
(local my-file (fls.file.make-file uri ["line 1" "line 2" "line 3"]))
|
(local my-file (fls.file.make-file uri ["line 1" "line 2" "line 3"]))
|
||||||
(assert
|
(assert
|
||||||
(match my-file
|
(match my-file
|
||||||
{:lines ["line 1" "line 2" "line 3"]}
|
{:lines ["line 1" "line 2" "line 3"]}
|
||||||
true
|
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"]})))
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
(import-macros {: it! : describe!} :test.macros)
|
(import-macros {: assert-matches : describe : it} :test.macros)
|
||||||
(local assert (require :luassert))
|
(local assert (require :luassert))
|
||||||
|
|
||||||
(local {: run} (require :fennel-ls))
|
(local {: run} (require :fennel-ls))
|
||||||
(local fennel (require :fennel))
|
(local fennel (require :fennel))
|
||||||
|
|
||||||
(describe! "initialization"
|
(describe "initialization"
|
||||||
;; TODO get rid of hardcoded paths here
|
;; TODO get rid of hardcoded paths here
|
||||||
(it! "responds to initialize"
|
(it "responds to initialize"
|
||||||
(local initialize
|
(local initialize
|
||||||
{:id 1
|
{:id 1
|
||||||
:jsonrpc "2.0"
|
:jsonrpc "2.0"
|
||||||
@ -21,12 +21,9 @@
|
|||||||
:trace "off"
|
:trace "off"
|
||||||
:workspaceFolders [{:name "/home/xerool/Documents/projects/fennel-ls"
|
:workspaceFolders [{:name "/home/xerool/Documents/projects/fennel-ls"
|
||||||
:uri "file:///home/xerool/Documents/projects/fennel-ls"}]}})
|
:uri "file:///home/xerool/Documents/projects/fennel-ls"}]}})
|
||||||
(assert
|
(assert-matches
|
||||||
(match (run [] initialize)
|
(run [] initialize)
|
||||||
{:id 1
|
{:id 1
|
||||||
:jsonrpc "2.0"
|
:jsonrpc "2.0"
|
||||||
:result {:capabilities {}
|
:result {:capabilities {}
|
||||||
:serverInfo {:name "fennel-ls" : version}}}
|
:serverInfo {:name "fennel-ls" : version}}})))
|
||||||
true
|
|
||||||
otherwise (values false (fennel.view otherwise))))))
|
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,22 @@
|
|||||||
(fn it! [title ...] `((. (require :busted) :it) ,title (fn [] ,...)))
|
(fn it [title ...]
|
||||||
(fn describe! [title ...] `((. (require :busted) :describe) ,title (fn [] ,...)))
|
`((. (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}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
(import-macros {: it! : describe!} :test.macros)
|
(import-macros {: assert-matches : describe : it} :test.macros)
|
||||||
(local assert (require :luassert))
|
(local assert (require :luassert))
|
||||||
|
|
||||||
(local fennel (require :fennel))
|
(local fennel (require :fennel))
|
||||||
@ -6,19 +6,19 @@
|
|||||||
(local fls (require :fls))
|
(local fls (require :fls))
|
||||||
(local {: run} (require :fennel-ls))
|
(local {: run} (require :fennel-ls))
|
||||||
|
|
||||||
(describe! "fls.protocol"
|
(describe "fls.protocol"
|
||||||
(it! "parses incoming messages"
|
(it "parses incoming messages"
|
||||||
(let [out (stringio.open "Content-Length: 29\r\n\r\n{\"my json content\":\"is cool\"}")]
|
(let [out (stringio.open "Content-Length: 29\r\n\r\n{\"my json content\":\"is cool\"}")]
|
||||||
(assert.same {"my json content" "is cool"}
|
(assert.same {"my json content" "is cool"}
|
||||||
(fls.protocol.read out))))
|
(fls.protocol.read out))))
|
||||||
|
|
||||||
(it! "serializes outgoing messages"
|
(it "serializes outgoing messages"
|
||||||
(let [in (stringio.create)]
|
(let [in (stringio.create)]
|
||||||
(fls.protocol.write in {"my json content" "is cool"})
|
(fls.protocol.write in {"my json content" "is cool"})
|
||||||
(assert.same "Content-Length: 29\r\n\r\n{\"my json content\":\"is cool\"}"
|
(assert.same "Content-Length: 29\r\n\r\n{\"my json content\":\"is cool\"}"
|
||||||
(in:value))))
|
(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\"}")]
|
(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"}
|
(assert.same {"my json content" "is cool"}
|
||||||
(fls.protocol.read out))
|
(fls.protocol.read out))
|
||||||
@ -27,10 +27,8 @@
|
|||||||
(assert.same nil
|
(assert.same nil
|
||||||
(fls.protocol.read out))))
|
(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{{{{{}}}}")]
|
(let [out (stringio.open "Content-Length: 9\r\n\r\n{{{{{}}}}")]
|
||||||
(assert
|
(assert-matches
|
||||||
(match (run [] (fls.protocol.read out))
|
(run [] (fls.protocol.read out))
|
||||||
{:error {:code -32700} :jsonrpc "2.0"}
|
{:error {:code -32700} :jsonrpc "2.0"}))))
|
||||||
true
|
|
||||||
otherwise (values false (fennel.view otherwise)))))))
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user