Skip to content

Commit

Permalink
Convert another batch of source and test files
Browse files Browse the repository at this point in the history
  • Loading branch information
russtoku committed Aug 22, 2024
1 parent 842f065 commit d056253
Show file tree
Hide file tree
Showing 26 changed files with 930 additions and 770 deletions.
74 changes: 74 additions & 0 deletions fnl/conjure-spec/linked-list_spec.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
(local {: describe : it} (require :plenary.busted))
(local assert (require :luassert.assert))
(local ll (require :conjure.linked-list))

(describe "conjure.linked-list"
(fn []

(describe "basics"
(fn []
(let [l (ll.create [1 2 3])]
(it "get first value"
(fn []
(assert.are.equals 1 (->> l (ll.val)))))
(it "get second value"
(fn []
(assert.are.equals 2 (->> l (ll.next) (ll.val)))))
(it "forward and back"
(fn []
(assert.are.equals 1 (->> l (ll.next) (ll.prev) (ll.val)))))
(it "last by steps"
(fn []
(assert.are.equals 3 (->> l (ll.next) (ll.next) (ll.val)))))
(it "off the end"
(fn []
(assert.are.equals nil (->> l (ll.next) (ll.next) (ll.next)))))
(it "off the front"
(fn []
(assert.are.equals nil (->> l (ll.prev)))))
(it "val handles nils"
(fn []
(assert.are.equals nil (ll.val nil))))
(it "last"
(fn []
(assert.are.equals 3 (->> l (ll.last) (ll.val)))))
(it "first"
(fn []
(assert.are.equals 1 (->> l (ll.first) (ll.val)))))
(it "last then first"
(fn []
(assert.are.equals 1 (->> l (ll.last) (ll.first) (ll.val))))))))

(describe "until"
(fn []
(let [l (ll.create [1 2 3 4 5])]

(it "nil if not found"
(fn []
(assert.are.equals nil (->> l (ll.until #(= 8 (ll.val $1))) (ll.val)))))
(it "target node if found"
(fn []
(assert.are.equals 3 (->> l (ll.until #(= 3 (ll.val $1))) (ll.val)))))
(it "can find the one before"
(fn []
(assert.are.equals 2 (->> l (ll.until #(= 3 (->> $1 (ll.next) (ll.val)))) (ll.val))))))))

(describe "cycle"
(fn []
(let [l (ll.cycle (ll.create [1 2 3]))]
(it "first is still first"
(fn []
(assert.are.equals 1 (->> l (ll.val)))))
(it "can still next"
(fn []
(assert.are.equals 2 (->> l (ll.next) (ll.val)))))
(it "can still next next (last)"
(fn []
(assert.are.equals 3 (->> l (ll.next) (ll.next) (ll.val)))))
(it "off the end loops"
(fn []
(assert.are.equals 1 (->> l (ll.next) (ll.next) (ll.next) (ll.val)))))
(it "off the front loops"
(fn []
(assert.are.equals 3 (->> l (ll.prev) (ll.val))))))))))

55 changes: 55 additions & 0 deletions fnl/conjure-spec/process_spec.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
(local {: describe : it} (require :plenary.busted))
(local assert (require :luassert.assert))
(local nvim (require :conjure.aniseed.nvim))
(local process (require :conjure.process))

(describe "conjure.process"
(fn []
(describe "executable?"
(fn []
(it "thing's that don't exist return false"
(fn []
(assert.are.equals false (process.executable? "nope-this-does-not-exist"))))
(it "sh should always exist, I hope"
(fn []
(assert.are.equals true (process.executable? "sh"))))
(it "only the first word is checked"
(fn []
(assert.are.equals true (process.executable? "sh foo bar"))))))

(describe "execute-stop-lifecycle"
(fn []
(let [sh (process.execute "sh")]
(it "we get a table to identify the process"
(fn []
(assert.are.equals :table (type sh))))
(it "it starts out as running"
(fn []
(assert.are.equals true (process.running? sh))))
(it "the running check handles nils"
(fn []
(assert.are.equals false (process.running? nil))))
(it "a buffer is created for the terminal / process"
(fn []
(assert.are.equals 1 (nvim.fn.bufexists sh.buf))))
(it "stopping returns the process table"
(fn []
(assert.are.equals sh (process.stop sh))))
(it "stopping is idempotent"
(fn []
(assert.are.equals sh (process.stop sh))))
(it "now it's not running"
(fn []
(assert.are.equals false (process.running? sh)))))))

(describe "on-exit-hook"
(fn []
(let [state {:args nil}
sh (process.execute
"sh"
{:on-exit (fn [...]
(tset state :args [...]))})]
(it "called and given the proc"
(fn []
(process.stop sh)
(assert.same [sh] state.args))))))))
48 changes: 48 additions & 0 deletions fnl/conjure-spec/promise_spec.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
(local {: describe : it} (require :plenary.busted))
(local assert (require :luassert.assert))
(local a (require :nfnl.core))
(local promise (require :conjure.promise))

(describe "conjure.promise"
(fn []
(describe "basics"
(let [p (promise.new)]
(fn []
(it "starts incomplete"
(fn []
(assert.are.equals false (promise.done? p))))
(it "done after deliver"
(fn []
(promise.deliver p :foo)
(assert.are.equals true (promise.done? p))))
(it "returns the value on close"
(fn []
(assert.are.equals :foo (promise.close p)))))))

(describe "multiple-deliveries"
(fn []
(let [p (promise.new)]
(it "only the first delivery works"
(fn []
(promise.deliver p :foo)
(promise.deliver p :bar)
(assert.are.equals :foo (promise.close p)))))))

(describe "async"
(let [p (promise.new)
del (promise.deliver-fn p)]
(vim.schedule (fn [] (del :later)))
(fn []
(it "async delivery hasn't happened yet"
(fn []
(assert.are.equals false (promise.done? p))))
(it "await returns 0 from wait()"
(fn []
(assert.are.equals 0 (promise.await p))))
(it "complete after await"
(fn []
(assert.are.equals true (promise.done? p))))
(it "value is correct"
(fn []
(assert.are.equals :later (promise.close p)))))))
))
19 changes: 19 additions & 0 deletions fnl/conjure-spec/school_spec.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(local {: describe : it} (require :plenary.busted))
(local assert (require :luassert.assert))
(local school (require :conjure.school))
(local nvim (require :conjure.aniseed.nvim))

(describe "running :ConjureSchool"
(fn []
(school.start)

(it "buffer has correct name"
(fn []
(assert.are.equals "conjure-school.fnl" (nvim.fn.bufname))))

(it "buffer requires conjure.school module"
(fn []
(assert.same ["(local school (require :conjure.school))"] (nvim.buf_get_lines 0 1 2 false))))

(nvim.ex.bdelete "conjure-school.fnl")
))
Loading

0 comments on commit d056253

Please sign in to comment.