2012-02-17 07:52:12 +04:00
|
|
|
_ = require 'underscore'
|
|
|
|
Buffer = require 'buffer'
|
|
|
|
Highlighter = require 'highlighter'
|
|
|
|
|
|
|
|
describe "screenLineFragment", ->
|
2012-02-22 21:27:49 +04:00
|
|
|
[screenLine, highlighter] = []
|
2012-02-17 07:52:12 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
buffer = new Buffer(require.resolve 'fixtures/sample.js')
|
|
|
|
highlighter = new Highlighter(buffer)
|
2012-02-23 04:24:27 +04:00
|
|
|
screenLine = highlighter.lineForScreenRow(3)
|
2012-02-17 07:52:12 +04:00
|
|
|
|
|
|
|
describe ".splitAt(column)", ->
|
|
|
|
it "breaks the line fragment into two fragments", ->
|
2012-02-22 21:27:49 +04:00
|
|
|
[left, right] = screenLine.splitAt(31)
|
2012-02-17 07:52:12 +04:00
|
|
|
expect(left.text).toBe ' var pivot = items.shift(), '
|
|
|
|
expect(tokensText left.tokens).toBe left.text
|
|
|
|
|
|
|
|
expect(right.text).toBe 'current, left = [], right = [];'
|
|
|
|
expect(tokensText right.tokens).toBe right.text
|
|
|
|
|
|
|
|
it "splits tokens if they straddle the split boundary", ->
|
2012-02-22 21:27:49 +04:00
|
|
|
[left, right] = screenLine.splitAt(34)
|
2012-02-17 07:52:12 +04:00
|
|
|
expect(left.text).toBe ' var pivot = items.shift(), cur'
|
|
|
|
expect(tokensText left.tokens).toBe left.text
|
|
|
|
|
|
|
|
expect(right.text).toBe 'rent, left = [], right = [];'
|
|
|
|
expect(tokensText right.tokens).toBe right.text
|
|
|
|
|
|
|
|
expect(_.last(left.tokens).type).toBe right.tokens[0].type
|
|
|
|
|
|
|
|
it "ensures the returned fragments cover the span of the original line", ->
|
2012-02-22 21:27:49 +04:00
|
|
|
[left, right] = screenLine.splitAt(15)
|
2012-03-01 05:39:45 +04:00
|
|
|
expect(left.inputDelta).toEqual [0, 15]
|
|
|
|
expect(left.outputDelta).toEqual [0, 15]
|
2012-02-17 07:52:12 +04:00
|
|
|
|
2012-03-01 05:39:45 +04:00
|
|
|
expect(right.inputDelta).toEqual [1, 0]
|
|
|
|
expect(right.outputDelta).toEqual [1, 0]
|
2012-02-17 07:52:12 +04:00
|
|
|
|
|
|
|
[left2, right2] = left.splitAt(5)
|
2012-03-01 05:39:45 +04:00
|
|
|
expect(left2.inputDelta).toEqual [0, 5]
|
|
|
|
expect(left2.outputDelta).toEqual [0, 5]
|
2012-02-17 07:52:12 +04:00
|
|
|
|
2012-03-01 05:39:45 +04:00
|
|
|
expect(right2.inputDelta).toEqual [0, 10]
|
|
|
|
expect(right2.outputDelta).toEqual [0, 10]
|
2012-02-17 07:52:12 +04:00
|
|
|
|
|
|
|
describe "if splitting at 0", ->
|
2012-03-07 05:27:06 +04:00
|
|
|
it "returns an empty line fragment for the left half", ->
|
|
|
|
left = screenLine.splitAt(0)[0]
|
|
|
|
expect(left.text).toBe ''
|
|
|
|
expect(left.tokens).toEqual []
|
|
|
|
expect(left.inputDelta).toEqual [0, 0]
|
|
|
|
expect(left.outputDelta).toEqual [0, 0]
|
2012-02-17 07:52:12 +04:00
|
|
|
|
2012-02-18 03:52:12 +04:00
|
|
|
describe "if splitting at a column equal to the line length", ->
|
|
|
|
it "returns an empty line fragment that spans a row for the right half", ->
|
2012-02-22 21:27:49 +04:00
|
|
|
[left, right] = screenLine.splitAt(screenLine.text.length)
|
2012-02-18 03:52:12 +04:00
|
|
|
|
2012-02-22 21:27:49 +04:00
|
|
|
expect(left.text).toBe screenLine.text
|
2012-03-01 05:39:45 +04:00
|
|
|
expect(left.outputDelta).toEqual [0, screenLine.text.length]
|
|
|
|
expect(left.inputDelta).toEqual [0, screenLine.text.length]
|
2012-02-18 03:52:12 +04:00
|
|
|
|
|
|
|
expect(right.text).toBe ''
|
2012-03-01 05:39:45 +04:00
|
|
|
expect(right.outputDelta).toEqual [1, 0]
|
|
|
|
expect(right.inputDelta).toEqual [1, 0]
|
2012-02-18 03:52:12 +04:00
|
|
|
|
|
|
|
describe ".concat(otherFragment)", ->
|
|
|
|
it "returns the concatenation of the receiver and the given fragment", ->
|
2012-02-22 21:27:49 +04:00
|
|
|
[left, right] = screenLine.splitAt(14)
|
|
|
|
expect(left.concat(right)).toEqual screenLine
|
2012-02-18 03:52:12 +04:00
|
|
|
|
2012-02-23 04:24:27 +04:00
|
|
|
concatenated = screenLine.concat(highlighter.lineForScreenRow(4))
|
2012-02-18 03:52:12 +04:00
|
|
|
expect(concatenated.text).toBe ' var pivot = items.shift(), current, left = [], right = []; while(items.length > 0) {'
|
|
|
|
expect(tokensText concatenated.tokens).toBe concatenated.text
|
2012-03-01 05:39:45 +04:00
|
|
|
expect(concatenated.outputDelta).toEqual [2, 0]
|
|
|
|
expect(concatenated.inputDelta).toEqual [2, 0]
|
2012-02-18 03:52:12 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|