diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-08-30 11:47:55 -0300 |
---|---|---|
committer | Nicolas Hillegeer <nicolas@hillegeer.com> | 2014-08-31 14:50:49 +0200 |
commit | d74ae5be9de985eee3e5026ffe0c639161ce82fc (patch) | |
tree | 798a2f126feaf40d490664e07c672100d0f3519b | |
parent | df50d242f5915621d41fc4f634d5ea1b0c7863b0 (diff) | |
download | rneovim-d74ae5be9de985eee3e5026ffe0c639161ce82fc.tar.gz rneovim-d74ae5be9de985eee3e5026ffe0c639161ce82fc.tar.bz2 rneovim-d74ae5be9de985eee3e5026ffe0c639161ce82fc.zip |
unittest: convert users_spec.moon to lua
-rw-r--r-- | test/unit/os/users_spec.lua | 91 | ||||
-rw-r--r-- | test/unit/os/users_spec.moon | 70 |
2 files changed, 91 insertions, 70 deletions
diff --git a/test/unit/os/users_spec.lua b/test/unit/os/users_spec.lua new file mode 100644 index 0000000000..df5d2365c6 --- /dev/null +++ b/test/unit/os/users_spec.lua @@ -0,0 +1,91 @@ +local helpers = require('test.unit.helpers') + +local cimport = helpers.cimport +local internalize = helpers.internalize +local eq = helpers.eq +local ffi = helpers.ffi +local lib = helpers.lib +local cstr = helpers.cstr +local NULL = helpers.NULL +local OK = helpers.OK +local FAIL = helpers.FAIL + +local users = cimport('./src/nvim/os/os.h', 'unistd.h') + +function garray_new() + return ffi.new('garray_T[1]') +end + +function garray_get_len(array) + return array[0].ga_len +end + +function garray_get_item(array, index) + return (ffi.cast('void **', array[0].ga_data))[index] +end + +describe('users function', function() + -- will probably not work on windows + local current_username = os.getenv('USER') + + describe('os_get_usernames', function() + it('returns FAIL if called with NULL', function() + eq(FAIL, users.os_get_usernames(NULL)) + end) + + it('fills the names garray with os usernames and returns OK', function() + local ga_users = garray_new() + eq(OK, users.os_get_usernames(ga_users)) + local user_count = garray_get_len(ga_users) + assert.is_true(user_count > 0) + local current_username_found = false + for i = 0, user_count - 1 do + local name = ffi.string((garray_get_item(ga_users, i))) + if name == current_username then + current_username_found = true + end + end + assert.is_true(current_username_found) + end) + end) + + describe('os_get_user_name', function() + it('should write the username into the buffer and return OK', function() + local name_out = ffi.new('char[100]') + eq(OK, users.os_get_user_name(name_out, 100)) + eq(current_username, ffi.string(name_out)) + end) + end) + + describe('os_get_uname', function() + it('should write the username into the buffer and return OK', function() + local name_out = ffi.new('char[100]') + local user_id = lib.getuid() + eq(OK, users.os_get_uname(user_id, name_out, 100)) + eq(current_username, ffi.string(name_out)) + end) + + it('should FAIL if the userid is not found', function() + local name_out = ffi.new('char[100]') + -- hoping nobody has this uid + local user_id = 2342 + eq(FAIL, users.os_get_uname(user_id, name_out, 100)) + eq('2342', ffi.string(name_out)) + end) + end) + + describe('os_get_user_directory', function() + it('should return NULL if called with NULL', function() + eq(NULL, users.os_get_user_directory(NULL)) + end) + + it('should return $HOME for the current user', function() + local home = os.getenv('HOME') + eq(home, ffi.string((users.os_get_user_directory(current_username)))) + end) + + it('should return NULL if the user is not found', function() + eq(NULL, users.os_get_user_directory('neovim_user_not_found_test')) + end) + end) +end) diff --git a/test/unit/os/users_spec.moon b/test/unit/os/users_spec.moon deleted file mode 100644 index 35c23ccc6f..0000000000 --- a/test/unit/os/users_spec.moon +++ /dev/null @@ -1,70 +0,0 @@ -{:cimport, :internalize, :eq, :ffi, :lib, :cstr, :NULL, :OK, :FAIL} = require 'test.unit.helpers' - -users = cimport './src/nvim/os/os.h', 'unistd.h' - -garray_new = () -> - ffi.new 'garray_T[1]' - -garray_get_len = (array) -> - array[0].ga_len - -garray_get_item = (array, index) -> - (ffi.cast 'void **', array[0].ga_data)[index] - - -describe 'users function', -> - - -- will probably not work on windows - current_username = os.getenv 'USER' - - describe 'os_get_usernames', -> - - it 'returns FAIL if called with NULL', -> - eq FAIL, users.os_get_usernames NULL - - it 'fills the names garray with os usernames and returns OK', -> - ga_users = garray_new! - eq OK, users.os_get_usernames ga_users - user_count = garray_get_len ga_users - assert.is_true user_count > 0 - current_username_found = false - for i = 0, user_count - 1 - name = ffi.string (garray_get_item ga_users, i) - if name == current_username - current_username_found = true - assert.is_true current_username_found - - describe 'os_get_user_name', -> - - it 'should write the username into the buffer and return OK', -> - name_out = ffi.new 'char[100]' - eq OK, users.os_get_user_name(name_out, 100) - eq current_username, ffi.string name_out - - describe 'os_get_uname', -> - - it 'should write the username into the buffer and return OK', -> - name_out = ffi.new 'char[100]' - user_id = lib.getuid! - eq OK, users.os_get_uname(user_id, name_out, 100) - eq current_username, ffi.string name_out - - it 'should FAIL if the userid is not found', -> - name_out = ffi.new 'char[100]' - -- hoping nobody has this uid - user_id = 2342 - eq FAIL, users.os_get_uname(user_id, name_out, 100) - eq '2342', ffi.string name_out - - describe 'os_get_user_directory', -> - - it 'should return NULL if called with NULL', -> - eq NULL, users.os_get_user_directory NULL - - it 'should return $HOME for the current user', -> - home = os.getenv('HOME') - eq home, ffi.string (users.os_get_user_directory current_username) - - it 'should return NULL if the user is not found', -> - eq NULL, users.os_get_user_directory 'neovim_user_not_found_test' - |