]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-surround/spec/vim-surround-spec.coffee
Update vim plugins
[rbdr/dotfiles] / atom / packages / vim-surround / spec / vim-surround-spec.coffee
1 helpers = require './spec-helper'
2
3 describe "Vim Surround activation", ->
4 [editor, pairs, editorElement, vimSurround, configPairs, chars, names] = []
5
6 beforeEach ->
7 pairs = ['()', '{}', '[]', '""', "''"]
8 atom.config.set('vim-surround.pairs', pairs)
9
10 vimSurround = atom.packages.loadPackage('vim-surround')
11 vimSurround.activate()
12
13 configPairs = atom.config.get('vim-surround.pairs')
14
15 helpers.getEditorElement (element) ->
16 editorElement = element
17 editor = editorElement.getModel()
18
19 editorClassList = editorElement.classList
20
21 editorClassList.add('editor')
22 editorClassList.add('vim-mode')
23 editorClassList.add('visual-mode')
24
25
26 describe "When the vim-surround module loads", ->
27 beforeEach ->
28 chars = []
29 pairs.forEach (pair) ->
30 for i in [0..pair.length-1]
31 char = pair[i]
32 chars.push char unless char in chars
33
34 commands = atom.commands.findCommands target: editorElement
35
36 names = []
37 commands.forEach (command) ->
38 names.push(command.name)
39
40 it "Creates a surround command for each configured pair character", ->
41 chars.forEach (char) ->
42 expect(names).toContain("vim-surround:surround-#{char}")
43
44 describe "and the list of pairs changes", ->
45 beforeEach ->
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)
50 chars = []
51 pairs.forEach (pair) ->
52 for i in [0..pair.length-1]
53 char = pair[i]
54 chars.push char unless char in chars
55
56 it "should add any new pairs.", ->
57 chars.forEach (char) ->
58 expect(names).toContain("vim-surround:surround-#{char}")
59
60 it "should remove any old pairs.", ->
61 expect(names).not.toContain("vim-surround:surround-'")
62
63 describe "and then deactivates", ->
64
65 beforeEach ->
66 vimSurround.deactivate()
67 commands = atom.commands.findCommands target: editorElement
68 names = (command.name for command in commands)
69
70 it "should clear out all commands from the registry", ->
71 chars.forEach (char) ->
72 expect(names).not.toContain("vim-surround:surround-#{char}")