From f592242737dddaf86d507816b27d6ba2fa715e44 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 26 Dec 2012 11:41:50 -0800 Subject: [PATCH] Terminate when no more tokens and at end of line This corrects a regression when pattern matching to the newline was added. If the newline is never matched the loop still needs to terminated so now when the position is before the newline and the last match had no tokens the loop is broken out of. --- spec/app/tokenized-buffer-spec.coffee | 17 +++++++++++++++++ spec/fixtures/hello.rb | 3 +++ src/app/text-mate-grammar.coffee | 1 + 3 files changed, 21 insertions(+) create mode 100644 spec/fixtures/hello.rb diff --git a/spec/app/tokenized-buffer-spec.coffee b/spec/app/tokenized-buffer-spec.coffee index 2eb7b74fb..7fbff436b 100644 --- a/spec/app/tokenized-buffer-spec.coffee +++ b/spec/app/tokenized-buffer-spec.coffee @@ -383,3 +383,20 @@ describe "TokenizedBuffer", -> expect(tokens[0].scopes).toEqual ["source.c++", "meta.preprocessor.c.include"] expect(tokens[1].value).toBe 'include' expect(tokens[1].scopes).toEqual ["source.c++", "meta.preprocessor.c.include", "keyword.control.import.include.c"] + + describe "when a Ruby source file is tokenized", -> + beforeEach -> + editSession = fixturesProject.buildEditSessionForPath('hello.rb', autoIndent: false) + buffer = editSession.buffer + tokenizedBuffer = editSession.displayBuffer.tokenizedBuffer + editSession.setVisible(true) + fullyTokenize(tokenizedBuffer) + + afterEach -> + editSession.destroy() + + it "doesn't loop infinitely (regression)", -> + expect(tokenizedBuffer.lineForScreenRow(0).text).toBe 'a = {' + expect(tokenizedBuffer.lineForScreenRow(1).text).toBe ' "b" => "c",' + expect(tokenizedBuffer.lineForScreenRow(2).text).toBe '}' + expect(tokenizedBuffer.lineForScreenRow(3).text).toBe '' diff --git a/spec/fixtures/hello.rb b/spec/fixtures/hello.rb new file mode 100644 index 000000000..7cd6688c7 --- /dev/null +++ b/spec/fixtures/hello.rb @@ -0,0 +1,3 @@ +a = { + "b" => "c", +} diff --git a/src/app/text-mate-grammar.coffee b/src/app/text-mate-grammar.coffee index dbba03344..28c599528 100644 --- a/src/app/text-mate-grammar.coffee +++ b/src/app/text-mate-grammar.coffee @@ -53,6 +53,7 @@ class TextMateGrammar tokens.push(nextTokens...) position = tokensEndPosition + break if position is line.length and nextTokens.length is 0 else # push filler token for unmatched text at end of line if position < line.length