diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2016-05-29 13:10:26 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2016-05-29 13:10:26 -0400 |
commit | 748898b4dd992c5a5d15a0e1f9f047fc42ba4fd3 (patch) | |
tree | ed1e80ccb3a40bede403d3a230df0b2f7f98b3cf | |
parent | ecbc9dbdfeebc3593f178127f44ef979b446b633 (diff) | |
parent | c7934233742fd2191ec11c6bb74c9c82c43538b5 (diff) | |
download | rneovim-748898b4dd992c5a5d15a0e1f9f047fc42ba4fd3.tar.gz rneovim-748898b4dd992c5a5d15a0e1f9f047fc42ba4fd3.tar.bz2 rneovim-748898b4dd992c5a5d15a0e1f9f047fc42ba4fd3.zip |
Merge pull request #4198 from daynin/string-tests
tests: add tests for vim_strsave_escaped() function
-rw-r--r-- | test/unit/strings_spec.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/unit/strings_spec.lua b/test/unit/strings_spec.lua index e935d2af6a..0034670ee8 100644 --- a/test/unit/strings_spec.lua +++ b/test/unit/strings_spec.lua @@ -8,6 +8,38 @@ local to_cstr = helpers.to_cstr local strings = cimport('stdlib.h', './src/nvim/strings.h', './src/nvim/memory.h') +describe('vim_strsave_escaped()', function() + local vim_strsave_escaped = function(s, chars) + local res = strings.vim_strsave_escaped(to_cstr(s), to_cstr(chars)) + 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('precedes by a backslash all chars from second argument', function() + eq([[\a\b\c\d]], vim_strsave_escaped('abcd','abcd')) + end) + + it('precedes by a backslash chars only from second argument', function() + eq([[\a\bcd]], vim_strsave_escaped('abcd','ab')) + end) + + it('returns a copy of passed string if second argument is empty', function() + eq('text \n text', vim_strsave_escaped('text \n text','')) + end) + + it('returns an empty string if first argument is empty string', function() + eq('', vim_strsave_escaped('','\r')) + end) + + it('returns a copy of passed string if it does not contain chars from 2nd argument', function() + eq('some text', vim_strsave_escaped('some text', 'a')) + end) +end) + describe('vim_strnsave_unquoted()', function() local vim_strnsave_unquoted = function(s, len) local res = strings.vim_strnsave_unquoted(to_cstr(s), len or #s) |