erb-spec.js 1.7 KB

1234567891011121314151617181920212223242526272829303132
  1. describe("TextMate HTML (Ruby - ERB) grammar", () => {
  2. let grammar = null;
  3. beforeEach(() => {
  4. atom.config.set('core.useTreeSitterParsers', false);
  5. waitsForPromise(() => atom.packages.activatePackage("language-ruby"));
  6. runs(() => grammar = atom.grammars.grammarForScopeName("text.html.erb"));
  7. });
  8. it("parses the grammar", () => {
  9. expect(grammar).toBeTruthy();
  10. expect(grammar.scopeName).toBe("text.html.erb");
  11. });
  12. it("tokenizes embedded ruby", () => {
  13. const {tokens} = grammar.tokenizeLine('<%= self %>');
  14. expect(tokens[0]).toEqual({value: '<%=', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'punctuation.section.embedded.begin.erb']});
  15. expect(tokens[1]).toEqual({value: ' ', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'source.ruby.embedded.erb']});
  16. expect(tokens[2]).toEqual({value: 'self', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'source.ruby.embedded.erb', 'variable.language.self.ruby']});
  17. expect(tokens[3]).toEqual({value: ' ', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'source.ruby.embedded.erb']});
  18. expect(tokens[4]).toEqual({value: '%>', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'punctuation.section.embedded.end.erb']});
  19. const lines = grammar.tokenizeLines('<%=\nself\n%>');
  20. expect(lines[0][0]).toEqual({value: '<%=', scopes: ['text.html.erb', 'meta.embedded.block.erb', 'punctuation.section.embedded.begin.erb']});
  21. expect(lines[1][0]).toEqual({value: 'self', scopes: ['text.html.erb', 'meta.embedded.block.erb', 'source.ruby.embedded.erb', 'variable.language.self.ruby']});
  22. expect(lines[2][0]).toEqual({value: '%>', scopes: ['text.html.erb', 'meta.embedded.block.erb', 'punctuation.section.embedded.end.erb']});
  23. });
  24. });