Skip to content

Instantly share code, notes, and snippets.

@DamnedScholar
Created November 2, 2016 02:54
Show Gist options
  • Save DamnedScholar/6bcc95a41cea746a5350508137eb165c to your computer and use it in GitHub Desktop.
Save DamnedScholar/6bcc95a41cea746a5350508137eb165c to your computer and use it in GitHub Desktop.
Atom language-javascript HTML embedding specs
describe 'HTML strings', ->
beforeEach ->
waitsForPromise ->
atom.packages.activatePackage("language-html")
describe "ES6 tagged HTML string templates", ->
it "tokenizes them as strings", ->
{tokens} = grammar.tokenizeLine('html`hey <b>${name}</b>`')
expect(tokens[0]).toEqual value: 'html', scopes: [ 'source.js', 'string.quoted.template.html.js', 'entity.name.function.js' ]
expect(tokens[1]).toEqual value: '`', scopes: [ 'source.js', 'string.quoted.template.html.js', 'punctuation.definition.string.begin.js' ]
expect(tokens[2]).toEqual value: 'hey <b>', scopes: ['source.js', 'string.quoted.template.html.js']
expect(tokens[3]).toEqual value: '${', scopes: ['source.js', 'string.quoted.template.html.js', 'source.js.embedded.source', 'punctuation.section.embedded.js']
expect(tokens[4]).toEqual value: 'name', scopes: ['source.js', 'string.quoted.template.html.js', 'source.js.embedded.source']
expect(tokens[5]).toEqual value: '}', scopes: ['source.js', 'string.quoted.template.html.js', 'source.js.embedded.source', 'punctuation.section.embedded.js']
expect(tokens[6]).toEqual value: '</b>', scopes: ['source.js', 'string.quoted.template.html.js']
expect(tokens[7]).toEqual value: '`', scopes: ['source.js', 'string.quoted.template.html.js', 'punctuation.definition.string.end.js']
describe "innerHTML attribute declarations with string template tags", ->
it "tokenizes them as strings", ->
{tokens} = grammar.tokenizeLine('text.innerHTML = `hey <b>${name}</b>`')
expect(tokens[0]).toEqual value: 'text', scopes: [ 'source.js', 'variable.other.object.js' ]
expect(tokens[1]).toEqual value: '.', scopes: [ 'source.js', 'meta.delimiter.property.period.js' ]
expect(tokens[2]).toEqual value: 'innerHTML', scopes: [ 'source.js', 'variable.other.property.js' ]
expect(tokens[3]).toEqual value: ' ', scopes: [ 'source.js', 'string.quoted.template.html.js' ]
expect(tokens[4]).toEqual value: '=', scopes: [ 'source.js', 'string.quoted.template.html.js', 'keyword.operator.assignment.js' ]
expect(tokens[5]).toEqual value: ' ', scopes: [ 'source.js', 'string.quoted.template.html.js' ]
expect(tokens[6]).toEqual value: '`', scopes: [ 'source.js', 'string.quoted.template.html.js', 'punctuation.definition.string.begin.js' ]
expect(tokens[7]).toEqual value: 'hey <b>', scopes: ['source.js', 'string.quoted.template.html.js']
expect(tokens[8]).toEqual value: '${', scopes: ['source.js', 'string.quoted.template.html.js', 'source.js.embedded.source', 'punctuation.section.embedded.js']
expect(tokens[9]).toEqual value: 'name', scopes: ['source.js', 'string.quoted.template.html.js', 'source.js.embedded.source']
expect(tokens[10]).toEqual value: '}', scopes: ['source.js', 'string.quoted.template.html.js', 'source.js.embedded.source', 'punctuation.section.embedded.js']
expect(tokens[11]).toEqual value: '</b>', scopes: ['source.js', 'string.quoted.template.html.js']
expect(tokens[12]).toEqual value: '`', scopes: ['source.js', 'string.quoted.template.html.js', 'punctuation.definition.string.end.js']
describe "ES6 tagged HTML string templates with expanded function name", ->
it "tokenizes them as strings", ->
{tokens} = grammar.tokenizeLine('escapeHTML`hey <b>${name}</b>`')
expect(tokens[0]).toEqual value: 'escapeHTML', scopes: [ 'source.js', 'string.quoted.template.html.js', 'entity.name.function.js' ]
expect(tokens[1]).toEqual value: '`', scopes: [ 'source.js', 'string.quoted.template.html.js', 'punctuation.definition.string.begin.js' ]
expect(tokens[2]).toEqual value: 'hey <b>', scopes: ['source.js', 'string.quoted.template.html.js']
expect(tokens[3]).toEqual value: '${', scopes: ['source.js', 'string.quoted.template.html.js', 'source.js.embedded.source', 'punctuation.section.embedded.js']
expect(tokens[4]).toEqual value: 'name', scopes: ['source.js', 'string.quoted.template.html.js', 'source.js.embedded.source']
expect(tokens[5]).toEqual value: '}', scopes: ['source.js', 'string.quoted.template.html.js', 'source.js.embedded.source', 'punctuation.section.embedded.js']
expect(tokens[6]).toEqual value: '</b>', scopes: ['source.js', 'string.quoted.template.html.js']
expect(tokens[7]).toEqual value: '`', scopes: ['source.js', 'string.quoted.template.html.js', 'punctuation.definition.string.end.js']
describe "ES6 tagged HTML string templates with expanded function name and white space", ->
it "tokenizes them as strings", ->
{tokens} = grammar.tokenizeLine('escapeHTML `hey <b>${name}</b>`')
expect(tokens[0]).toEqual value: 'escapeHTML', scopes: [ 'source.js', 'string.quoted.template.html.js', 'entity.name.function.js' ]
expect(tokens[1]).toEqual value: ' ', scopes: [ 'source.js', 'string.quoted.template.html.js' ]
expect(tokens[2]).toEqual value: '`', scopes: [ 'source.js', 'string.quoted.template.html.js', 'punctuation.definition.string.begin.js' ]
expect(tokens[3]).toEqual value: 'hey <b>', scopes: ['source.js', 'string.quoted.template.html.js']
expect(tokens[4]).toEqual value: '${', scopes: ['source.js', 'string.quoted.template.html.js', 'source.js.embedded.source', 'punctuation.section.embedded.js']
expect(tokens[5]).toEqual value: 'name', scopes: ['source.js', 'string.quoted.template.html.js', 'source.js.embedded.source']
expect(tokens[6]).toEqual value: '}', scopes: ['source.js', 'string.quoted.template.html.js', 'source.js.embedded.source', 'punctuation.section.embedded.js']
expect(tokens[7]).toEqual value: '</b>', scopes: ['source.js', 'string.quoted.template.html.js']
expect(tokens[8]).toEqual value: '`', scopes: ['source.js', 'string.quoted.template.html.js', 'punctuation.definition.string.end.js']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment