Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More nfnl conversion #601

Merged
merged 8 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions fnl/conjure-spec/client/fennel/aniseed_spec.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
(local {: describe : it} (require :plenary.busted))
(local assert (require :luassert.assert))
(local a (require :nfnl.core))
(local ani (require :conjure.client.fennel.aniseed))

(describe "client.fennel.aniseed"
(fn []
(local ex-mod "test.foo.bar")
(local ex-file "/some-big/ol/path/test/foo/bar.fnl")
(local ex-file2 "/some-big/ol/path/test/foo/bar/init.fnl")
(local ex-no-file "/some-big/ol/path/test/foo/bar/no/init.fnl")

(fn contains? [s substr]
(values
substr
(if (string.find s substr)
substr
s)))

(describe "module-name"
(fn []
(tset package.loaded ex-mod {:my :module})

(it "default name"
(fn []
(assert.are.equals ani.default-module-name (ani.module-name nil nil))))
(it "ex-mod and ex-file"
(fn []
(assert.are.equals ex-mod (ani.module-name ex-mod ex-file))))
(it "ex-file and no ex-mod"
(fn []
(assert.are.equals ex-mod (ani.module-name nil ex-file))))
(it "ex-file2 and no ex-mod"
(fn []
(assert.are.equals ex-mod (ani.module-name nil ex-file2))))
(it "default module name when no ex-file"
(fn []
(assert.are.equals ani.default-module-name (ani.module-name nil ex-no-file))))

(tset package.loaded ex-mod nil)
))
(describe "eval-str"
(fn []
(fn eval! [code]
(var result nil)
(var raw nil)
(ani.eval-str
{:code code
:context "foo.bar"
:passive? true
:file-path "foo/bar.fnl"
:on-result #(set result $1)
:on-result-raw #(set raw $1)})
{:result result
:raw raw})

(it "evaluates a form"
(fn []
(assert.same {:raw [30] :result "30"} (eval! "(+ 10 20)"))))
(it "eval a function definition"
(fn []
(let [{: raw : result} (eval! "(fn hi [] 10)")]
(assert.are.equals :function (type (a.first raw)))
(assert.are.equals :string (type result))
(assert.is_not_nil (contains? result "#<function: "))
)))
(it "evaluates a function"
(fn []
(assert.same {:raw [10] :result "10"} (eval! "(hi)"))))
(it "evaulates unknown identifier"
(fn []
(let [{: result : raw} (eval! "(ohno)")]
(assert.are.equals (contains? result "Compile error: unknown identifier: ohno")))))

(tset package.loaded :foo.bar nil)))
(describe "repl"
(fn []
(let [foo-opts {:filename "foo.fnl"
:moduleName :foo}
bar-opts {:filename "bar.fnl"
:moduleName :bar}
bash-repl
(fn [opts]
(let [name (. opts :moduleName)
eval! (ani.repl opts)]
(it (.. "evaluate a form in module " name)
(fn []
(assert.same {:ok? true :results [3]} (eval! "(+ 1 2)"))
))

(it (.. "create local and evaluate a form with it in module " name)
(fn []
(assert.same {:ok? true :results []} (eval! "(local hi 10)"))
(assert.same {:ok? true :results [15]} (eval! "(+ 5 hi)"))
))

(it (.. "create def and evaluate a form with it in module " name)
(fn []
(assert.same {:ok? true :results []} (eval! "(def hi2 20)"))
(assert.same {:ok? true :results [25]} (eval! "(+ 5 hi2)"))
))))]

(bash-repl foo-opts)
(bash-repl foo-opts)
(tset package.loaded foo-opts.moduleName nil)

(bash-repl bar-opts)
(bash-repl bar-opts)
(tset package.loaded bar-opts.moduleName nil))))))
3 changes: 2 additions & 1 deletion fnl/conjure-spec/client_spec.fnl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(local {: describe : it : before-each } (require :plenary.busted))
(local assert (require :luassert.assert))
(local nc (require :nfnl.core))
(local client (require :conjure.client))

(describe "multiple-states? before a change"
Expand Down Expand Up @@ -113,5 +114,5 @@
(client.each-loaded-client
(fn []
(table.insert suffixes (client.get :buf-suffix))))
(assert.same [:.sql :.fnl] suffixes)
(assert.same (nc.sort [:.sql :.fnl]) (nc.sort suffixes))
nil))))
98 changes: 98 additions & 0 deletions fnl/conjure-spec/dynamic_spec.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
(local {: describe : it} (require :plenary.busted))
(local assert (require :luassert.assert))

