aboutsummaryrefslogtreecommitdiff
path: root/test/unit/os_unix.moon
blob: 2e817673a4380474fa43ee230d801fb3e820c44b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{:cimport, :eq, :ffi} = require 'test.unit.helpers'

cstr = ffi.typeof 'char[?]'
os = cimport './src/os_unix.h'

describe 'os_unix function', ->
  describe 'mch_isdir', ->
    TRUE = 1
    FALSE = 0

    ffi.cdef('int mch_isdir(char * name);')

    mch_isdir = (name) ->
      name = cstr (string.len name), name
      os.mch_isdir(name)

    setup ->
      lfs.mkdir 'empty-test-directory'
      lfs.touch 'empty-test-directory/test.file'

    teardown ->
      lfs.rmdir 'empty-test-directory'

    it 'returns false if an empty string is given', ->
      eq FALSE, (mch_isdir '')

    it 'returns false if a nonexisting directory is given', ->
      eq FALSE, (mch_isdir 'non-existing-directory')

    it 'returns false if an existing file is given', ->
      eq FALSE, (mch_isdir 'non-existing-directory/test.file')

    it 'returns true if the current directory is given', ->
      eq TRUE, (mch_isdir '.')

    it 'returns true if the parent directory is given', ->
      eq TRUE, (mch_isdir '..')

    it 'returns true if an newly created directory is given', ->
      eq TRUE, (mch_isdir 'empty-test-directory')