Create synthetic iterator boundaries between open and close tags

If no non-negative integer exists between an open and close tag code,
we still need to report a boundary there, since close tags always have
to come first at any given iterator position.

:pear:ed with @as-cii
This commit is contained in:
Nathan Sobo
2016-04-21 10:43:21 -06:00
parent 754cbc2a67
commit 5ed30f910c
2 changed files with 49 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
/** @babel */
import TokenizedBufferIterator from '../src/tokenized-buffer-iterator'
import {Point} from 'text-buffer'
describe('TokenizedBufferIterator', () => {
it('reports two boundaries at the same position when tags close, open, then close again without a non-negative integer separating them (regression)', () => {
const tokenizedBuffer = {
tokenizedLineForRow () {
return {
tags: [-1, -2, -1, -2],
text: '',
openScopes: []
}
}
}
const grammarRegistry = {
scopeForId () {
return 'foo'
}
}
const iterator = new TokenizedBufferIterator(tokenizedBuffer, grammarRegistry)
iterator.seek(Point(0, 0))
expect(iterator.getPosition()).toEqual(Point(0, 0))
expect(iterator.getCloseTags()).toEqual([])
expect(iterator.getOpenTags()).toEqual(['foo'])
iterator.moveToSuccessor()
expect(iterator.getPosition()).toEqual(Point(0, 0))
expect(iterator.getCloseTags()).toEqual(['foo'])
expect(iterator.getOpenTags()).toEqual(['foo'])
iterator.moveToSuccessor()
expect(iterator.getCloseTags()).toEqual(['foo'])
expect(iterator.getOpenTags()).toEqual([])
})
})

View File

@@ -28,7 +28,11 @@ class TokenizedBufferIterator
else
scopeName = @grammarRegistry.scopeForId(tag)
if tag % 2 is 0
@closeTags.push(scopeName)
if @openTags.length > 0
@tagIndex = index
break
else
@closeTags.push(scopeName)
else
@openTags.push(scopeName)
@@ -56,7 +60,10 @@ class TokenizedBufferIterator
else
scopeName = @grammarRegistry.scopeForId(tag)
if tag % 2 is 0
@closeTags.push(scopeName)
if @openTags.length > 0
break
else
@closeTags.push(scopeName)
else
@openTags.push(scopeName)
@tagIndex++