Skip to content

Commit

Permalink
Add spec for wrapSelectionInBrackets and backspace
Browse files Browse the repository at this point in the history
  • Loading branch information
fstiewitz committed Mar 31, 2016
1 parent 26d598d commit 58a029f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/bracket-matcher.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class BracketMatcher
"": ""

toggleQuotes: (includeSmartQuotes) ->
return if @pairedCharacters? and includeSmartQuotes is (@pairedCharacters isnt @defaultPairs)
if includeSmartQuotes
@pairedCharacters = _.extend({}, @defaultPairs, @smartQuotePairs)
else
Expand Down
29 changes: 27 additions & 2 deletions spec/bracket-matcher-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ describe "bracket matching", ->
expect(editor.getSelectedBufferRange()).toEqual [[0, 1], [0, 5]]
expect(editor.getLastSelection().isReversed()).toBeTruthy()

describe "when the bracket-matcher.wrapSelectionsInBrackets is falsy", ->
describe "when the bracket-matcher.wrapSelectionsInBrackets is falsy globally", ->
it "does not wrap the selection in brackets", ->
atom.config.set('bracket-matcher.wrapSelectionsInBrackets', false)
editor.setText 'text'
Expand All @@ -677,6 +677,18 @@ describe "bracket matching", ->
expect(buffer.getText()).toBe '('
expect(editor.getSelectedBufferRange()).toEqual [[0, 1], [0, 1]]

describe "when the bracket-matcher.wrapSelectionsInBrackets is falsy in scope", ->
it "does not wrap the selection in brackets", ->
atom.config.set('bracket-matcher.wrapSelectionsInBrackets', true)
atom.config.set('bracket-matcher.wrapSelectionsInBrackets', false, scopeSelector: '.source.js')
editor.setText 'text'
editor.moveToBottom()
editor.selectToTop()
editor.selectAll()
editor.insertText '('
expect(buffer.getText()).toBe '('
expect(editor.getSelectedBufferRange()).toEqual [[0, 1], [0, 1]]

describe "when there is text selected on multiple lines", ->
it "wraps the selection with brackets", ->
editor.insertText 'text\nabcd'
Expand Down Expand Up @@ -921,7 +933,7 @@ describe "bracket matching", ->
editor.backspace()
expect(buffer.lineForRow(0)).toBe ""

it "does not delete end bracket even if it directly precedes a begin bracket if autocomplete is turned off", ->
it "does not delete end bracket even if it directly precedes a begin bracket if autocomplete is turned off globally", ->
atom.config.set 'bracket-matcher.autocompleteBrackets', false
buffer.setText("")
editor.setCursorBufferPosition([0, 0])
Expand All @@ -933,6 +945,19 @@ describe "bracket matching", ->
editor.backspace()
expect(buffer.lineForRow(0)).toBe "}"

it "does not delete end bracket even if it directly precedes a begin bracket if autocomplete is turned off in scope", ->
atom.config.set 'bracket-matcher.autocompleteBrackets', true
atom.config.set 'bracket-matcher.autocompleteBrackets', false, scopeSelector: '.source.js'
buffer.setText("")
editor.setCursorBufferPosition([0, 0])
editor.insertText "{"
expect(buffer.lineForRow(0)).toBe "{"
editor.insertText "}"
expect(buffer.lineForRow(0)).toBe "{}"
editor.setCursorBufferPosition([0, 1])
editor.backspace()
expect(buffer.lineForRow(0)).toBe "}"

describe 'bracket-matcher:close-tag', ->
beforeEach ->
waitsForPromise ->
Expand Down

0 comments on commit 58a029f

Please sign in to comment.