]> git.madduck.net Git - etc/vim.git/blobdiff - .vim/bundle/ale/test/lua/ale_env_spec.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / test / lua / ale_env_spec.lua
diff --git a/.vim/bundle/ale/test/lua/ale_env_spec.lua b/.vim/bundle/ale/test/lua/ale_env_spec.lua
new file mode 100644 (file)
index 0000000..1cceb5b
--- /dev/null
@@ -0,0 +1,56 @@
+local eq = assert.are.same
+local ale = require("ale")
+
+describe("ale.env", function()
+    local is_win32 = false
+
+    setup(function()
+        _G.vim = {
+            o = setmetatable({}, {
+                __index = function(_, key)
+                    if key == "shell" then
+                        if is_win32 then
+                            return "cmd.exe"
+                        end
+
+                        return "bash"
+                    end
+
+                    return nil
+                end
+            }),
+            fn = {
+                has = function(feature)
+                    return feature == "win32" and is_win32
+                end,
+                -- Mock a very poor version of shellescape() for Unix
+                -- This shouldn't be called for Windows
+                shellescape = function(str)
+                    return "'" .. str .. "'"
+                end,
+                fnamemodify = function(shell, _)
+                    return shell
+                end
+            }
+        }
+    end)
+
+    teardown(function()
+        _G.vim = nil
+    end)
+
+    before_each(function()
+        is_win32 = false
+    end)
+
+    it("should escape values correctly on Unix", function()
+        eq("name='xxx' ", ale.env('name', 'xxx'))
+        eq("name='foo bar' ", ale.env('name', 'foo bar'))
+    end)
+
+    it("should escape values correctly on Windows", function()
+        is_win32 = true
+        eq('set name=xxx && ', ale.env('name', 'xxx'))
+        eq('set "name=foo bar" && ', ale.env('name', 'foo bar'))
+    end)
+end)