mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Folding works with coffeescript
This commit is contained in:
@@ -5,22 +5,43 @@ Highlighter = require 'highlighter'
|
||||
describe "FoldSuggester", ->
|
||||
foldSuggester = null
|
||||
|
||||
beforeEach ->
|
||||
buffer = new Buffer(require.resolve 'fixtures/sample.js')
|
||||
highlighter = new Highlighter(buffer)
|
||||
foldSuggester = new FoldSuggester(highlighter)
|
||||
describe "javascript", ->
|
||||
beforeEach ->
|
||||
buffer = new Buffer(require.resolve 'fixtures/sample.js')
|
||||
highlighter = new Highlighter(buffer)
|
||||
foldSuggester = new FoldSuggester(highlighter)
|
||||
|
||||
describe ".isBufferRowFoldable(bufferRow)", ->
|
||||
it "returns true only when the buffer row starts a foldable region", ->
|
||||
expect(foldSuggester.isBufferRowFoldable(0)).toBeTruthy()
|
||||
expect(foldSuggester.isBufferRowFoldable(1)).toBeTruthy()
|
||||
expect(foldSuggester.isBufferRowFoldable(2)).toBeFalsy()
|
||||
expect(foldSuggester.isBufferRowFoldable(3)).toBeFalsy()
|
||||
describe ".isBufferRowFoldable(bufferRow)", ->
|
||||
it "returns true only when the buffer row starts a foldable region", ->
|
||||
expect(foldSuggester.isBufferRowFoldable(0)).toBeTruthy()
|
||||
expect(foldSuggester.isBufferRowFoldable(1)).toBeTruthy()
|
||||
expect(foldSuggester.isBufferRowFoldable(2)).toBeFalsy()
|
||||
expect(foldSuggester.isBufferRowFoldable(3)).toBeFalsy()
|
||||
|
||||
describe ".rowRangeForFoldAtBufferRow(bufferRow)", ->
|
||||
it "returns the start/end rows of the foldable region starting at the given row", ->
|
||||
expect(foldSuggester.rowRangeForFoldAtBufferRow(0)).toEqual [0, 12]
|
||||
expect(foldSuggester.rowRangeForFoldAtBufferRow(1)).toEqual [1, 9]
|
||||
expect(foldSuggester.rowRangeForFoldAtBufferRow(2)).toBeNull()
|
||||
expect(foldSuggester.rowRangeForFoldAtBufferRow(4)).toEqual [4, 7]
|
||||
describe ".rowRangeForFoldAtBufferRow(bufferRow)", ->
|
||||
it "returns the start/end rows of the foldable region starting at the given row", ->
|
||||
expect(foldSuggester.rowRangeForFoldAtBufferRow(0)).toEqual [0, 12]
|
||||
expect(foldSuggester.rowRangeForFoldAtBufferRow(1)).toEqual [1, 9]
|
||||
expect(foldSuggester.rowRangeForFoldAtBufferRow(2)).toBeNull()
|
||||
expect(foldSuggester.rowRangeForFoldAtBufferRow(4)).toEqual [4, 7]
|
||||
|
||||
describe "coffeescript", ->
|
||||
beforeEach ->
|
||||
buffer = new Buffer(require.resolve 'fixtures/sample.coffee')
|
||||
highlighter = new Highlighter(buffer)
|
||||
foldSuggester = new FoldSuggester(highlighter)
|
||||
|
||||
describe ".isBufferRowFoldable(bufferRow)", ->
|
||||
it "returns true only when the buffer row starts a foldable region", ->
|
||||
expect(foldSuggester.isBufferRowFoldable(0)).toBeTruthy()
|
||||
expect(foldSuggester.isBufferRowFoldable(1)).toBeTruthy()
|
||||
expect(foldSuggester.isBufferRowFoldable(2)).toBeFalsy()
|
||||
expect(foldSuggester.isBufferRowFoldable(3)).toBeFalsy()
|
||||
expect(foldSuggester.isBufferRowFoldable(19)).toBeTruthy()
|
||||
|
||||
describe ".rowRangeForFoldAtBufferRow(bufferRow)", ->
|
||||
it "returns the start/end rows of the foldable region starting at the given row", ->
|
||||
expect(foldSuggester.rowRangeForFoldAtBufferRow(0)).toEqual [0, 20]
|
||||
expect(foldSuggester.rowRangeForFoldAtBufferRow(1)).toEqual [1, 17]
|
||||
expect(foldSuggester.rowRangeForFoldAtBufferRow(2)).toBeNull()
|
||||
expect(foldSuggester.rowRangeForFoldAtBufferRow(19)).toEqual [19, 20]
|
||||
23
spec/fixtures/sample.coffee
vendored
Normal file
23
spec/fixtures/sample.coffee
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
class quicksort
|
||||
sort: (items) ->
|
||||
return items if items.length <= 1
|
||||
|
||||
pivot = items.shift()
|
||||
left = []
|
||||
right = []
|
||||
|
||||
# Comment in the middle
|
||||
|
||||
while items.length > 0
|
||||
current = items.shift()
|
||||
if current < pivot
|
||||
left.push(current)
|
||||
else
|
||||
right.push(current);
|
||||
|
||||
sort(left).concat(pivot).concat(sort(right))
|
||||
|
||||
noop: ->
|
||||
# just a noop
|
||||
|
||||
exports.modules = quicksort
|
||||
@@ -8,6 +8,9 @@ class AceFoldAdaptor
|
||||
getLine: (bufferRow) ->
|
||||
@buffer.lineForRow(bufferRow)
|
||||
|
||||
getLength: ->
|
||||
@buffer.numLines()
|
||||
|
||||
$findClosingBracket: (bracketType, bufferPosition) ->
|
||||
@highlighter.findClosingBracket([bufferPosition.row, bufferPosition.column - 1])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user