aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/runtime_spec.lua
blob: 7286e89c765e9b75435d9fd8f459cb9e896fc460 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
local helpers = require('test.functional.helpers')(after_each)

local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
local exec = helpers.exec
local mkdir_p = helpers.mkdir_p
local rmdir = helpers.rmdir
local write_file = helpers.write_file

describe('runtime:', function()
  local xhome = 'Xhome'
  local pathsep = helpers.get_pathsep()
  local xconfig = xhome .. pathsep .. 'Xconfig'

  before_each(function()
    clear()
    mkdir_p(xconfig .. pathsep .. 'nvim')
  end)

  after_each(function()
    rmdir(xhome)
  end)

  describe('plugin', function()
    before_each(clear)
    it('loads plugin/*.lua from XDG config home', function()
      local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep)
      local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep)
      mkdir_p(plugin_folder_path)
      write_file(plugin_file_path, [[ vim.g.lua_plugin = 1 ]])

      clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}

      eq(1, eval('g:lua_plugin'))
      rmdir(plugin_folder_path)
    end)


    it('loads plugin/*.lua from start plugins', function()
      local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'catagory',
      'start', 'test_plugin'}, pathsep)
      local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep)
      local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'},
      pathsep)
      mkdir_p(plugin_folder_path)
      write_file(plugin_file_path, [[vim.g.lua_plugin = 2]])

      clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}

      eq(2, eval('g:lua_plugin'))
      rmdir(plugin_path)
    end)
  end)

  describe('colors', function()
    before_each(clear)
    it('loads lua colorscheme', function()
      local colorscheme_folder = table.concat({xconfig, 'nvim', 'colors'},
                                                   pathsep)
      local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme.lua'},
                                            pathsep)
      mkdir_p(colorscheme_folder)
      write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]])

      clear{ args_rm={'-' }, env={ XDG_CONFIG_HOME=xconfig }}
      exec('colorscheme new_colorscheme')

      eq(1, eval('g:lua_colorscheme'))
      rmdir(colorscheme_folder)
    end)

    it('loads vim colorscheme when both lua and vim version exist', function()
      local colorscheme_folder = table.concat({xconfig, 'nvim', 'colors'},
                                                   pathsep)
      local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme'},
                                            pathsep)
      mkdir_p(colorscheme_folder)
      write_file(colorscheme_file..'.vim', [[let g:colorscheme = 'vim']])
      write_file(colorscheme_file..'.lua', [[vim.g.colorscheme = 'lua']])

      clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}
      exec('colorscheme new_colorscheme')

      eq('vim', eval('g:colorscheme'))
      rmdir(colorscheme_folder)
    end)
  end)

  describe('compiler', function()
    local compiler_folder = table.concat({xconfig, 'nvim', 'compiler'}, pathsep)
    before_each(clear)

    it('loads lua compilers', function()
      local compiler_file = table.concat({compiler_folder, 'new_compiler.lua'},
                                            pathsep)
      mkdir_p(compiler_folder)
      write_file(compiler_file, [[vim.g.lua_compiler = 1]])

      clear{ args_rm={'-' }, env={ XDG_CONFIG_HOME=xconfig }}
      exec('compiler new_compiler')

      eq(1, eval('g:lua_compiler'))
      rmdir(compiler_folder)
    end)

    it('loads vim compilers when both lua and vim version exist', function()
      local compiler_file = table.concat({compiler_folder, 'new_compiler'},
                                            pathsep)
      mkdir_p(compiler_folder)
      write_file(compiler_file..'.vim', [[let g:compiler = 'vim']])
      write_file(compiler_file..'.lua', [[vim.g.compiler = 'lua']])

      clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}
      exec('compiler new_compiler')

      eq('vim', eval('g:compiler'))
      rmdir(compiler_folder)
    end)
  end)

  describe('ftplugin', function()
    local ftplugin_folder = table.concat({xconfig, 'nvim', 'ftplugin'}, pathsep)

    before_each(clear)

    it('loads lua ftplugins', function()
      local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, pathsep)
      mkdir_p(ftplugin_folder)
      write_file(ftplugin_file , [[vim.g.lua_ftplugin = 1]])

      clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }}

      exec [[set filetype=new-ft]]
      eq(1, eval('g:lua_ftplugin'))
      rmdir(ftplugin_folder)
    end)
  end)

  describe('indent', function()
    local indent_folder = table.concat({xconfig, 'nvim', 'indent'}, pathsep)

    before_each(clear)

    it('loads lua indents', function()
      local indent_file = table.concat({indent_folder , 'new-ft.lua'}, pathsep)
      mkdir_p(indent_folder)
      write_file(indent_file , [[vim.g.lua_indent = 1]])

      clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }}

      exec [[set filetype=new-ft]]
      eq(1, eval('g:lua_indent'))
      rmdir(indent_folder)
    end)
  end)

  describe('ftdetect', function()
    local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep)

    before_each(clear)

    it('loads lua ftdetects', function()
      local ftdetect_file = table.concat({ftdetect_folder , 'new-ft.lua'}, pathsep)
      mkdir_p(ftdetect_folder)
      write_file(ftdetect_file , [[vim.g.lua_ftdetect = 1]])

      clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }}

      eq(1, eval('g:lua_ftdetect'))
      rmdir(ftdetect_folder)
    end)
  end)

end)