mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
💄
More consistent method names among Highlighter, LineWrapper, LineFolder, and LineMap
This commit is contained in:
@@ -11,8 +11,8 @@ describe "Highlighter", ->
|
||||
|
||||
describe "constructor", ->
|
||||
it "tokenizes all the lines in the buffer", ->
|
||||
expect(highlighter.screenLineForRow(0).tokens[0]).toEqual(type: 'keyword.definition', value: 'var')
|
||||
expect(highlighter.screenLineForRow(11).tokens[1]).toEqual(type: 'keyword', value: 'return')
|
||||
expect(highlighter.lineForScreenRow(0).tokens[0]).toEqual(type: 'keyword.definition', value: 'var')
|
||||
expect(highlighter.lineForScreenRow(11).tokens[1]).toEqual(type: 'keyword', value: 'return')
|
||||
|
||||
describe "when the buffer changes", ->
|
||||
changeHandler = null
|
||||
@@ -26,11 +26,11 @@ describe "Highlighter", ->
|
||||
range = new Range([0, 0], [2, 0])
|
||||
buffer.change(range, "foo()\nbar()\n")
|
||||
|
||||
expect(highlighter.screenLineForRow(0).tokens[0]).toEqual(type: 'identifier', value: 'foo')
|
||||
expect(highlighter.screenLineForRow(1).tokens[0]).toEqual(type: 'identifier', value: 'bar')
|
||||
expect(highlighter.lineForScreenRow(0).tokens[0]).toEqual(type: 'identifier', value: 'foo')
|
||||
expect(highlighter.lineForScreenRow(1).tokens[0]).toEqual(type: 'identifier', value: 'bar')
|
||||
|
||||
# line 2 is unchanged
|
||||
expect(highlighter.screenLineForRow(2).tokens[1]).toEqual(type: 'keyword', value: 'if')
|
||||
expect(highlighter.lineForScreenRow(2).tokens[1]).toEqual(type: 'keyword', value: 'if')
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -43,9 +43,9 @@ describe "Highlighter", ->
|
||||
changeHandler.reset()
|
||||
|
||||
buffer.insert([2, 0], '/*')
|
||||
expect(highlighter.screenLineForRow(3).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.screenLineForRow(4).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.screenLineForRow(5).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(3).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(4).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(5).tokens[0].type).toBe 'comment'
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -57,7 +57,7 @@ describe "Highlighter", ->
|
||||
buffer.insert([5, 0], '*/')
|
||||
|
||||
buffer.insert([1, 0], 'var ')
|
||||
expect(highlighter.screenLineForRow(1).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(1).tokens[0].type).toBe 'comment'
|
||||
|
||||
describe "when lines are both updated and removed", ->
|
||||
it "updates tokens to reflect the removed lines", ->
|
||||
@@ -65,16 +65,16 @@ describe "Highlighter", ->
|
||||
buffer.change(range, "foo()")
|
||||
|
||||
# previous line 0 remains
|
||||
expect(highlighter.screenLineForRow(0).tokens[0]).toEqual(type: 'keyword.definition', value: 'var')
|
||||
expect(highlighter.lineForScreenRow(0).tokens[0]).toEqual(type: 'keyword.definition', value: 'var')
|
||||
|
||||
# previous line 3 should be combined with input to form line 1
|
||||
expect(highlighter.screenLineForRow(1).tokens[0]).toEqual(type: 'identifier', value: 'foo')
|
||||
expect(highlighter.screenLineForRow(1).tokens[6]).toEqual(type: 'identifier', value: 'pivot')
|
||||
expect(highlighter.lineForScreenRow(1).tokens[0]).toEqual(type: 'identifier', value: 'foo')
|
||||
expect(highlighter.lineForScreenRow(1).tokens[6]).toEqual(type: 'identifier', value: 'pivot')
|
||||
|
||||
# lines below deleted regions should be shifted upward
|
||||
expect(highlighter.screenLineForRow(2).tokens[1]).toEqual(type: 'keyword', value: 'while')
|
||||
expect(highlighter.screenLineForRow(3).tokens[1]).toEqual(type: 'identifier', value: 'current')
|
||||
expect(highlighter.screenLineForRow(4).tokens[3]).toEqual(type: 'keyword.operator', value: '<')
|
||||
expect(highlighter.lineForScreenRow(2).tokens[1]).toEqual(type: 'keyword', value: 'while')
|
||||
expect(highlighter.lineForScreenRow(3).tokens[1]).toEqual(type: 'identifier', value: 'current')
|
||||
expect(highlighter.lineForScreenRow(4).tokens[3]).toEqual(type: 'keyword.operator', value: '<')
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -86,9 +86,9 @@ describe "Highlighter", ->
|
||||
changeHandler.reset()
|
||||
|
||||
buffer.change(new Range([2, 0], [3, 0]), '/*')
|
||||
expect(highlighter.screenLineForRow(2).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.screenLineForRow(3).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.screenLineForRow(4).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(2).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(3).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(4).tokens[0].type).toBe 'comment'
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -101,19 +101,19 @@ describe "Highlighter", ->
|
||||
buffer.change(range, "foo()\nbar()\nbaz()\nquux()")
|
||||
|
||||
# previous line 0 remains
|
||||
expect(highlighter.screenLineForRow(0).tokens[0]).toEqual(type: 'keyword.definition', value: 'var')
|
||||
expect(highlighter.lineForScreenRow(0).tokens[0]).toEqual(type: 'keyword.definition', value: 'var')
|
||||
|
||||
# 3 new lines inserted
|
||||
expect(highlighter.screenLineForRow(1).tokens[0]).toEqual(type: 'identifier', value: 'foo')
|
||||
expect(highlighter.screenLineForRow(2).tokens[0]).toEqual(type: 'identifier', value: 'bar')
|
||||
expect(highlighter.screenLineForRow(3).tokens[0]).toEqual(type: 'identifier', value: 'baz')
|
||||
expect(highlighter.lineForScreenRow(1).tokens[0]).toEqual(type: 'identifier', value: 'foo')
|
||||
expect(highlighter.lineForScreenRow(2).tokens[0]).toEqual(type: 'identifier', value: 'bar')
|
||||
expect(highlighter.lineForScreenRow(3).tokens[0]).toEqual(type: 'identifier', value: 'baz')
|
||||
|
||||
# previous line 2 is joined with quux() on line 4
|
||||
expect(highlighter.screenLineForRow(4).tokens[0]).toEqual(type: 'identifier', value: 'quux')
|
||||
expect(highlighter.screenLineForRow(4).tokens[4]).toEqual(type: 'keyword', value: 'if')
|
||||
expect(highlighter.lineForScreenRow(4).tokens[0]).toEqual(type: 'identifier', value: 'quux')
|
||||
expect(highlighter.lineForScreenRow(4).tokens[4]).toEqual(type: 'keyword', value: 'if')
|
||||
|
||||
# previous line 3 is pushed down to become line 5
|
||||
expect(highlighter.screenLineForRow(5).tokens[3]).toEqual(type: 'identifier', value: 'pivot')
|
||||
expect(highlighter.lineForScreenRow(5).tokens[3]).toEqual(type: 'identifier', value: 'pivot')
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -125,13 +125,13 @@ describe "Highlighter", ->
|
||||
changeHandler.reset()
|
||||
|
||||
buffer.insert([2, 0], '/*\nabcde\nabcder')
|
||||
expect(highlighter.screenLineForRow(2).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.screenLineForRow(3).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.screenLineForRow(4).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.screenLineForRow(5).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.screenLineForRow(6).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.screenLineForRow(7).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.screenLineForRow(8).tokens[0].type).not.toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(2).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(3).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(4).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(5).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(6).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(7).tokens[0].type).toBe 'comment'
|
||||
expect(highlighter.lineForScreenRow(8).tokens[0].type).not.toBe 'comment'
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
|
||||
@@ -12,7 +12,7 @@ describe "LineMap", ->
|
||||
buffer = new Buffer(require.resolve 'fixtures/sample.js')
|
||||
highlighter = new Highlighter(buffer)
|
||||
map = new LineMap
|
||||
[line0, line1, line2, line3, line4] = highlighter.screenLinesForRows(0, 4)
|
||||
[line0, line1, line2, line3, line4] = highlighter.linesForScreenRows(0, 4)
|
||||
|
||||
describe ".insertAtBufferRow(row, screenLine(s))", ->
|
||||
describe "when passed a single, line fragment", ->
|
||||
@@ -192,7 +192,7 @@ describe "LineMap", ->
|
||||
it "wraps buffer positions at the end of a screen line to the end end of the next screen line", ->
|
||||
expect(map.screenPositionForBufferPosition([4, 20], true)).toEqual [3, 0]
|
||||
|
||||
describe ".screenLineCount()", ->
|
||||
describe ".lineCount()", ->
|
||||
it "returns the total of all inserted screen row deltas", ->
|
||||
[line1a, line1b] = line1.splitAt(10)
|
||||
[line3a, line3b] = line3.splitAt(10)
|
||||
@@ -201,6 +201,6 @@ describe "LineMap", ->
|
||||
|
||||
map.insertAtBufferRow(0, [line0, line1a, line1b, line2])
|
||||
|
||||
expect(map.screenLineCount()).toBe 4
|
||||
expect(map.lineCount()).toBe 4
|
||||
|
||||
|
||||
|
||||
@@ -16,22 +16,22 @@ describe "LineWrapper", ->
|
||||
|
||||
describe ".tokensForScreenRow(row)", ->
|
||||
it "returns tokens for the line fragment corresponding to the given screen row", ->
|
||||
expect(tokensText wrapper.screenLineForRow(3).tokens).toEqual(' var pivot = items.shift(), current, left = [], ')
|
||||
expect(tokensText wrapper.screenLineForRow(4).tokens).toEqual('right = [];')
|
||||
expect(tokensText wrapper.screenLineForRow(5).tokens).toEqual(' while(items.length > 0) {')
|
||||
expect(tokensText wrapper.lineForScreenRow(3).tokens).toEqual(' var pivot = items.shift(), current, left = [], ')
|
||||
expect(tokensText wrapper.lineForScreenRow(4).tokens).toEqual('right = [];')
|
||||
expect(tokensText wrapper.lineForScreenRow(5).tokens).toEqual(' while(items.length > 0) {')
|
||||
|
||||
describe ".screenLineCount()", ->
|
||||
describe ".lineCount()", ->
|
||||
it "returns the total number of screen lines", ->
|
||||
expect(wrapper.screenLineCount()).toBe 16
|
||||
expect(wrapper.lineCount()).toBe 16
|
||||
|
||||
describe "when the buffer changes", ->
|
||||
describe "when a buffer line is updated", ->
|
||||
describe "when the number of screen lines remains the same for the changed buffer line", ->
|
||||
it "re-wraps the existing lines and emits a change event for all its screen lines", ->
|
||||
buffer.insert([6, 28], '1234567')
|
||||
expect(wrapper.screenLineForRow(7).text).toBe ' current < pivot ? left1234567.push(current) '
|
||||
expect(wrapper.screenLineForRow(8).text).toBe ': right.push(current);'
|
||||
expect(wrapper.screenLineForRow(9).text).toBe ' }'
|
||||
expect(wrapper.lineForScreenRow(7).text).toBe ' current < pivot ? left1234567.push(current) '
|
||||
expect(wrapper.lineForScreenRow(8).text).toBe ': right.push(current);'
|
||||
expect(wrapper.lineForScreenRow(9).text).toBe ' }'
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -41,10 +41,10 @@ describe "LineWrapper", ->
|
||||
describe "when the number of screen lines increases for the changed buffer line", ->
|
||||
it "re-wraps and adds an additional screen line and emits a change event for all screen lines", ->
|
||||
buffer.insert([6, 28], '1234567890')
|
||||
expect(wrapper.screenLineForRow(7).text).toBe ' current < pivot ? '
|
||||
expect(wrapper.screenLineForRow(8).text).toBe 'left1234567890.push(current) : '
|
||||
expect(wrapper.screenLineForRow(9).text).toBe 'right.push(current);'
|
||||
expect(wrapper.screenLineForRow(10).text).toBe ' }'
|
||||
expect(wrapper.lineForScreenRow(7).text).toBe ' current < pivot ? '
|
||||
expect(wrapper.lineForScreenRow(8).text).toBe 'left1234567890.push(current) : '
|
||||
expect(wrapper.lineForScreenRow(9).text).toBe 'right.push(current);'
|
||||
expect(wrapper.lineForScreenRow(10).text).toBe ' }'
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -54,8 +54,8 @@ describe "LineWrapper", ->
|
||||
describe "when the number of screen lines decreases for the changed buffer line", ->
|
||||
it "re-wraps and removes a screen line and emits a change event for all screen lines", ->
|
||||
buffer.change(new Range([6, 24], [6, 42]), '')
|
||||
expect(wrapper.screenLineForRow(7).text).toBe ' current < pivot ? : right.push(current);'
|
||||
expect(wrapper.screenLineForRow(8).text).toBe ' }'
|
||||
expect(wrapper.lineForScreenRow(7).text).toBe ' current < pivot ? : right.push(current);'
|
||||
expect(wrapper.lineForScreenRow(8).text).toBe ' }'
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -65,10 +65,10 @@ describe "LineWrapper", ->
|
||||
describe "when buffer lines are inserted", ->
|
||||
it "re-wraps existing and new screen lines and emits a change event", ->
|
||||
buffer.insert([6, 21], '1234567890 abcdefghij 1234567890\nabcdefghij')
|
||||
expect(wrapper.screenLineForRow(7).text).toBe ' current < pivot1234567890 abcdefghij '
|
||||
expect(wrapper.screenLineForRow(8).text).toBe '1234567890'
|
||||
expect(wrapper.screenLineForRow(9).text).toBe 'abcdefghij ? left.push(current) : '
|
||||
expect(wrapper.screenLineForRow(10).text).toBe 'right.push(current);'
|
||||
expect(wrapper.lineForScreenRow(7).text).toBe ' current < pivot1234567890 abcdefghij '
|
||||
expect(wrapper.lineForScreenRow(8).text).toBe '1234567890'
|
||||
expect(wrapper.lineForScreenRow(9).text).toBe 'abcdefghij ? left.push(current) : '
|
||||
expect(wrapper.lineForScreenRow(10).text).toBe 'right.push(current);'
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -78,10 +78,10 @@ describe "LineWrapper", ->
|
||||
describe "when buffer lines are removed", ->
|
||||
it "removes screen lines and emits a change event", ->
|
||||
buffer.change(new Range([3, 21], [7, 5]), ';')
|
||||
expect(wrapper.screenLineForRow(3).text).toBe ' var pivot = items;'
|
||||
expect(wrapper.screenLineForRow(4).text).toBe ' return '
|
||||
expect(wrapper.screenLineForRow(5).text).toBe 'sort(left).concat(pivot).concat(sort(right));'
|
||||
expect(wrapper.screenLineForRow(6).text).toBe ' };'
|
||||
expect(wrapper.lineForScreenRow(3).text).toBe ' var pivot = items;'
|
||||
expect(wrapper.lineForScreenRow(4).text).toBe ' return '
|
||||
expect(wrapper.lineForScreenRow(5).text).toBe 'sort(left).concat(pivot).concat(sort(right));'
|
||||
expect(wrapper.lineForScreenRow(6).text).toBe ' };'
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
@@ -91,9 +91,9 @@ describe "LineWrapper", ->
|
||||
describe ".setMaxLength(length)", ->
|
||||
it "changes the length at which lines are wrapped and emits a change event for all screen lines", ->
|
||||
wrapper.setMaxLength(40)
|
||||
expect(tokensText wrapper.screenLineForRow(4).tokens).toBe 'left = [], right = [];'
|
||||
expect(tokensText wrapper.screenLineForRow(5).tokens).toBe ' while(items.length > 0) {'
|
||||
expect(tokensText wrapper.screenLineForRow(12).tokens).toBe 'sort(left).concat(pivot).concat(sort(rig'
|
||||
expect(tokensText wrapper.lineForScreenRow(4).tokens).toBe 'left = [], right = [];'
|
||||
expect(tokensText wrapper.lineForScreenRow(5).tokens).toBe ' while(items.length > 0) {'
|
||||
expect(tokensText wrapper.lineForScreenRow(12).tokens).toBe 'sort(left).concat(pivot).concat(sort(rig'
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
|
||||
@@ -8,7 +8,7 @@ describe "screenLineFragment", ->
|
||||
beforeEach ->
|
||||
buffer = new Buffer(require.resolve 'fixtures/sample.js')
|
||||
highlighter = new Highlighter(buffer)
|
||||
screenLine = highlighter.screenLineForRow(3)
|
||||
screenLine = highlighter.lineForScreenRow(3)
|
||||
|
||||
describe ".splitAt(column)", ->
|
||||
it "breaks the line fragment into two fragments", ->
|
||||
@@ -65,7 +65,7 @@ describe "screenLineFragment", ->
|
||||
[left, right] = screenLine.splitAt(14)
|
||||
expect(left.concat(right)).toEqual screenLine
|
||||
|
||||
concatenated = screenLine.concat(highlighter.screenLineForRow(4))
|
||||
concatenated = screenLine.concat(highlighter.lineForScreenRow(4))
|
||||
expect(concatenated.text).toBe ' var pivot = items.shift(), current, left = [], right = []; while(items.length > 0) {'
|
||||
expect(tokensText concatenated.tokens).toBe concatenated.text
|
||||
expect(concatenated.screenDelta).toEqual [2, 0]
|
||||
|
||||
Reference in New Issue
Block a user