Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F133288
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lua/ivy/prompt_test.lua b/lua/ivy/prompt_test.lua
new file mode 100644
index 0000000..57b0339
--- /dev/null
+++ b/lua/ivy/prompt_test.lua
@@ -0,0 +1,67 @@
+local prompt = require "ivy.prompt"
+
+before_each(function()
+ -- Mock the global vim functions we are using in the prompt
+ _G.vim = {
+ notify = function() end,
+ api = {
+ nvim_echo = function() end,
+ },
+ }
+
+ prompt.destroy()
+end)
+
+-- Input a list of strings into the prompt
+local input = function(input_table)
+ for index = 1, #input_table do
+ prompt.input(input_table[index])
+ end
+end
+
+-- Asserts the prompt contains the correct value
+local assert_prompt = function(t, expected)
+ local text = prompt.text()
+ if text ~= expected then
+ t.error("The promp text should be '" .. expected .. "' found '" .. text .. "'")
+ end
+end
+
+it("starts with empty text", function(t)
+ if prompt.text() ~= "" then
+ t.error "The prompt should start with empty text"
+ end
+end)
+
+it("can input some text", function(t)
+ input { "A", "d", "e" }
+ assert_prompt(t, "Ade")
+end)
+
+it("can delete a char", function(t)
+ input { "A", "d", "e", "BACKSPACE" }
+ assert_prompt(t, "Ad")
+end)
+
+it("will reset the text", function(t)
+ input { "A", "d", "e" }
+ prompt.set "New"
+ assert_prompt(t, "New")
+end)
+
+it("can move around the a word", function(t)
+ input { "P", "r", "o", "p", "t", "LEFT", "LEFT", "LEFT", "RIGHT", "m" }
+ assert_prompt(t, "Prompt")
+end)
+
+it("can delete a word", function(t)
+ prompt.set "Ade Attwood"
+ input { "DELETE_WORD" }
+ assert_prompt(t, "Ade")
+end)
+
+it("can delete a word in the middle", function(t)
+ prompt.set "Ade middle A"
+ input { "LEFT", "LEFT", "DELETE_WORD" }
+ assert_prompt(t, "Ade A")
+end)
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jun 9, 8:59 PM (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8976
Default Alt Text
(1 KB)
Attached To
Mode
R1 ivy.nvim
Attached
Detach File
Event Timeline
Log In to Comment