1 helpers = require './spec-helper'
3 describe "Vim Surround activation", ->
4 [editor, pairs, editorElement, vimSurround, configPairs, chars, names] = []
7 pairs = ['()', '{}', '[]', '""', "''"]
8 atom.config.set('vim-surround.pairs', pairs)
10 vimSurround = atom.packages.loadPackage('vim-surround')
11 vimSurround.activate()
13 configPairs = atom.config.get('vim-surround.pairs')
15 helpers.getEditorElement (element) ->
16 editorElement = element
17 editor = editorElement.getModel()
19 editorClassList = editorElement.classList
21 editorClassList.add('editor')
22 editorClassList.add('vim-mode')
23 editorClassList.add('visual-mode')
26 describe "When the vim-surround module loads", ->
29 pairs.forEach (pair) ->
30 for i in [0..pair.length-1]
32 chars.push char unless char in chars
34 commands = atom.commands.findCommands target: editorElement
37 commands.forEach (command) ->
38 names.push(command.name)
40 it "Creates a surround command for each configured pair character", ->
41 chars.forEach (char) ->
42 expect(names).toContain("vim-surround:surround-#{char}")
44 describe "and the list of pairs changes", ->
46 pairs = ['()', '{}', '[]', '""', "-+"]
47 atom.config.set('vim-surround.pairs', pairs)
48 commands = atom.commands.findCommands target: editorElement
49 names = (command.name for command in commands)
51 pairs.forEach (pair) ->
52 for i in [0..pair.length-1]
54 chars.push char unless char in chars
56 it "should add any new pairs.", ->
57 chars.forEach (char) ->
58 expect(names).toContain("vim-surround:surround-#{char}")
60 it "should remove any old pairs.", ->
61 expect(names).not.toContain("vim-surround:surround-'")
63 describe "and then deactivates", ->
66 vimSurround.deactivate()
67 commands = atom.commands.findCommands target: editorElement
68 names = (command.name for command in commands)
70 it "should clear out all commands from the registry", ->
71 chars.forEach (char) ->
72 expect(names).not.toContain("vim-surround:surround-#{char}")