 Range = require 'range'
 _ = require 'underscore'
 
-describe "LineWrapper", ->
+fdescribe "LineWrapper", ->
   [wrapper, buffer] = []
 
   beforeEach ->
     buffer = new Buffer(require.resolve('fixtures/sample.js'))
     wrapper = new LineWrapper(50, new Highlighter(buffer))
 
-  describe ".screenLinesForBufferRow(bufferRow)", ->
-    it "returns an array of tokens for each screen line associated with the buffer row", ->
-      wrapper.setMaxLength(30)
-      screenLines = wrapper.wrappedLines[6].screenLines
-
-      expect(screenLines.length).toBe 3
-      [line1, line2, line3] = screenLines
-
-      # TODO: Get this working again after finalizing split tokens
-      # expect(line1.endColumn).toBe 24
-      # expect(tokensText(line1)).toBe '      current < pivot ? '
-
-      # expect(line2.endColumn).toBe 45
-      # expect(tokensText(line2)).toBe 'left.push(current) : '
-
-      # expect(line3.endColumn).toBe 65
-      # expect(tokensText(line3)).toBe 'right.push(current);'
+  describe ".tokensForScreenRow(row)", ->
+    it "returns tokens for the line fragment corresponding to the given screen row", ->
+      expect(tokensText wrapper.tokensForScreenRow(3)).toEqual('    var pivot = items.shift(), current, left = [], ')
+      expect(tokensText wrapper.tokensForScreenRow(4)).toEqual('right = [];')
+      expect(tokensText wrapper.tokensForScreenRow(5)).toEqual('    while(items.length > 0) {')
 
   describe "when the buffer changes", ->
     changeHandler = null


    describe "when buffer lines are removed", ->

    describe "when an unwrapped line is updated", ->
      describe "when the update does not cause the line to wrap", ->
        it "updates tokens for the corresponding screen line and emits a change event", ->
          buffer.insert([0, 10], 'h')
          expect(tokensText(wrapper.tokensForScreenRow(0))).toContain 'quickshort'

          expect(changeHandler).toHaveBeenCalled()
          [event] = changeHandler.argsForCall[0]
          expect(event.oldRange).toEqual(new Range([0, 10], [0, 10]))
          expect(event.newRange).toEqual(new Range([0, 10], [0, 11]))
          changeHandler.reset()

          # below a wrapped line
          buffer.insert([4, 10], 'foo')
          expect(tokensText(wrapper.tokensForScreenRow(5))).toContain 'fooitems'
          expect(changeHandler).toHaveBeenCalled()
          [event] = changeHandler.argsForCall[0]
          expect(event.oldRange).toEqual(new Range([5, 10], [5, 10]))
          expect(event.newRange).toEqual(new Range([5, 10], [5, 13]))


      describe "when the update causes the line to wrap once", ->
        it "updates tokens for the corresponding screen lines and emits a change event", ->
          buffer.insert([2, 4], longText)
          expect(tokensText(wrapper.tokensForScreenRow(2))).toBe '    0123456789ABCDEFif (items.length <= 1) return '
          expect(tokensText(wrapper.tokensForScreenRow(3))).toBe 'items;'
          expect(tokensText(wrapper.tokensForScreenRow(4))).toBe '    var pivot = items.shift(), current, left = [], '

          expect(changeHandler).toHaveBeenCalled()
          [event] = changeHandler.argsForCall[0]
          expect(event.oldRange).toEqual(new Range([2, 4], [2, 4]))
          expect(event.newRange).toEqual(new Range([2, 4], [3, 6]))

      describe "when the update causes the line to wrap multiple times", ->
        it "updates tokens for the corresponding screen lines and emits a change event", ->
          buffer.insert([2, 4], ["/*",longText, longText, longText, longText, "*/"].join(' '))
          expect(tokensText(wrapper.tokensForScreenRow(2))).toBe '    /* 0123456789ABCDEF 0123456789ABCDEF '
          expect(tokensText(wrapper.tokensForScreenRow(3))).toBe '0123456789ABCDEF 0123456789ABCDEF */if '
          expect(tokensText(wrapper.tokensForScreenRow(4))).toBe '(items.length <= 1) return items;'
          expect(tokensText(wrapper.tokensForScreenRow(5))).toBe '    var pivot = items.shift(), current, left = [], '

          expect(changeHandler).toHaveBeenCalled()
          [event] = changeHandler.argsForCall[0]
          expect(event.oldRange).toEqual(new Range([2, 4], [2, 4]))
          expect(event.newRange).toEqual(new Range([2, 4], [4, 33]))

    describe "when a wrapped line is updated", ->
      describe "when the old text spans multiple screen lines", ->
        describe "when the new text spans fewer screen lines than the old text", ->
          it "updates tokens for the corresponding screen lines and emits a change event", ->
            wrapper.setMaxLength(15)

            range = new Range([3, 8], [3, 47])
            buffer.change(range, "a")
            expect(tokensText(wrapper.tokensForScreenRow(9))).toBe '    var a [], '
            expect(tokensText(wrapper.tokensForScreenRow(10))).toBe 'right = [];'
            expect(tokensText(wrapper.tokensForScreenRow(11))).toBe '    '

            expect(changeHandler).toHaveBeenCalled()
            [event] = changeHandler.argsForCall[0]
            expect(event.oldRange).toEqual [[9, 8], [11, 16]]
            expect(event.newRange).toEqual [[9, 8], [9, 9]]

        describe "when the new text spans as many screen lines than the old text", ->
          it "updates tokens for the corresponding screen lines and emits a change event", ->
            range = new Range([3, 40], [3, 57])
            buffer.change(range, text10)
            expect(tokensText(wrapper.tokensForScreenRow(3))).toBe '    var pivot = items.shift(), current, '
            expect(tokensText(wrapper.tokensForScreenRow(4))).toBe '0123456789= [];'
            expect(tokensText(wrapper.tokensForScreenRow(5))).toBe '    while(items.length > 0) {'

            expect(changeHandler).toHaveBeenCalled()
            [event] = changeHandler.argsForCall[0]
            expect(event.oldRange).toEqual [[3, 40], [4, 6]]
            expect(event.newRange).toEqual [[3, 40], [4, 10]]

        describe "when the new text spans more screen lines than the old text", ->
          it "updates tokens for the corresponding screen lines and emits a change event", ->
            range = new Range([3, 40], [3, 57])
            buffer.change(range, text60)
            expect(tokensText(wrapper.tokensForScreenRow(3))).toBe '    var pivot = items.shift(), current, 0123456789 '
            expect(tokensText(wrapper.tokensForScreenRow(4))).toBe '123456789 123456789 123456789 123456789 123456789= '
            expect(tokensText(wrapper.tokensForScreenRow(5))).toBe '[];'
            expect(tokensText(wrapper.tokensForScreenRow(6))).toBe '    while(items.length > 0) {'

            expect(changeHandler).toHaveBeenCalled()
            [event] = changeHandler.argsForCall[0]
            expect(event.oldRange).toEqual [[3, 40], [4, 6]]
            expect(event.newRange).toEqual [[3, 40], [5, 3]]

    describe "when a line is inserted", ->
      describe "when the line is wrapped", ->

      describe "when the line is not wrapped", ->

    describe "when a line is removed", ->
      describe "when the line is wrapped", ->

      describe "when the line is not wrapped", ->

  describe ".tokensForScreenRow(row)", ->
    it "returns tokens for the line fragment corresponding to the given screen row", ->
      expect(wrapper.tokensForScreenRow(3)).toEqual(wrapper.wrappedLines[3].screenLines[0])
      expect(wrapper.tokensForScreenRow(4)).toEqual(wrapper.wrappedLines[3].screenLines[1])
      expect(wrapper.tokensForScreenRow(5)).toEqual(wrapper.wrappedLines[4].screenLines[0])

  describe ".splitTokens(tokens)", ->
    makeTokens = (array) ->

          expect(line2.endColumn).toBe 14
          expect(line2.textLength).toBe 3

