Page MenuHomePhorge

No OneTemporary

diff --git a/lua/ivy/libivy_test.lua b/lua/ivy/libivy_test.lua
new file mode 100644
index 0000000..44159e5
--- /dev/null
+++ b/lua/ivy/libivy_test.lua
@@ -0,0 +1,9 @@
+local libivy = require "ivy.libivy"
+
+it("should run a simple match", function(t)
+ local score = libivy.ivy_match("term", "I am a serch term")
+
+ if score > 0 then
+ t.error "Score should not be grater than 0"
+ end
+end)
diff --git a/lua/ivy/matcher_test.lua b/lua/ivy/matcher_test.lua
new file mode 100644
index 0000000..3b057f5
--- /dev/null
+++ b/lua/ivy/matcher_test.lua
@@ -0,0 +1,30 @@
+local libivy = require "ivy.libivy"
+
+-- Helper function to test a that string `one` has a higher match score than
+-- string `two`. If string `one` has a lower score than string `two` a string
+-- will be returned that can be used in body of an error. If not then `nil` is
+-- returned and all is good.
+local match_test = function(term, one, two)
+ local score_one = libivy.ivy_match(term, one)
+ local score_two = libivy.ivy_match(term, two)
+
+ if score_one < score_two then
+ return one .. " should be ranked higher than " .. two
+ end
+
+ return nil
+end
+
+it("sould match path separator", function(t)
+ local result = match_test("file", "some/file.lua", "somefile.lua")
+ if result then
+ t.error(result)
+ end
+end)
+
+it("sould match the start of a string", function(t)
+ local result = match_test("file", "file.lua", "somefile.lua")
+ if result then
+ t.error(result)
+ end
+end)
diff --git a/scripts/test.lua b/scripts/test.lua
new file mode 100644
index 0000000..b7090ab
--- /dev/null
+++ b/scripts/test.lua
@@ -0,0 +1,62 @@
+package.path = "lua/?.lua;" .. package.path
+
+local global_context = {
+ current_test_name = "",
+ total = 0,
+ pass = 0,
+ fail = 0,
+}
+
+_G.it = function(name, callback)
+ local context = {
+ name = name,
+ error = function(message)
+ error(message, 2)
+ end,
+ }
+
+ local time = os.clock() * 1000
+ local status, err = pcall(callback, context)
+ local elapsed = (os.clock() * 1000) - time
+ local prefix = "\x1B[42mPASS"
+
+ global_context.total = global_context.total + 1
+
+ if status then
+ global_context.pass = global_context.pass + 1
+ else
+ global_context.fail = global_context.fail + 1
+ prefix = "\x1B[41mFAIL"
+ end
+
+ print(string.format("%s\x1B[0m %s - %s (%.3f ms)", prefix, global_context.current_test_name, name, elapsed))
+ if err then
+ print(" " .. err)
+ end
+end
+
+local start_time = os.clock()
+for _, name in ipairs(arg) do
+ -- Turn the file name in to a lau module name that we can require
+ local module = name:gsub("^lua/", "")
+ module, _ = module:gsub("/init.lua$", "")
+ module, _ = module:gsub(".lua$", "")
+ module = module:gsub("/", ".")
+
+ global_context.current_test_name = module:gsub("_test", "")
+ require(module)
+end
+
+print(string.format(
+ [[
+
+Tests: %d passed, %d total
+Time: %.3f seconds]],
+ global_context.pass,
+ global_context.total,
+ (os.clock()) - start_time
+))
+
+if global_context.fail > 0 then
+ os.exit(1, true)
+end

File Metadata

Mime Type
text/x-diff
Expires
Wed, Sep 10, 5:13 PM (11 h, 37 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9012
Default Alt Text
(3 KB)

Event Timeline