Avoid using tokenizedLineForScreenRow in TextEditorPresenter specs

This commit is contained in:
Antonio Scandurra
2016-03-17 10:35:54 +01:00
parent 661417e362
commit 708da39355

View File

@@ -1229,9 +1229,16 @@ describe "TextEditorPresenter", ->
describe ".tiles", -> describe ".tiles", ->
lineStateForScreenRow = (presenter, row) -> lineStateForScreenRow = (presenter, row) ->
lineId = presenter.model.tokenizedLineForScreenRow(row).id tilesState = getState(presenter).content.tiles
tileRow = presenter.tileForRow(row) lineId = presenter.linesByScreenRow.get(row)?.id
getState(presenter).content.tiles[tileRow]?.lines[lineId] tilesState[presenter.tileForRow(row)]?.lines[lineId]
tokensIncludeTag = (tokens, tag) ->
includeTag = false
for {openTags, closeTags} in tokens
includeTag = true for openTag in openTags when openTag.indexOf(tag) isnt -1
includeTag = true for closeTag in closeTags when closeTag.indexOf(tag) isnt -1
includeTag
tiledContentContract (presenter) -> getState(presenter).content tiledContentContract (presenter) -> getState(presenter).content
@@ -1241,73 +1248,56 @@ describe "TextEditorPresenter", ->
presenter.setExplicitHeight(3) presenter.setExplicitHeight(3)
expect(lineStateForScreenRow(presenter, 2)).toBeUndefined() expect(lineStateForScreenRow(presenter, 2)).toBeUndefined()
line3 = editor.tokenizedLineForScreenRow(3)
expectValues lineStateForScreenRow(presenter, 3), { expectValues lineStateForScreenRow(presenter, 3), {
screenRow: 3 screenRow: 3, tokens: [
text: line3.text {closeTags: [], openTags: ['text.plain.null-grammar', 'leading-whitespace'], text: ' '},
tags: line3.tags {closeTags: ['leading-whitespace'], openTags: ['leading-whitespace'], text: ' '},
specialTokens: line3.specialTokens {closeTags: ['leading-whitespace'], openTags: [], text: 'var pivot = items.shift(), current, left = [], right = [];'},
firstNonWhitespaceIndex: line3.firstNonWhitespaceIndex {closeTags: ['text.plain.null-grammar'], openTags: [], text: ''}
firstTrailingWhitespaceIndex: line3.firstTrailingWhitespaceIndex ]
invisibles: line3.invisibles
} }
line4 = editor.tokenizedLineForScreenRow(4)
expectValues lineStateForScreenRow(presenter, 4), { expectValues lineStateForScreenRow(presenter, 4), {
screenRow: 4 screenRow: 4, tokens: [
text: line4.text {closeTags: [], openTags: ['text.plain.null-grammar', 'leading-whitespace'], text: ' '},
tags: line4.tags {closeTags: ['leading-whitespace'], openTags: ['leading-whitespace'], text: ' '},
specialTokens: line4.specialTokens {closeTags: ['leading-whitespace'], openTags: [], text: 'while(items.length > 0) {'},
firstNonWhitespaceIndex: line4.firstNonWhitespaceIndex {closeTags: ['text.plain.null-grammar'], openTags: [], text: ''}
firstTrailingWhitespaceIndex: line4.firstTrailingWhitespaceIndex ]
invisibles: line4.invisibles
} }
line5 = editor.tokenizedLineForScreenRow(5)
expectValues lineStateForScreenRow(presenter, 5), { expectValues lineStateForScreenRow(presenter, 5), {
screenRow: 5 screenRow: 5, tokens: [
text: line5.text {closeTags: [], openTags: ['text.plain.null-grammar', 'leading-whitespace'], text: ' '},
tags: line5.tags {closeTags: ['leading-whitespace'], openTags: ['leading-whitespace'], text: ' '},
specialTokens: line5.specialTokens {closeTags: ['leading-whitespace'], openTags: ['leading-whitespace'], text: ' '},
firstNonWhitespaceIndex: line5.firstNonWhitespaceIndex {closeTags: ['leading-whitespace'], openTags: [], text: 'current = items.shift();'},
firstTrailingWhitespaceIndex: line5.firstTrailingWhitespaceIndex {closeTags: ['text.plain.null-grammar'], openTags: [], text: ''}
invisibles: line5.invisibles ]
} }
line6 = editor.tokenizedLineForScreenRow(6)
expectValues lineStateForScreenRow(presenter, 6), { expectValues lineStateForScreenRow(presenter, 6), {
screenRow: 6 screenRow: 6, tokens: [
text: line6.text {closeTags: [], openTags: ['text.plain.null-grammar', 'leading-whitespace'], text: ' '},
tags: line6.tags {closeTags: ['leading-whitespace'], openTags: ['leading-whitespace'], text: ' '},
specialTokens: line6.specialTokens {closeTags: ['leading-whitespace'], openTags: ['leading-whitespace'], text: ' '},
firstNonWhitespaceIndex: line6.firstNonWhitespaceIndex {closeTags: ['leading-whitespace'], openTags: [], text: 'current < pivot ? left.push(current) : right.push(current);'},
firstTrailingWhitespaceIndex: line6.firstTrailingWhitespaceIndex {closeTags: ['text.plain.null-grammar'], openTags: [], text: ''}
invisibles: line6.invisibles ]
} }
line7 = editor.tokenizedLineForScreenRow(7)
expectValues lineStateForScreenRow(presenter, 7), { expectValues lineStateForScreenRow(presenter, 7), {
screenRow: 7 screenRow: 7, tokens: [
text: line7.text {closeTags: [], openTags: ['text.plain.null-grammar', 'leading-whitespace'], text: ' '},
tags: line7.tags {closeTags: ['leading-whitespace'], openTags: ['leading-whitespace'], text: ' '},
specialTokens: line7.specialTokens {closeTags: ['leading-whitespace'], openTags: [], text: '}'},
firstNonWhitespaceIndex: line7.firstNonWhitespaceIndex {closeTags: ['text.plain.null-grammar'], openTags: [], text: ''}
firstTrailingWhitespaceIndex: line7.firstTrailingWhitespaceIndex ]
invisibles: line7.invisibles
} }
line8 = editor.tokenizedLineForScreenRow(8)
expectValues lineStateForScreenRow(presenter, 8), { expectValues lineStateForScreenRow(presenter, 8), {
screenRow: 8 screenRow: 8, tokens: [
text: line8.text {closeTags: [], openTags: ['text.plain.null-grammar', 'leading-whitespace'], text: ' '},
tags: line8.tags {closeTags: ['leading-whitespace'], openTags: ['leading-whitespace'], text: ' '},
specialTokens: line8.specialTokens {closeTags: ['leading-whitespace'], openTags: [], text: 'return sort(left).concat(pivot).concat(sort(right));'},
firstNonWhitespaceIndex: line8.firstNonWhitespaceIndex {closeTags: ['text.plain.null-grammar'], openTags: [], text: ''}
firstTrailingWhitespaceIndex: line8.firstTrailingWhitespaceIndex ]
invisibles: line8.invisibles
} }
expect(lineStateForScreenRow(presenter, 9)).toBeUndefined() expect(lineStateForScreenRow(presenter, 9)).toBeUndefined()
it "updates when the editor's content changes", -> it "updates when the editor's content changes", ->
@@ -1315,34 +1305,36 @@ describe "TextEditorPresenter", ->
expectStateUpdate presenter, -> buffer.insert([2, 0], "hello\nworld\n") expectStateUpdate presenter, -> buffer.insert([2, 0], "hello\nworld\n")
line1 = editor.tokenizedLineForScreenRow(1)
expectValues lineStateForScreenRow(presenter, 1), { expectValues lineStateForScreenRow(presenter, 1), {
text: line1.text screenRow: 1, tokens: [
tags: line1.tags {closeTags: [], openTags: ['text.plain.null-grammar', 'leading-whitespace'], text: ' '},
{closeTags: ['leading-whitespace'], openTags: [], text: 'var sort = function(items) {'},
{closeTags: ['text.plain.null-grammar'], openTags: [], text : ''}
]
} }
line2 = editor.tokenizedLineForScreenRow(2)
expectValues lineStateForScreenRow(presenter, 2), { expectValues lineStateForScreenRow(presenter, 2), {
text: line2.text screenRow: 2, tokens: [
tags: line2.tags {closeTags: [], openTags: ['text.plain.null-grammar'], text: 'hello'},
{closeTags: ['text.plain.null-grammar'], openTags: [], text: ''}
]
} }
line3 = editor.tokenizedLineForScreenRow(3)
expectValues lineStateForScreenRow(presenter, 3), { expectValues lineStateForScreenRow(presenter, 3), {
text: line3.text screenRow: 3, tokens: [
tags: line3.tags {closeTags: [], openTags: ['text.plain.null-grammar'], text: 'world'},
{closeTags: ['text.plain.null-grammar'], openTags: [], text: ''}
]
} }
it "includes the .endOfLineInvisibles if the editor.showInvisibles config option is true", -> it "includes the .endOfLineInvisibles if the editor.showInvisibles config option is true", ->
editor.setText("hello\nworld\r\n") editor.setText("hello\nworld\r\n")
presenter = buildPresenter(explicitHeight: 25, scrollTop: 0, lineHeight: 10) presenter = buildPresenter(explicitHeight: 25, scrollTop: 0, lineHeight: 10)
expect(lineStateForScreenRow(presenter, 0).endOfLineInvisibles).toBeNull() expect(tokensIncludeTag(lineStateForScreenRow(presenter, 0).tokens, 'eol')).toBe(false)
expect(lineStateForScreenRow(presenter, 1).endOfLineInvisibles).toBeNull() expect(tokensIncludeTag(lineStateForScreenRow(presenter, 1).tokens, 'eol')).toBe(false)
atom.config.set('editor.showInvisibles', true) atom.config.set('editor.showInvisibles', true)
presenter = buildPresenter(explicitHeight: 25, scrollTop: 0, lineHeight: 10) presenter = buildPresenter(explicitHeight: 25, scrollTop: 0, lineHeight: 10)
expect(lineStateForScreenRow(presenter, 0).endOfLineInvisibles).toEqual [atom.config.get('editor.invisibles.eol')] expect(tokensIncludeTag(lineStateForScreenRow(presenter, 0).tokens, 'eol')).toBe(true)
expect(lineStateForScreenRow(presenter, 1).endOfLineInvisibles).toEqual [atom.config.get('editor.invisibles.cr'), atom.config.get('editor.invisibles.eol')] expect(tokensIncludeTag(lineStateForScreenRow(presenter, 1).tokens, 'eol')).toBe(true)
describe ".blockDecorations", -> describe ".blockDecorations", ->
it "contains all block decorations that are present before/after a line, both initially and when decorations change", -> it "contains all block decorations that are present before/after a line, both initially and when decorations change", ->
@@ -2905,12 +2897,9 @@ describe "TextEditorPresenter", ->
describe ".content.tiles", -> describe ".content.tiles", ->
lineNumberStateForScreenRow = (presenter, screenRow) -> lineNumberStateForScreenRow = (presenter, screenRow) ->
editor = presenter.model tilesState = getLineNumberGutterState(presenter).content.tiles
tileRow = presenter.tileForRow(screenRow) line = presenter.linesByScreenRow.get(screenRow)
line = editor.tokenizedLineForScreenRow(screenRow) tilesState[presenter.tileForRow(screenRow)]?.lineNumbers[line?.id]
gutterState = getLineNumberGutterState(presenter)
gutterState.content.tiles[tileRow]?.lineNumbers[line?.id]
tiledContentContract (presenter) -> getLineNumberGutterState(presenter).content tiledContentContract (presenter) -> getLineNumberGutterState(presenter).content
@@ -2919,7 +2908,7 @@ describe "TextEditorPresenter", ->
editor.foldBufferRow(4) editor.foldBufferRow(4)
editor.setSoftWrapped(true) editor.setSoftWrapped(true)
editor.setDefaultCharWidth(1) editor.setDefaultCharWidth(1)
editor.setEditorWidthInChars(50) editor.setEditorWidthInChars(51)
presenter = buildPresenter(explicitHeight: 25, scrollTop: 30, lineHeight: 10, tileSize: 2) presenter = buildPresenter(explicitHeight: 25, scrollTop: 30, lineHeight: 10, tileSize: 2)
expect(lineNumberStateForScreenRow(presenter, 1)).toBeUndefined() expect(lineNumberStateForScreenRow(presenter, 1)).toBeUndefined()