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

Turn tree-sitter on by default #17879

Merged
merged 11 commits into from
Sep 5, 2018
Prev Previous commit
Next Next commit
Fix up text editor specs
  • Loading branch information
maxbrunsfeld committed Sep 4, 2018
commit 0db70b7865de0e9080a658e996833179924f7818
52 changes: 16 additions & 36 deletions spec/text-editor-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,7 @@ describe('TextEditor', () => {

const scopeDescriptors = editor.getCursors().map(c => c.getScopeDescriptor())
expect(scopeDescriptors[0].getScopesArray()).toEqual(['source.js'])
expect(scopeDescriptors[1].getScopesArray()).toEqual(['source.js', 'string.quoted.single.js'])
expect(scopeDescriptors[1].getScopesArray()).toEqual(['source.js', 'string.quoted'])

spyOn(editor.getBuffer().getLanguageMode(), 'getNonWordCharacters').andCallFake(function (position) {
const result = '/\()"\':,.;<>~!@#$%^&*|+=[]{}`?'
Expand Down Expand Up @@ -5978,6 +5978,10 @@ describe('TextEditor', () => {
})

describe('when the buffer\'s language mode changes', () => {
beforeEach(() => {
atom.config.set('core.useTreeSitterParsers', false)
})

it('notifies onDidTokenize observers when retokenization is finished', async () => {
// Exercise the full `tokenizeInBackground` code path, which bails out early if
// `.setVisible` has not been called with `true`.
Expand Down Expand Up @@ -6293,7 +6297,7 @@ describe('TextEditor', () => {
// folds are also duplicated
expect(editor.isFoldedAtScreenRow(5)).toBe(true)
expect(editor.isFoldedAtScreenRow(7)).toBe(true)
expect(editor.lineTextForScreenRow(7)).toBe(` while(items.length > 0) {${editor.displayLayer.foldCharacter}`)
expect(editor.lineTextForScreenRow(7)).toBe(` while(items.length > 0) {${editor.displayLayer.foldCharacter}}`)
expect(editor.lineTextForScreenRow(8)).toBe(' return sort(left).concat(pivot).concat(sort(right));')
})

Expand Down Expand Up @@ -6478,6 +6482,7 @@ describe('TextEditor', () => {

describe("when the editor's grammar has an injection selector", () => {
beforeEach(async () => {
atom.config.set('core.useTreeSitterParsers', false)
await atom.packages.activatePackage('language-text')
await atom.packages.activatePackage('language-javascript')
})
Expand Down Expand Up @@ -6985,25 +6990,25 @@ describe('TextEditor', () => {

describe('indent guides', () => {
it('shows indent guides when `editor.showIndentGuide` is set to true and the editor is not mini', () => {
editor.setText(' foo')
editor.setTabLength(2)

editor.update({showIndentGuide: false})
expect(editor.tokensForScreenRow(0)).toEqual([
expect(editor.tokensForScreenRow(1).slice(0, 3)).toEqual([
{text: ' ', scopes: ['syntax--source syntax--js', 'leading-whitespace']},
{text: 'foo', scopes: ['syntax--source syntax--js']}
{text: 'var', scopes: ['syntax--source syntax--js', 'syntax--storage syntax--type']},
{text: ' sort ', scopes: ['syntax--source syntax--js']}
])

editor.update({showIndentGuide: true})
expect(editor.tokensForScreenRow(0)).toEqual([
expect(editor.tokensForScreenRow(1).slice(0, 3)).toEqual([
{text: ' ', scopes: ['syntax--source syntax--js', 'leading-whitespace indent-guide']},
{text: 'foo', scopes: ['syntax--source syntax--js']}
{text: 'var', scopes: ['syntax--source syntax--js', 'syntax--storage syntax--type']},
{text: ' sort ', scopes: ['syntax--source syntax--js']}
])

editor.setMini(true)
expect(editor.tokensForScreenRow(0)).toEqual([
expect(editor.tokensForScreenRow(1).slice(0, 3)).toEqual([
{text: ' ', scopes: ['syntax--source syntax--js', 'leading-whitespace']},
{text: 'foo', scopes: ['syntax--source syntax--js']}
{text: 'var', scopes: ['syntax--source syntax--js', 'syntax--storage syntax--type']},
{text: ' sort ', scopes: ['syntax--source syntax--js']}
])
})
})
Expand Down Expand Up @@ -7437,22 +7442,6 @@ describe('TextEditor', () => {
expect([fold2.start.row, fold2.end.row]).toEqual([1, 9])
expect([fold3.start.row, fold3.end.row]).toEqual([4, 7])
})

it('works with multi-line comments', async () => {
editor = await atom.workspace.open('sample-with-comments.js', {autoIndent: false})

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

describe('.foldBufferRow(bufferRow)', () => {
Expand Down Expand Up @@ -7487,15 +7476,6 @@ describe('TextEditor', () => {
})
})

describe('when the bufferRow is in a multi-line comment', () => {
it('searches upward and downward for surrounding comment lines and folds them as a single fold', () => {
editor.buffer.insert([1, 0], ' //this is a comment\n // and\n //more docs\n\n//second comment')
editor.foldBufferRow(1)
const [fold] = editor.unfoldAll()
expect([fold.start.row, fold.end.row]).toEqual([1, 3])
})
})

describe('when the bufferRow is a single-line comment', () => {
it('searches upward for the first row that begins a syntactic region containing the folded row (and folds it)', () => {
editor.buffer.insert([1, 0], ' //this is a single line comment\n')
Expand Down
32 changes: 30 additions & 2 deletions spec/text-mate-language-mode-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('TextMateLanguageMode', () => {

beforeEach(async () => {
config = atom.config
config.settings.core.useTreeSitterParsers = false
config.set('core.useTreeSitterParsers', false)
// enable async tokenization
TextMateLanguageMode.prototype.chunkSize = 5
jasmine.unspy(TextMateLanguageMode.prototype, 'tokenizeInBackground')
Expand All @@ -21,7 +21,7 @@ describe('TextMateLanguageMode', () => {
afterEach(() => {
buffer && buffer.destroy()
languageMode && languageMode.destroy()
config.settings.core.useTreeSitterParsers = true
config.unset('core.useTreeSitterParsers')
})

describe('when the editor is constructed with the largeFileMode option set to true', () => {
Expand Down Expand Up @@ -878,6 +878,24 @@ describe('TextMateLanguageMode', () => {
...languageMode.getFoldableRangesAtIndentLevel(2, 2),
].sort((a, b) => (a.start.row - b.start.row) || (a.end.row - b.end.row)).map(r => r.toString()))
})

it('works with multi-line comments', async () => {
await atom.packages.activatePackage('language-javascript')
editor = await atom.workspace.open('sample-with-comments.js', {autoIndent: false})
fullyTokenize(editor.getBuffer().getLanguageMode())

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

describe('.getFoldableRangeContainingPoint', () => {
Expand Down Expand Up @@ -976,6 +994,16 @@ describe('TextMateLanguageMode', () => {
expect(editor.languageMode.getFoldableRangeContainingPoint(Point(2, Infinity), 2)).toEqual([[1, Infinity], [9, Infinity]])
expect(editor.languageMode.getFoldableRangeContainingPoint(Point(4, Infinity), 2)).toEqual([[4, Infinity], [7, Infinity]])
})

it('searches upward and downward for surrounding comment lines and folds them as a single fold', async () => {
await atom.packages.activatePackage('language-javascript')
editor = await atom.workspace.open('sample-with-comments.js')
editor.buffer.insert([1, 0], ' //this is a comment\n // and\n //more docs\n\n//second comment')
fullyTokenize(editor.getBuffer().getLanguageMode())
editor.foldBufferRow(1)
const [fold] = editor.unfoldAll()
expect([fold.start.row, fold.end.row]).toEqual([1, 3])
})
})

describe('TokenIterator', () =>
Expand Down