diff --git a/spec/fixtures/jade.cson b/spec/fixtures/jade.cson new file mode 100644 index 0000000..44def5e --- /dev/null +++ b/spec/fixtures/jade.cson @@ -0,0 +1,891 @@ +'fileTypes': [ + 'jade' +] +'name': 'Jade' +'patterns': [ + { + 'comment': 'Doctype declaration.' + 'match': '^(!!!|doctype)(\\s*[a-zA-Z0-9-_]+)?' + 'name': 'comment.other.doctype.jade' + } + { + 'begin': '^(\\s*)//-' + 'comment': 'Unbuffered (jade-only) comments.' + 'end': '^(?!(\\1\\s)|\\s*$)' + 'name': 'comment.unbuffered.block.jade' + } + { + 'begin': '^(\\s*)//' + 'comment': 'Buffered (html) comments.' + 'end': '^(?!(\\1\\s)|\\s*$)' + 'name': 'string.comment.buffered.block.jade' + 'patterns': [ + { + 'captures': + '1': + 'name': 'invalid.illegal.comment.comment.block.jade' + 'comment': 'Buffered comments inside buffered comments will generate invalid html.' + 'match': '^\\s*(//)(?!-)' + 'name': 'string.comment.buffered.block.jade' + } + ] + } + { + 'begin': '^(\\s*)(script)(?=[.#(\\s])((?![^\\n]*type=)|(?=[^\\n]*text/javascript))' + 'beginCaptures': + '2': + 'name': 'entity.name.tag.script.jade' + 'comment': 'Script tag with JavaScript code.' + 'end': '^(?!(\\1\\s)|\\s*$)' + 'name': 'source.script.jade' + 'patterns': [ + { + 'begin': '\\G(?=\\()' + 'end': '$' + 'name': 'stuff.tag.script.jade' + 'patterns': [ + { + 'include': '#tag_attributes' + } + ] + } + { + 'begin': '\\G(?=[.#])' + 'end': '$' + 'name': 'stuff.tag.script.jade' + 'patterns': [ + { + 'include': '#complete_tag' + } + ] + } + { + 'include': 'source.js' + } + ] + } + { + 'begin': '^(\\s*)(style)(?=[.#(\\s])' + 'beginCaptures': + '2': + 'name': 'entity.name.tag.script.jade' + 'comment': 'Style tag with CSS code.' + 'end': '^(?!(\\1\\s)|\\s*$)' + 'name': 'source.style.jade' + 'patterns': [ + { + 'begin': '\\G(?=\\()' + 'end': '$' + 'name': 'stuff.tag.style.jade' + 'patterns': [ + { + 'include': '#tag_attributes' + } + ] + } + { + 'begin': '\\G(?=[.#])' + 'end': '$' + 'name': 'stuff.tag.style.jade' + 'patterns': [ + { + 'include': '#complete_tag' + } + ] + } + { + 'include': 'source.css' + } + ] + } + { + 'begin': '^(\\s*):(markdown)(?=\\(|$)$' + 'beginCaptures': + '2': + 'name': 'constant.language.name.markdown.filter.jade' + 'end': '^(?!(\\1\\s)|\\s*$)' + 'name': 'text.markdown.filter.jade' + 'patterns': [ + { + 'include': '#filter_args' + } + { + 'include': 'text.html.markdown' + } + ] + } + { + 'begin': '^(\\s*):(sass)(?=\\(|$)$' + 'beginCaptures': + '2': + 'name': 'constant.language.name.sass.filter.jade' + 'end': '^(?!(\\1\\s)|\\s*$)' + 'name': 'source.sass.filter.jade' + 'patterns': [ + { + 'include': '#filter_args' + } + { + 'include': 'source.sass' + } + ] + } + { + 'begin': '^(\\s*):(less)(?=\\(|$)$' + 'beginCaptures': + '2': + 'name': 'constant.language.name.less.filter.jade' + 'end': '^(?!(\\1\\s)|\\s*$)' + 'name': 'source.less.filter.jade' + 'patterns': [ + { + 'include': '#filter_args' + } + { + 'include': 'source.less' + } + ] + } + { + 'begin': '^(\\s*):(stylus)(?=\\(|$)$' + 'beginCaptures': + '2': + 'name': 'constant.language.name.stylus.filter.jade' + 'end': '^(?!(\\1\\s)|\\s*$)' + 'name': 'source.stylus.filter.jade' + 'patterns': [ + { + 'include': '#filter_args' + } + { + 'include': 'source.stylus' + } + ] + } + { + 'begin': '^(\\s*):(coffee(script)?)(?=\\(|$)' + 'beginCaptures': + '2': + 'name': 'constant.language.name.coffeescript.filter.jade' + 'end': '^(?!(\\1\\s)|\\s*$)' + 'name': 'source.coffeescript.filter.jade' + 'patterns': [ + { + 'include': '#filter_args' + } + { + 'include': 'source.coffee' + } + ] + } + { + 'begin': '^(\\s*)((:(?=.))|(:$))' + 'beginCaptures': + '4': + 'name': 'invalid.illegal.empty.generic.filter.jade' + 'comment': 'Generic Jade filter.' + 'end': '^(?!(\\1\\s)|\\s*$)' + 'name': 'text.generic.filter.jade' + 'patterns': [ + { + 'begin': '\\G(?<=:)(?=.)' + 'end': '$' + 'name': 'name.generic.filter.jade' + 'patterns': [ + { + 'match': '\\G\\(' + 'name': 'invalid.illegal.name.generic.filter.jade' + } + { + 'match': '\\w' + 'name': 'constant.language.name.generic.filter.jade' + } + { + 'include': '#filter_args' + } + { + 'match': '\\W' + 'name': 'invalid.illegal.name.generic.filter.jade' + } + ] + } + ] + } + { + 'begin': '^(\\s*)(?=[\\w.#].*?\\.$)(?=(?:(?:(?:(?:(?:#[\\w-]+)|(?:\\.[\\w-]+))|(?:(?:[#!]\\{[^}]*\\})|(?:\\w(?:(?:[\\w:-]+[\\w-])|(?:[\\w-]*)))))(?:(?:#[\\w-]+)|(?:\\.[\\w-]+)|(?:\\((?:[^()\\\'\\"]*(?:(?:\\\'(?:[^\\\']|(?:(?]*>)' + 'end': '$|(?=>)' + 'name': 'html' + 'patterns': [ + { + 'include': 'text.html.basic' + } + { + 'include': '#interpolated_value' + } + { + 'include': '#interpolated_error' + } + ] + 'filter_args': + 'begin': '\\G(\\()' + 'captures': + '1': + 'name': 'meta.args.filter.jade' + '2': + 'name': 'invalid.illegal.extra.args.filter.jade' + 'end': '(\\))(.*?$)' + 'name': 'args.filter.jade' + 'patterns': [ + { + 'begin': '([^\\s(),=]+)(=?)' + 'beginCaptures': + '1': + 'name': 'entity.other.attribute-name.tag.jade' + '2': + 'name': 'punctuation.separator.key-value.jade' + 'contentName': 'string.value.args.filter.jade' + 'end': '((?=\\))|,|$)' + 'name': 'attributes.tag.jade' + 'patterns': [ + { + 'include': '#filter_args_paren' + } + ] + } + ] + 'filter_args_paren': + 'begin': '\\(' + 'end': '\\)|$' + 'patterns': [ + { + 'include': '#filter_args_paren' + } + ] + 'flow_control': + 'begin': '(for|if|else if|else|each|until|while|unless|case)(\\s+|$)' + 'captures': + '1': + 'name': 'storage.type.function.jade' + 'comment': 'Jade control flow.' + 'end': '$' + 'name': 'meta.control.flow.jade' + 'patterns': [ + { + 'begin': '' + 'end': '$' + 'name': 'js.embedded.control.flow.jade' + 'patterns': [ + { + 'include': 'source.js' + } + ] + } + ] + 'html_entity': + 'patterns': [ + { + 'match': '(&)([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+)(;)' + 'name': 'constant.character.entity.html.text.jade' + } + { + 'match': '[<>&]' + 'name': 'invalid.illegal.html_entity.text.jade' + } + ] + 'inline_jade': + 'begin': '(?%-])\\s+[^+/*|&=:^~!?<>%-])))' + 'name': 'attributes.tag.jade' + 'patterns': [ + { + 'include': '#tag_attribute_value_paren' + } + { + 'include': '#tag_attribute_value_brackets' + } + { + 'include': '#tag_attribute_value_braces' + } + { + 'include': '#string' + } + { + 'include': 'source.js' + } + ] + } + ] + 'tag_classes': + 'match': '\\.[\\w-]+' + 'name': 'constant.language.js' + 'tag_id': + 'match': '#[\\w-]+' + 'name': 'constant.id.tag.jade' + 'tag_mixin_attributes': + 'begin': '(&attributes\\()' + 'captures': + '1': + 'name': 'entity.name.function.jade' + 'end': '(\\))' + 'name': 'attributes.tag.jade' + 'patterns': [ + { + 'match': 'attributes(?=\\))' + 'name': 'storage.type.keyword.jade' + } + { + 'include': 'source.js' + } + ] + 'tag_name': + 'begin': '([#!]\\{(?=.*?\\}))|(\\w(([\\w:-]+[\\w-])|([\\w-]*)))' + 'end': '(\\G(? "support.constant.color.w3c-standard-color-name.css" ] + describe "Jade", -> + describe "it handles comments", -> + it "correctly handles a single line comment", -> + loadGrammarSync "jade.cson" + grammar = registry.grammarForScopeName("source.jade") + {tokens} = grammar.tokenizeLine "//- A comment" + + expect(tokens[0].scopes).toEqual [ + 'source.jade' + 'comment.unbuffered.block.jade' + ] + + expect(tokens[1].scopes).toEqual [ + 'source.jade' + 'comment.unbuffered.block.jade' + ] + + it "correctly handles a single line comment after content", -> + loadGrammarSync "jade.cson" + grammar = registry.grammarForScopeName("source.jade") + lines = grammar.tokenizeLines """ + h1 Header + + //- A comment + """ + + expect(lines[2][0].scopes).toEqual [ + 'source.jade' + 'comment.unbuffered.block.jade' + ] + + expect(lines[2][1].scopes).toEqual [ + 'source.jade' + 'comment.unbuffered.block.jade' + ] + + it "correctly handles odd-line comments", -> + loadGrammarSync "jade.cson" + grammar = registry.grammarForScopeName("source.jade") + lines = grammar.tokenizeLines """ + h1 Header + + + + //- A comment + """ + + expect(lines[4][0].scopes).toEqual [ + 'source.jade' + 'comment.unbuffered.block.jade' + ] + + expect(lines[4][1].scopes).toEqual [ + 'source.jade' + 'comment.unbuffered.block.jade' + ] + + describe "when the position doesn't advance", -> it "logs an error and tokenizes the remainder of the line", -> spyOn(console, 'error')