diff options
author | ZyX <kp-pav@yandex.ru> | 2016-01-10 22:08:43 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2016-01-11 05:24:44 +0300 |
commit | 3b7c4093e24fd413696e3f0aba9a7a1a470a8b4f (patch) | |
tree | dd038941cebd5367a9bf92ca9d52b1638e07c162 /test/unit/strings_spec.lua | |
parent | 73b8c89518404ea3fbb376e98c1a60e868581ecd (diff) | |
download | rneovim-3b7c4093e24fd413696e3f0aba9a7a1a470a8b4f.tar.gz rneovim-3b7c4093e24fd413696e3f0aba9a7a1a470a8b4f.tar.bz2 rneovim-3b7c4093e24fd413696e3f0aba9a7a1a470a8b4f.zip |
shell: Unquote &shell* options before using them
Diffstat (limited to 'test/unit/strings_spec.lua')
-rw-r--r-- | test/unit/strings_spec.lua | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/test/unit/strings_spec.lua b/test/unit/strings_spec.lua new file mode 100644 index 0000000000..b310ccb541 --- /dev/null +++ b/test/unit/strings_spec.lua @@ -0,0 +1,69 @@ +local helpers = require("test.unit.helpers") + +local cimport = helpers.cimport +local internalize = helpers.internalize +local eq = helpers.eq +local ffi = helpers.ffi +local to_cstr = helpers.to_cstr + +local strings = cimport('stdlib.h', './src/nvim/strings.h', + './src/nvim/memory.h') + +describe('vim_strnsave_unquoted()', function() + local vim_strnsave_unquoted = function(s, len) + local res = strings.vim_strnsave_unquoted(to_cstr(s), len or #s) + local ret = ffi.string(res) + -- Explicitly free memory so we are sure it is allocated: if it was not it + -- will crash. + strings.xfree(res) + return ret + end + + it('copies unquoted strings as-is', function() + eq('-c', vim_strnsave_unquoted('-c')) + eq('', vim_strnsave_unquoted('')) + end) + + it('respects length argument', function() + eq('', vim_strnsave_unquoted('-c', 0)) + eq('-', vim_strnsave_unquoted('-c', 1)) + eq('-', vim_strnsave_unquoted('"-c', 2)) + end) + + it('unquotes fully quoted word', function() + eq('/bin/sh', vim_strnsave_unquoted('"/bin/sh"')) + end) + + it('unquotes partially quoted word', function() + eq('/Program Files/sh', vim_strnsave_unquoted('/Program" "Files/sh')) + end) + + it('removes ""', function() + eq('/Program Files/sh', vim_strnsave_unquoted('/""Program" "Files/sh')) + end) + + it('performs unescaping of "', function() + eq('/"Program Files"/sh', vim_strnsave_unquoted('/"\\""Program Files"\\""/sh')) + end) + + it('performs unescaping of \\', function() + eq('/\\Program Files\\foo/sh', vim_strnsave_unquoted('/"\\\\"Program Files"\\\\foo"/sh')) + end) + + it('strips quote when there is no pair to it', function() + eq('/Program Files/sh', vim_strnsave_unquoted('/Program" Files/sh')) + eq('', vim_strnsave_unquoted('"')) + end) + + it('allows string to end with one backslash unescaped', function() + eq('/Program Files/sh\\', vim_strnsave_unquoted('/Program" Files/sh\\')) + end) + + it('does not perform unescaping out of quotes', function() + eq('/Program\\ Files/sh\\', vim_strnsave_unquoted('/Program\\ Files/sh\\')) + end) + + it('does not unescape \\n', function() + eq('/Program\\nFiles/sh', vim_strnsave_unquoted('/Program"\\n"Files/sh')) + end) +end) |