-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #601 from russtoku/nfnl-migration
More nfnl conversion
- Loading branch information
Showing
28 changed files
with
990 additions
and
708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"])))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.