Mock getMaxTokensPerLine instead of overwriting member var

This commit is contained in:
Corey Johnson & Nathan Sobo 2013-03-29 11:21:40 -07:00 committed by probablycorey
parent a9175665fa
commit 7d9e64a52d
2 changed files with 5 additions and 2 deletions

View File

@ -302,7 +302,7 @@ describe "TextMateGrammar", ->
describe "when a line has more tokens than `maxTokensPerLine`", ->
it "creates a final token with the remaining text and resets the ruleStack to match the begining of the line", ->
grammar = syntax.selectGrammar("hello.js")
grammar.maxTokensPerLine = 5
spyOn(grammar, 'getMaxTokensPerLine').andCallFake -> 5
originalRuleStack = [grammar.initialRule, grammar.initialRule, grammar.initialRule]
{tokens, ruleStack} = grammar.tokenizeLine("one(two(three(four(five(_param_)))))", originalRuleStack)
expect(tokens.length).toBe 5

View File

@ -48,7 +48,7 @@ class TextMateGrammar
previousRuleStackLength = ruleStack.length
previousPosition = position
if tokens.length >= (@maxTokensPerLine - 1)
if tokens.length >= (@getMaxTokensPerLine() - 1)
token = new Token(value: line[position..], scopes: scopes)
tokens.push token
ruleStack = originalRuleStack
@ -87,6 +87,9 @@ class TextMateGrammar
ruleStack.forEach (rule) -> rule.clearAnchorPosition()
{ tokens, ruleStack }
getMaxTokensPerLine: ->
@maxTokensPerLine
class Rule
grammar: null
scopeName: null