Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Move more textmate-specific tests to TextMateLanguageMode spec
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed Sep 4, 2018
1 parent 0db70b7 commit 60c19af
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 45 deletions.
47 changes: 2 additions & 45 deletions spec/text-editor-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7511,12 +7511,12 @@ describe('TextEditor', () => {
editor = await atom.workspace.open('sample.js', {autoIndent: false})

editor.foldAllAtIndentLevel(0)
expect(editor.lineTextForScreenRow(0)).toBe(`var quicksort = function () {${editor.displayLayer.foldCharacter}`)
expect(editor.lineTextForScreenRow(0)).toBe(`var quicksort = function () {${editor.displayLayer.foldCharacter}};`)
expect(editor.getLastScreenRow()).toBe(0)

editor.foldAllAtIndentLevel(1)
expect(editor.lineTextForScreenRow(0)).toBe('var quicksort = function () {')
expect(editor.lineTextForScreenRow(1)).toBe(` var sort = function(items) {${editor.displayLayer.foldCharacter}`)
expect(editor.lineTextForScreenRow(1)).toBe(` var sort = function(items) {${editor.displayLayer.foldCharacter}};`)
expect(editor.getLastScreenRow()).toBe(4)

editor.foldAllAtIndentLevel(2)
Expand All @@ -7526,19 +7526,6 @@ describe('TextEditor', () => {
expect(editor.getLastScreenRow()).toBe(9)
})

it('folds every foldable range at a given indentLevel', async () => {
editor = await atom.workspace.open('sample-with-comments.js', {autoIndent: false})

editor.foldAllAtIndentLevel(2)
const folds = editor.unfoldAll()
expect(folds.length).toBe(5)
expect([folds[0].start.row, folds[0].end.row]).toEqual([6, 8])
expect([folds[1].start.row, folds[1].end.row]).toEqual([11, 16])
expect([folds[2].start.row, folds[2].end.row]).toEqual([17, 20])
expect([folds[3].start.row, folds[3].end.row]).toEqual([21, 22])
expect([folds[4].start.row, folds[4].end.row]).toEqual([24, 25])
})

it('does not fold anything but the indentLevel', async () => {
editor = await atom.workspace.open('sample-with-comments.js', {autoIndent: false})

Expand All @@ -7548,36 +7535,6 @@ describe('TextEditor', () => {
expect([folds[0].start.row, folds[0].end.row]).toEqual([0, 30])
})
})

describe('.isFoldableAtBufferRow(bufferRow)', () => {
it('returns true if the line starts a multi-line comment', async () => {
editor = await atom.workspace.open('sample-with-comments.js')

expect(editor.isFoldableAtBufferRow(1)).toBe(true)
expect(editor.isFoldableAtBufferRow(6)).toBe(true)
expect(editor.isFoldableAtBufferRow(8)).toBe(false)
expect(editor.isFoldableAtBufferRow(11)).toBe(true)
expect(editor.isFoldableAtBufferRow(15)).toBe(false)
expect(editor.isFoldableAtBufferRow(17)).toBe(true)
expect(editor.isFoldableAtBufferRow(21)).toBe(true)
expect(editor.isFoldableAtBufferRow(24)).toBe(true)
expect(editor.isFoldableAtBufferRow(28)).toBe(false)
})

it('returns true for lines that end with a comment and are followed by an indented line', async () => {
editor = await atom.workspace.open('sample-with-comments.js')

expect(editor.isFoldableAtBufferRow(5)).toBe(true)
})

it("does not return true for a line in the middle of a comment that's followed by an indented line", async () => {
editor = await atom.workspace.open('sample-with-comments.js')

expect(editor.isFoldableAtBufferRow(7)).toBe(false)
editor.buffer.insert([8, 0], ' ')
expect(editor.isFoldableAtBufferRow(7)).toBe(false)
})
})
})
})

Expand Down
44 changes: 44 additions & 0 deletions spec/text-mate-language-mode-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,36 @@ describe('TextMateLanguageMode', () => {
expect(languageMode.isFoldableAtRow(7)).toBe(false)
expect(languageMode.isFoldableAtRow(8)).toBe(false)
})

it('returns true if the line starts a multi-line comment', async () => {
editor = await atom.workspace.open('sample-with-comments.js')
fullyTokenize(editor.getBuffer().getLanguageMode())

expect(editor.isFoldableAtBufferRow(1)).toBe(true)
expect(editor.isFoldableAtBufferRow(6)).toBe(true)
expect(editor.isFoldableAtBufferRow(8)).toBe(false)
expect(editor.isFoldableAtBufferRow(11)).toBe(true)
expect(editor.isFoldableAtBufferRow(15)).toBe(false)
expect(editor.isFoldableAtBufferRow(17)).toBe(true)
expect(editor.isFoldableAtBufferRow(21)).toBe(true)
expect(editor.isFoldableAtBufferRow(24)).toBe(true)
expect(editor.isFoldableAtBufferRow(28)).toBe(false)
})

it('returns true for lines that end with a comment and are followed by an indented line', async () => {
editor = await atom.workspace.open('sample-with-comments.js')

expect(editor.isFoldableAtBufferRow(5)).toBe(true)
})

it("does not return true for a line in the middle of a comment that's followed by an indented line", async () => {
editor = await atom.workspace.open('sample-with-comments.js')
fullyTokenize(editor.getBuffer().getLanguageMode())

expect(editor.isFoldableAtBufferRow(7)).toBe(false)
editor.buffer.insert([8, 0], ' ')
expect(editor.isFoldableAtBufferRow(7)).toBe(false)
})
})

describe('.getFoldableRangesAtIndentLevel', () => {
Expand Down Expand Up @@ -848,6 +878,20 @@ describe('TextMateLanguageMode', () => {
}
`)
})

it('folds every foldable range at a given indentLevel', async () => {
editor = await atom.workspace.open('sample-with-comments.js')
fullyTokenize(editor.getBuffer().getLanguageMode())

editor.foldAllAtIndentLevel(2)
const folds = editor.unfoldAll()
expect(folds.length).toBe(5)
expect([folds[0].start.row, folds[0].end.row]).toEqual([6, 8])
expect([folds[1].start.row, folds[1].end.row]).toEqual([11, 16])
expect([folds[2].start.row, folds[2].end.row]).toEqual([17, 20])
expect([folds[3].start.row, folds[3].end.row]).toEqual([21, 22])
expect([folds[4].start.row, folds[4].end.row]).toEqual([24, 25])
})
})

describe('.getFoldableRanges', () => {
Expand Down

0 comments on commit 60c19af

Please sign in to comment.