-
-
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 #597 from russtoku/nfnl-migration
Convert tree-sitter.fnl, timer.fnl, text.fnl, stack.fnl, and tests
- Loading branch information
Showing
12 changed files
with
539 additions
and
219 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,34 @@ | ||
(local {: describe : it} (require :plenary.busted)) | ||
(local assert (require :luassert.assert)) | ||
(local stack (require :conjure.stack)) | ||
|
||
(describe "conjure.stack" | ||
(fn [] | ||
(describe "push" | ||
(fn [] | ||
(it "item on a stack" | ||
(fn [] | ||
(assert.same [1 2 3] (-> (stack.push [] 1) | ||
(stack.push 2) | ||
(stack.push 3))))))) | ||
|
||
(describe "pop" | ||
(fn [] | ||
(it "top of stack" | ||
(fn [] | ||
(assert.same [1 2] (stack.pop [1 2 3])))) | ||
|
||
(it "empty stack" | ||
(fn [] | ||
(assert.same [] (stack.pop [])))))) | ||
|
||
(describe "peek" | ||
(fn [] | ||
(it "top of stack" | ||
(fn [] | ||
(assert.are.equals 3 (stack.peek [1 2 3])))) | ||
|
||
(it "empty stack" | ||
(fn [] | ||
(assert.are.equals nil (stack.peek [])))) | ||
)))) |
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,155 @@ | ||
(local {: describe : it} (require :plenary.busted)) | ||
(local assert (require :luassert.assert)) | ||
(local text (require :conjure.text)) | ||
|
||
(describe "text" | ||
(fn [] | ||
(describe "left-sample" | ||
(fn [] | ||
(it "handles empty strings" | ||
(fn [] | ||
(assert.are.equals "" (text.left-sample "" 0)))) | ||
|
||
(it "handles single characters" | ||
(fn [] | ||
(assert.are.equals "f" (text.left-sample "f" 1)))) | ||
|
||
(it "does nothing if correct" | ||
(fn [] | ||
(assert.are.equals "foo bar" (text.left-sample "foo bar" 10)))) | ||
|
||
(it "replaces lots of whitespace with a space" | ||
(fn [] | ||
(assert.are.equals "foo bar" (text.left-sample "foo \n\n bar" 10)))) | ||
|
||
(it "cuts the string if too long" | ||
(fn [] | ||
(assert.are.equals "foo bar b..." (text.left-sample "foo \n\n bar \n\n baz" 10)))) | ||
|
||
(it "trims leading and trailing whitespace" | ||
(fn [] | ||
(assert.are.equals "foo bar" (text.left-sample " foo \n \n bar \n" 10)))))) | ||
|
||
(describe "right-sample" | ||
(fn [] | ||
(it "same as left-sample, but we want the right" | ||
(fn [] | ||
(assert.are.equals "...o bar baz" (text.right-sample "foo \n\n bar \n\n baz" 10)))))) | ||
|
||
(describe "split-lines" | ||
(fn [] | ||
(it "nothing to nothing" | ||
(fn [] | ||
(assert.same [""] (text.split-lines "") ""))) | ||
|
||
(it "basic split" | ||
(fn [] | ||
(assert.same ["foo" "bar"] (text.split-lines "foo\nbar") ""))) | ||
|
||
(it "blank lines" | ||
(fn [] | ||
(assert.same ["foo" "" "bar"] (text.split-lines "foo\n\nbar") ""))) | ||
|
||
(it "Windows CRLF" | ||
(fn [] | ||
(assert.same ["foo" "bar"] (text.split-lines "foo\r\nbar") "") | ||
)))) | ||
|
||
(describe "prefixed-lines" | ||
(fn [] | ||
(it "nothing to nothing" | ||
(fn [] | ||
(assert.same ["; "] (text.prefixed-lines "" "; ")))) | ||
|
||
(it "single line" | ||
(fn [] | ||
(assert.same ["; foo"] (text.prefixed-lines "foo" "; ")))) | ||
|
||
(it "multiple lines" | ||
(fn [] | ||
(assert.same ["; foo" "; bar"] (text.prefixed-lines "foo\nbar" "; ")))))) | ||
|
||
(describe "starts-with" | ||
(fn [] | ||
(it "foo" | ||
(fn [] | ||
(assert.are.equals true (text.starts-with "foobar" "foo")))) | ||
|
||
(it "foob" | ||
(fn [] | ||
(assert.are.equals true (text.starts-with "foobar" "foob")))) | ||
|
||
(it "foox" | ||
(fn [] | ||
(assert.are.equals false (text.starts-with "foobar" "foox")))) | ||
|
||
(it "ohno" | ||
(fn [] | ||
(assert.are.equals nil (text.starts-with nil "ohno")))))) | ||
|
||
(describe "ends-with" | ||
(fn [] | ||
(it "bar" | ||
(fn [] | ||
(assert.are.equals true (text.ends-with "foobar" "bar")))) | ||
|
||
(it "obar" | ||
(fn [] | ||
(assert.are.equals true (text.ends-with "foobar" "obar")))) | ||
|
||
(it "xbar" | ||
(fn [] | ||
(assert.are.equals false (text.ends-with "foobar" "xbar")))) | ||
|
||
(it "ohno" | ||
(fn [] | ||
(assert.are.equals nil (text.ends-with nil "ohno")))))) | ||
|
||
(describe "first-and-last-chars" | ||
(fn [] | ||
(it "of parentheses around words" | ||
(fn [] | ||
(assert.are.equals "()" (text.first-and-last-chars "(hello-world)")))) | ||
(it "of empty string" | ||
(fn [] | ||
(assert.are.equals "" (text.first-and-last-chars "")))) | ||
(it "of single opening parenthesis" | ||
(fn [] | ||
(assert.are.equals "(" (text.first-and-last-chars "(")))) | ||
(it "of nil" | ||
(fn [] | ||
(assert.are.equals nil (text.first-and-last-chars nil)))))) | ||
|
||
(describe "chars" | ||
(fn [] | ||
(it "of nothing" | ||
(fn [] | ||
(assert.same [] (text.chars)))) | ||
(it "of empty string" | ||
(fn [] | ||
(assert.same [] (text.chars "")))) | ||
(it "of \"abc\"" | ||
(fn [] | ||
(assert.same [:a :b :c] (text.chars "abc")))))) | ||
|
||
(describe "upper-first" | ||
(fn [] | ||
(it "of empty string" | ||
(fn [] | ||
(assert.are.equals "" (text.upper-first "")))) | ||
(it "of \"A\"" | ||
(fn [] | ||
(assert.are.equals "A" (text.upper-first "A")))) | ||
(it "of \"a\"" | ||
(fn [] | ||
(assert.are.equals "A" (text.upper-first "a")))) | ||
(it "of first word of many words" | ||
(fn [] | ||
(assert.are.equals "Foo bar bAZ 5" (text.upper-first "foo bar bAZ 5")))) | ||
(it "of nil" | ||
(fn [] | ||
(assert.are.equals nil (text.upper-first nil)))) | ||
(it "of string of numbers" | ||
(fn [] | ||
(assert.are.equals "123" (text.upper-first "123")) | ||
)))))) |
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 |
---|---|---|
@@ -1,17 +1,20 @@ | ||
(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) | ||
(local {: autoload} (require :nfnl.module)) | ||
(local a (autoload :conjure.aniseed.core)) | ||
|
||
(module conjure.stack | ||
{autoload {a conjure.aniseed.core}}) | ||
|
||
(defn push [s v] | ||
(fn push [s v] | ||
(table.insert s v) | ||
s) | ||
|
||
(defn pop [s] | ||
(fn pop [s] | ||
(table.remove s) | ||
s) | ||
|
||
(defn peek [s] | ||
(fn peek [s] | ||
(a.last s)) | ||
|
||
*module* | ||
{ | ||
: push | ||
: pop | ||
: peek | ||
} | ||
|
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 |
---|---|---|
@@ -1,18 +1,20 @@ | ||
(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) | ||
(local {: autoload} (require :nfnl.module)) | ||
(local a (autoload :conjure.aniseed.core)) | ||
(local nvim (autoload :conjure.aniseed.nvim)) | ||
|
||
(module conjure.timer | ||
{autoload {a conjure.aniseed.core | ||
nvim conjure.aniseed.nvim}}) | ||
|
||
(defn defer [f ms] | ||
(fn defer [f ms] | ||
;; vim.loop is deprecated in Neovim 0.10. Use vim.uv instead. | ||
(let [t (vim.loop.new_timer)] | ||
(t:start ms 0 (vim.schedule_wrap f)) | ||
t)) | ||
|
||
(defn destroy [t] | ||
(fn destroy [t] | ||
(when t | ||
(t:stop) | ||
(t:close)) | ||
nil) | ||
|
||
*module* | ||
{ | ||
: defer | ||
: destroy | ||
} |
Oops, something went wrong.