Apply small refactor to unit tests

Redefine macro constants as enums in the ffi and import those in their
respective test modules.
This commit is contained in:
Thiago de Arruda
2014-03-04 11:26:37 -03:00
parent 0677e0ee9c
commit 34538a82f3
3 changed files with 44 additions and 31 deletions

View File

@@ -1,13 +1,21 @@
{:cimport, :internalize, :eq, :ffi} = require 'test.unit.helpers'
{:cimport, :internalize, :eq, :ffi, :lib, :cstr} = require 'test.unit.helpers'
misc1 = cimport './src/misc1.h'
cstr = ffi.typeof 'char[?]'
--misc1 = cimport './src/misc1.h'
-- TODO extract constants from vim.h
-- remove these statements once 'cimport' is working properly for misc1.h
misc1 = lib
ffi.cdef [[
enum FPC {
FPC_SAME = 1, FPC_DIFF = 2, FPC_NOTX = 4, FPC_DIFFX = 6, FPC_SAMEX = 7
};
int fullpathcmp(char_u *s1, char_u *s2, int checkname);
]]
-- import constants parsed by ffi
{:FPC_SAME, :FPC_DIFF, :FPC_NOTX, :FPC_DIFFX, :FPC_SAMEX} = lib
describe 'misc1 function', ->
describe 'fullpathcmp', ->
ffi.cdef 'int fullpathcmp(char *s1, char *s2, int checkname);'
fullpathcmp = (s1, s2, cn) ->
s1 = cstr (string.len s1) + 1, s1
@@ -17,12 +25,6 @@ describe 'misc1 function', ->
f1 = 'f1.o'
f2 = 'f2.o'
FPC_SAME = 1
FPC_DIFF = 2
FPC_NOTX = 4
FPC_DIFFX = 6
FPC_SAMEX = 7
before_each ->
-- create the three files that will be used in this spec
(io.open f1, 'w').close!