diff --git a/spec/fixtures/always-match-end-pattern.cson b/spec/fixtures/always-match-end-pattern.cson new file mode 100644 index 0000000..d8436ae --- /dev/null +++ b/spec/fixtures/always-match-end-pattern.cson @@ -0,0 +1,38 @@ +name: "alwaysMatchEndPattern" +scopeName: "source.always-match-end-pattern" +patterns: [ + { + begin: 'outer-inner' + end: '```' + name: 'outer' + alwaysMatchEndPattern: true + patterns: [ + { + begin: '/\\*' + end: '\\*/' + name: 'inner' + } + ] + } + { + begin: 'outer-middle-inner' + end: '```' + name: 'outer' + alwaysMatchEndPattern: true + patterns: [ + { + begin: '/\\*' + end: '```' + name: 'middle' + alwaysMatchEndPattern: true + patterns: [ + { + begin: '' + name: 'inner' + } + ] + } + ] + } +] diff --git a/spec/grammar-spec.coffee b/spec/grammar-spec.coffee index 1a55239..af83cd9 100644 --- a/spec/grammar-spec.coffee +++ b/spec/grammar-spec.coffee @@ -295,6 +295,35 @@ describe "Grammar tokenization", -> expect(lines[4][2]).toEqual value: "}", scopes: ['source.apply-end-pattern-last', 'normal-env', 'scope'] expect(lines[4][3]).toEqual value: "excentricSyntax }", scopes: ['source.apply-end-pattern-last', 'normal-env'] + describe "when the alwaysMatchEndPattern flag is set in a pattern", -> + beforeEach -> + grammar = loadGrammarSync('always-match-end-pattern.cson') + + it "attempts to match that end pattern first even when its included patterns have not finished matching", -> + lines = grammar.tokenizeLines """ + outer-inner + /* + stuff + ``` + """ + + expect(lines[1][0]).toEqual value: '/*', scopes: ['source.always-match-end-pattern', 'outer', 'inner'] + expect(lines[3][0]).toEqual value: '```', scopes: ['source.always-match-end-pattern', 'outer'] + + it "attempts to match the outermost pattern", -> + lines = grammar.tokenizeLines """ + outer-middle-inner + /* + stuff +