       buffer = editor.getBuffer()
 
   describe "matching bracket highlighting", ->
+    expectNoHighlights = ->
+      expect(editorView.underlayer.find('.bracket-matcher:visible')).not.toExist()
+
+    expectHighlights = (startBufferPosition, endBufferPosition) ->
+      highlights = editorView.underlayer.find('.bracket-matcher:visible')
+      expect(highlights.length).toBe(2)
+
+      expect(highlights.eq(0).position()).toEqual(editor.pixelPositionForBufferPosition(startBufferPosition))
+      expect(highlights.eq(0).width()).toBeGreaterThan(0)
+      expect(highlights.eq(0).height()).toBeGreaterThan(0)
+
+      expect(highlights.eq(1).position()).toEqual(editor.pixelPositionForBufferPosition(endBufferPosition))
+      expect(highlights.eq(1).width()).toBeGreaterThan(0)
+      expect(highlights.eq(1).height()).toBeGreaterThan(0)
+
     describe "when the cursor is before a starting pair", ->
       it "highlights the starting pair and ending pair", ->
         editor.moveToEndOfLine()
         editor.moveLeft()
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
-        expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([0,28])
-        expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([12,0])
-
-        expect(editorView.underlayer.find('.bracket-matcher:first').width()).toBeGreaterThan 0
-        expect(editorView.underlayer.find('.bracket-matcher:last').width()).toBeGreaterThan 0
-        expect(editorView.underlayer.find('.bracket-matcher:first').height()).toBeGreaterThan 0
-        expect(editorView.underlayer.find('.bracket-matcher:last').height()).toBeGreaterThan 0
+        expectHighlights([0,28], [12,0])
 
     describe "when the cursor is after a starting pair", ->
       it "highlights the starting pair and ending pair", ->
         editor.moveToEndOfLine()
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
-        expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([0,28])
-        expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([12,0])
+        expectHighlights([0,28], [12,0])
 
     describe "when the cursor is before an ending pair", ->
       it "highlights the starting pair and ending pair", ->
         editor.moveToBottom()
         editor.moveLeft()
         editor.moveLeft()
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
-        expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([12,0])
-        expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([0,28])
+        expectHighlights([12,0], [0,28])
 
     describe "when the cursor is after an ending pair", ->
       it "highlights the starting pair and ending pair", ->
         editor.moveToBottom()
         editor.moveLeft()
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
-        expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([12,0])
-        expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([0,28])
+        expectHighlights([12,0], [0,28])
 
     describe "when there are unpaired brackets", ->
       it "highlights the correct start/end pairs", ->
         editor.setText '(()'
         editor.setCursorBufferPosition([0,0])
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 0
+        expectNoHighlights()
 
         editor.setCursorBufferPosition([0,1])
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
-        expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([0,1])
-        expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([0,2])
+        expectHighlights([0,1], [0,2])
 
         editor.setCursorBufferPosition([0,2])
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
-        expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([0,1])
-        expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([0,2])
+        expectHighlights([0,1], [0,2])
 
         editor.setText ('())')
         editor.setCursorBufferPosition([0,0])
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
-        expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([0,0])
-        expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([0,1])
+        expectHighlights([0,0], [0,1])
 
         editor.setCursorBufferPosition([0,1])
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
-        expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([0,0])
-        expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([0,1])
+        expectHighlights([0,0], [0,1])
 
         editor.setCursorBufferPosition([0,2])
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 0
+        expectNoHighlights()
 
     describe "when the cursor is moved off a pair", ->
       it "removes the starting pair and ending pair highlights", ->
         editor.moveToEndOfLine()
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
+        expectHighlights([0,28], [12,0])
+
         editor.moveToBeginningOfLine()
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 0
+        expectNoHighlights()
 
     describe "when the pair moves", ->
       it "repositions the highlights", ->
         editor.moveToEndOfLine()
         editor.moveLeft()
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
+        expectHighlights([0,28], [12,0])
+
         editor.deleteToBeginningOfLine()
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
+        expectHighlights([0,0], [12,0])
 
     describe "when the font size changes", ->
       it "repositions the highlights", ->
         editor.moveToBottom()
         editor.moveLeft()
         atom.config.set('editor.fontSize', editorView.getFontSize() + 10)
-        expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
-        expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([12,0])
-        expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([0,28])
+        expectHighlights([12,0], [0,28])
 
     describe "when the soft wrap setting changes on the editor", ->
       it "repositions the highlights", ->

          """

          editor.setCursorBufferPosition([2,2])
          expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
          expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([2,2])
          expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([0,1])

          editor.setCursorBufferPosition([0,7])
          expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
          expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([0,1])
          expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([2,2])

      describe "when the opening and closing tags are on the same line", ->
        it "highlight the opening and closing tags", ->
          buffer.setText "<test>text</test>"

          editor.setCursorBufferPosition([0,2])
          expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
          expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([0,1])
          expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([0,12])

          editor.setCursorBufferPosition([0,12])
          expect(editorView.underlayer.find('.bracket-matcher:visible').length).toBe 2
          expect(editorView.underlayer.find('.bracket-matcher:first').position()).toEqual editor.pixelPositionForBufferPosition([0,12])
          expect(editorView.underlayer.find('.bracket-matcher:last').position()).toEqual editor.pixelPositionForBufferPosition([0,1])

  describe "when bracket-matcher:go-to-matching-bracket is triggered", ->
    describe "when the cursor is before the starting pair", ->

          """

          editor.setCursorBufferPosition([0,0])
          expectHighlights([0,1], [3,2])

          editor.setCursorBufferPosition([0,1])
          expectHighlights([0,1], [3,2])

      describe "when on a closing tag", ->
        it "highlight the opening and closing tag", ->
