A pattern with no name or contentName does not insert undefined into scope array

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-09-07 11:20:56 -07:00
parent 10c36191ec
commit b00830cbc8
2 changed files with 12 additions and 2 deletions

View File

@ -142,9 +142,19 @@ describe "TextMateGrammar", ->
{tokens} = grammar.getLineTokens('')
expect(tokens[0]).toEqual value: '', scopes: ["source.coffee"]
describe "when the line matches a pattern with a 'contentName' key", ->
describe "when the line matches a pattern with a 'contentName'", ->
it "creates tokens using the content of contentName as the token name", ->
grammar = TextMateBundle.grammarForFileName("sample.txt")
{tokens} = grammar.getLineTokens('ok, cool')
expect(tokens[0]).toEqual value: 'ok, cool', scopes: ["text.plain", "meta.paragraph.text"]
describe "when the line matches a pattern with no `name` or `contentName`", ->
it "creates tokens without adding a new scope", ->
grammar = TextMateBundle.grammarsByFileType["rb"]
{tokens} = grammar.getLineTokens('%w|oh \\look|')
expect(tokens[0]).toEqual value: '%w', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby", "punctuation.definition.string.begin.ruby"]
expect(tokens[1]).toEqual value: '|', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby", "punctuation.definition.string.begin.ruby"]
expect(tokens[2]).toEqual value: 'oh ', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby"]
expect(tokens[3]).toEqual value: '\\l', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby"]
expect(tokens[4]).toEqual value: 'ook|', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby"]

View File

@ -144,7 +144,7 @@ class Pattern
handleMatch: (stack, line, captureIndices) ->
scopes = _.pluck(stack, "scopeName")
scopes.push(@scopeName) unless @popRule
scopes.push(@scopeName) if @scopeName and not @popRule
if @captures
tokens = @getTokensForCaptureIndices(line, captureIndices, scopes)