aboutsummaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
authorStefan Hoffmann <stefan991@gmail.com>2014-03-06 21:55:17 +0100
committerThiago de Arruda <tpadilha84@gmail.com>2014-03-13 17:18:43 -0300
commit6fd9f090fc66c3ba38dc07ea6c982c3124735f32 (patch)
tree052b7d267c182c9975fb2b3e837cef66b0a166b4 /test/unit
parentf6ace9962d95eb12236083871154c1501f02c556 (diff)
downloadrneovim-6fd9f090fc66c3ba38dc07ea6c982c3124735f32.tar.gz
rneovim-6fd9f090fc66c3ba38dc07ea6c982c3124735f32.tar.bz2
rneovim-6fd9f090fc66c3ba38dc07ea6c982c3124735f32.zip
refactored logic from init_users() into mch_get_usernames()
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/os/users.moon52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/unit/os/users.moon b/test/unit/os/users.moon
new file mode 100644
index 0000000000..366407d5c8
--- /dev/null
+++ b/test/unit/os/users.moon
@@ -0,0 +1,52 @@
+{:cimport, :internalize, :eq, :ffi, :lib, :cstr} = require 'test.unit.helpers'
+
+-- fs = cimport './src/os/os.h'
+-- remove these statements once 'cimport' is working properly for misc1.h
+users = lib
+ffi.cdef [[
+typedef struct growarray {
+ int ga_len;
+ int ga_maxlen;
+ int ga_itemsize;
+ int ga_growsize;
+ void *ga_data;
+} garray_T;
+int mch_get_usernames(garray_T *usernames);
+]]
+
+NULL = ffi.cast 'void*', 0
+OK = 1
+FAIL = 0
+
+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', ->
+
+ describe 'mch_get_usernames', ->
+
+ -- will probably not work on windows
+ current_username = os.getenv 'USER'
+
+ it 'returns FAIL if called with NULL', ->
+ eq FAIL, users.mch_get_usernames NULL
+
+ it 'fills the names garray with os usernames and returns OK', ->
+ ga_users = garray_new!
+ eq OK, users.mch_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
+