(local dyn (require :conjure.dynamic))

(describe "conjure.dynamic"
(fn []
(describe "new-and-unbox"
(fn []
(let [foo (dyn.new #(do :bar))]
(it "new returns a function"
(fn []
(assert.are.equals :function (type foo))))
(it "function is wrapped"
(fn []
(assert.are.equals :bar (foo)))))))

(describe "bind"
(fn []
(let [foo (dyn.new #(do 1))]
(it "one level deep"
(fn []
(assert.are.equals 1 (foo))))
(it "two levels deep"
(fn []
(dyn.bind
{foo #(do 2)}
(fn [expected]
(assert.are.equals expected (foo)))
2)))
(it "no more than two levels deep"
(fn []
(dyn.bind
{foo #(do 2)}
(fn []
(assert.are.equals 2 (foo))
(dyn.bind
{foo #(do 3)}
(fn []
(assert.are.equals 3 (foo))))
(dyn.bind
{foo #(error "OHNO")}
(fn []
(let [(ok? result) (pcall foo)]
(assert.are.equals false ok?)
(assert.are.equals result "OHNO"))))
(assert.are.equals 2 (foo)))))))))

(describe "set!"
(fn []
(let [foo (dyn.new #(do 1))]
(it "one level deep"
(fn []
(assert.are.equals (foo) 1)))
(it "more than two levels deep"
(fn []
(dyn.bind
{foo #(do 2)}
(fn []
(assert.are.equals (foo) 2)
(assert.are.equals nil (dyn.set! foo #(do 3)))
(assert.are.equals (foo) 3))))))))

(describe "set-root!"
(fn []
(let [foo (dyn.new #(do 1))]
(it "one level deep"
(fn []
(assert.are.equals (foo) 1)))
(it "three levels deep"
(fn []
(dyn.bind
{foo #(do 2)}
(fn []
(assert.are.equals (foo) 2)
(assert.are.equals nil (dyn.set-root! foo #(do 3)))
(assert.are.equals (foo) 2)))))
(it "remembers binding from three levels deep"
(fn []
(assert.are.equals (foo) 3)))
(it "four levels deep"
(fn []
(dyn.set-root! foo #(do 4))))
(it "remembers binding from four levels deep"
(fn []
(assert.are.equals (foo) 4))))))

(describe "type-guard"
(fn []
(let [(ok? result) (pcall dyn.new :foo)]
(it "direct call of conjure.dynamic value fails"
(fn []
(assert.are.equals false ok?)
))
(it "returns why failed"
(fn []
(assert.is_not_nil (string.match result "conjure.dynamic values must always be wrapped in a function"))
nil)))))))
20 changes: 20 additions & 0 deletions fnl/conjure-spec/remote/stdio2_spec.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(local {: describe : it} (require :plenary.busted))
(local assert (require :luassert.assert))
(local stdio (require :conjure.remote.stdio2))

(describe "conjure.remote.stdio2"
(fn []
(describe "parse-cmd"
(fn []
(it "parses a string"
(fn []
(assert.same {:cmd "foo" :args []} (stdio.parse-cmd "foo"))))
(it "parses a list of one string"
(fn []
(assert.same {:cmd "foo" :args []} (stdio.parse-cmd ["foo"]))))
(it "parses a string with words separated by spaces"
(fn []
(assert.same {:cmd "foo" :args ["bar" "baz"]} (stdio.parse-cmd "foo bar baz"))))
(it "parses a list of more than one string"
(fn []
(assert.same {:cmd "foo" :args ["bar" "baz"]} (stdio.parse-cmd ["foo" "bar" "baz"]))))))))
1 change: 0 additions & 1 deletion fnl/conjure-spec/remote/stdio_spec.fnl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(local {: describe : it} (require :plenary.busted))
(local assert (require :luassert.assert))
(local a (require :nfnl.core))
(local stdio (require :conjure.remote.stdio))

(describe "conjure.remote.stdio"
Expand Down
Loading