Adapt specs to use the new API

This commit is contained in:
Antonio Scandurra
2016-02-17 11:17:24 +01:00
parent 2c71a448b3
commit a613fa5133

View File

@@ -903,7 +903,7 @@ describe "TokenizedBuffer", ->
expect(tokenizedBuffer.tokenizedLineForRow(9).indentLevel).toBe 2
expect(tokenizedBuffer.tokenizedLineForRow(10).indentLevel).toBe 2 # }
describe ".foldable on tokenized lines", ->
describe "::foldableRowsForRowRange(startRow, endRow)", ->
changes = null
beforeEach ->
@@ -915,74 +915,74 @@ describe "TokenizedBuffer", ->
buffer, config: atom.config, grammarRegistry: atom.grammars, packageManager: atom.packages, assert: atom.assert
})
fullyTokenize(tokenizedBuffer)
tokenizedBuffer.onDidChange (change) ->
delete change.bufferChange
changes.push(change)
it "sets .foldable to true on the first line of multi-line comments", ->
expect(tokenizedBuffer.tokenizedLineForRow(0).foldable).toBe true
expect(tokenizedBuffer.tokenizedLineForRow(1).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(2).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(3).foldable).toBe true # because of indent
expect(tokenizedBuffer.tokenizedLineForRow(13).foldable).toBe true
expect(tokenizedBuffer.tokenizedLineForRow(14).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(15).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(16).foldable).toBe false
it "includes the first line of multi-line comments", ->
foldableRows = tokenizedBuffer.foldableRowsForRowRange(0, 16)
expect(foldableRows.has(0)).toBe true
expect(foldableRows.has(1)).toBe false
expect(foldableRows.has(2)).toBe false
expect(foldableRows.has(3)).toBe true # because of indent
expect(foldableRows.has(13)).toBe true
expect(foldableRows.has(14)).toBe false
expect(foldableRows.has(15)).toBe false
expect(foldableRows.has(16)).toBe false
buffer.insert([0, Infinity], '\n')
expect(changes).toEqual [{start: 0, end: 1, delta: 1}]
expect(tokenizedBuffer.tokenizedLineForRow(0).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(1).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(2).foldable).toBe true
expect(tokenizedBuffer.tokenizedLineForRow(3).foldable).toBe false
foldableRows = tokenizedBuffer.foldableRowsForRowRange(0, 3)
expect(foldableRows.has(0)).toBe false
expect(foldableRows.has(1)).toBe false
expect(foldableRows.has(2)).toBe true
expect(foldableRows.has(3)).toBe false
changes = []
buffer.undo()
expect(changes).toEqual [{start: 0, end: 2, delta: -1}]
expect(tokenizedBuffer.tokenizedLineForRow(0).foldable).toBe true
expect(tokenizedBuffer.tokenizedLineForRow(1).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(2).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(3).foldable).toBe true # because of indent
it "sets .foldable to true on non-comment lines that precede an increase in indentation", ->
foldableRows = tokenizedBuffer.foldableRowsForRowRange(0, 3)
expect(foldableRows.has(0)).toBe true
expect(foldableRows.has(1)).toBe false
expect(foldableRows.has(2)).toBe false
expect(foldableRows.has(3)).toBe true # because of indent
it "includes non-comment lines that precede an increase in indentation", ->
buffer.insert([2, 0], ' ') # commented lines preceding an indent aren't foldable
expect(tokenizedBuffer.tokenizedLineForRow(1).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(2).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(3).foldable).toBe true
expect(tokenizedBuffer.tokenizedLineForRow(4).foldable).toBe true
expect(tokenizedBuffer.tokenizedLineForRow(5).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(6).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(7).foldable).toBe true
expect(tokenizedBuffer.tokenizedLineForRow(8).foldable).toBe false
changes = []
foldableRows = tokenizedBuffer.foldableRowsForRowRange(0, 8)
expect(foldableRows.has(1)).toBe false
expect(foldableRows.has(2)).toBe false
expect(foldableRows.has(3)).toBe true
expect(foldableRows.has(4)).toBe true
expect(foldableRows.has(5)).toBe false
expect(foldableRows.has(6)).toBe false
expect(foldableRows.has(7)).toBe true
expect(foldableRows.has(8)).toBe false
buffer.insert([7, 0], ' ')
expect(changes).toEqual [{start: 6, end: 7, delta: 0}]
expect(tokenizedBuffer.tokenizedLineForRow(6).foldable).toBe true
expect(tokenizedBuffer.tokenizedLineForRow(7).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(8).foldable).toBe false
changes = []
foldableRows = tokenizedBuffer.foldableRowsForRowRange(6, 8)
expect(foldableRows.has(6)).toBe true
expect(foldableRows.has(7)).toBe false
expect(foldableRows.has(8)).toBe false
buffer.undo()
expect(changes).toEqual [{start: 6, end: 7, delta: 0}]
expect(tokenizedBuffer.tokenizedLineForRow(6).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(7).foldable).toBe true
expect(tokenizedBuffer.tokenizedLineForRow(8).foldable).toBe false
changes = []
foldableRows = tokenizedBuffer.foldableRowsForRowRange(6, 8)
expect(foldableRows.has(6)).toBe false
expect(foldableRows.has(7)).toBe true
expect(foldableRows.has(8)).toBe false
buffer.insert([7, 0], " \n x\n")
expect(changes).toEqual [{start: 6, end: 7, delta: 2}]
expect(tokenizedBuffer.tokenizedLineForRow(6).foldable).toBe true
expect(tokenizedBuffer.tokenizedLineForRow(7).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(8).foldable).toBe false
changes = []
foldableRows = tokenizedBuffer.foldableRowsForRowRange(6, 8)
expect(foldableRows.has(6)).toBe true
expect(foldableRows.has(7)).toBe false
expect(foldableRows.has(8)).toBe false
buffer.insert([9, 0], " ")
expect(changes).toEqual [{start: 9, end: 9, delta: 0}]
expect(tokenizedBuffer.tokenizedLineForRow(6).foldable).toBe true
expect(tokenizedBuffer.tokenizedLineForRow(7).foldable).toBe false
expect(tokenizedBuffer.tokenizedLineForRow(8).foldable).toBe false
foldableRows = tokenizedBuffer.foldableRowsForRowRange(6, 8)
expect(foldableRows.has(6)).toBe true
expect(foldableRows.has(7)).toBe false
expect(foldableRows.has(8)).toBe false
describe "when the buffer is configured with the null grammar", ->
it "uses the placeholder tokens and does not actually tokenize using the grammar", ->