diff options
author | Wayne Rowcliffe <war1025@gmail.com> | 2014-07-19 22:51:04 -0500 |
---|---|---|
committer | Wayne Rowcliffe <war1025@gmail.com> | 2014-07-22 05:28:17 -0500 |
commit | 7a2ea275eb5964f4a9b875ca273068fb9b40c81d (patch) | |
tree | bd9347f6efe81084eb4b703f6f5b6bbbaccffdc4 /test/unit/fileio_spec.lua | |
parent | 5941ccab76744d47749b20b948c8534a1972d866 (diff) | |
download | rneovim-7a2ea275eb5964f4a9b875ca273068fb9b40c81d.tar.gz rneovim-7a2ea275eb5964f4a9b875ca273068fb9b40c81d.tar.bz2 rneovim-7a2ea275eb5964f4a9b875ca273068fb9b40c81d.zip |
Add tests for buffer.c and fileio.c
Diffstat (limited to 'test/unit/fileio_spec.lua')
-rw-r--r-- | test/unit/fileio_spec.lua | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/test/unit/fileio_spec.lua b/test/unit/fileio_spec.lua new file mode 100644 index 0000000000..180fc3c184 --- /dev/null +++ b/test/unit/fileio_spec.lua @@ -0,0 +1,83 @@ +local helpers = require("test.unit.helpers") +--{:cimport, :internalize, :eq, :neq, :ffi, :lib, :cstr, :to_cstr} = require 'test.unit.helpers' + +local eq = helpers.eq +local ffi = helpers.ffi +local to_cstr = helpers.to_cstr + +local fileio = helpers.cimport("./src/nvim/fileio.h") + +describe('file_pat functions', function() + describe('file_pat_to_reg_pat', function() + + local file_pat_to_reg_pat = function(pat) + local res = fileio.file_pat_to_reg_pat(to_cstr(pat), NULL, NULL, 0) + return ffi.string(res) + end + + it('returns ^path$ regex for literal path input', function() + eq( '^path$', file_pat_to_reg_pat('path')) + end) + + it('does not prepend ^ when there is a starting glob (*)', function() + eq('path$', file_pat_to_reg_pat('*path')) + end) + + it('does not append $ when there is an ending glob (*)', function() + eq('^path', file_pat_to_reg_pat('path*')) + end) + + it('does not include ^ or $ when surrounded by globs (*)', function() + eq('path', file_pat_to_reg_pat('*path*')) + end) + + it('replaces the bash any character (?) with the regex any character (.)', function() + eq('^foo.bar$', file_pat_to_reg_pat('foo?bar')) + end) + + it('replaces a glob (*) in the middle of a path with regex multiple any character (.*)', + function() + eq('^foo.*bar$', file_pat_to_reg_pat('foo*bar')) + end) + + it([[unescapes \? to ?]], function() + eq('^foo?bar$', file_pat_to_reg_pat([[foo\?bar]])) + end) + + it([[unescapes \% to %]], function() + eq('^foo%bar$', file_pat_to_reg_pat([[foo\%bar]])) + end) + + it([[unescapes \, to ,]], function() + eq('^foo,bar$', file_pat_to_reg_pat([[foo\,bar]])) + end) + + it([[unescapes '\ ' to ' ']], function() + eq('^foo bar$', file_pat_to_reg_pat([[foo\ bar]])) + end) + + it([[escapes . to \.]], function() + eq([[^foo\.bar$]], file_pat_to_reg_pat('foo.bar')) + end) + + it('Converts bash brace expansion {a,b} to regex options (a|b)', function() + eq([[^foo\(bar\|baz\)$]], file_pat_to_reg_pat('foo{bar,baz}')) + end) + + it('Collapses multiple consecutive * into a single character', function() + eq([[^foo.*bar$]], file_pat_to_reg_pat('foo*******bar')) + eq([[foobar$]], file_pat_to_reg_pat('********foobar')) + eq([[^foobar]], file_pat_to_reg_pat('foobar********')) + end) + + it('Does not escape ^', function() + eq([[^^blah$]], file_pat_to_reg_pat('^blah')) + eq([[^foo^bar$]], file_pat_to_reg_pat('foo^bar')) + end) + + it('Does not escape $', function() + eq([[^blah$$]], file_pat_to_reg_pat('blah$')) + eq([[^foo$bar$]], file_pat_to_reg_pat('foo$bar')) + end) + end) +end) |