|
| 1 | +# -*- coding: utf-8 -*- # |
| 2 | +# frozen_string_literal: true |
| 3 | + |
| 4 | +describe Rouge::Lexers::Gts do |
| 5 | + let(:subject) { Rouge::Lexers::Gts.new } |
| 6 | + |
| 7 | + describe 'guessing' do |
| 8 | + include Support::Guessing |
| 9 | + |
| 10 | + it 'guesses by filename' do |
| 11 | + assert_guess :filename => 'app/components/ui/form.gts' |
| 12 | + assert_guess :filename => 'app/templates/form.gts' |
| 13 | + assert_guess :filename => 'tests/integration/components/ui/form-test.gts' |
| 14 | + end |
| 15 | + |
| 16 | + it 'guesses by mimetype' do |
| 17 | + assert_guess :mimetype => 'text/x-gts' |
| 18 | + assert_guess :mimetype => 'application/x-gts' |
| 19 | + end |
| 20 | + end |
| 21 | + |
| 22 | + describe 'lexing' do |
| 23 | + include Support::Lexing |
| 24 | + |
| 25 | + it 'lexes the opening <template> tag' do |
| 26 | + assert_tokens_equal '<template>', |
| 27 | + ["Name.Tag", "<"], ["Keyword", "template"], ["Name.Tag", ">"] |
| 28 | + end |
| 29 | + |
| 30 | + it 'lexes the closing </template> tag' do |
| 31 | + assert_tokens_equal '<template></template>', |
| 32 | + ["Name.Tag", "<"], ["Keyword", "template"], ["Name.Tag", "></"], ["Keyword", "template"], ["Name.Tag", ">"] |
| 33 | + assert_tokens_equal '<template> </template>', |
| 34 | + ["Name.Tag", "<"], ["Keyword", "template"], ["Name.Tag", ">"], ["Text", " "], ["Name.Tag", "</"], ["Keyword", "template"], ["Name.Tag", ">"] |
| 35 | + end |
| 36 | + |
| 37 | + it 'lexes a Glimmer component' do |
| 38 | + code = <<~FILE |
| 39 | + import Component from '@glimmer/component'; |
| 40 | + import { t } from 'ember-intl'; |
| 41 | +
|
| 42 | + interface HelloSignature { |
| 43 | + Args: { |
| 44 | + name: string; |
| 45 | + }; |
| 46 | + } |
| 47 | +
|
| 48 | + export default class Hello extends Component<HelloSignature> { |
| 49 | + <template> |
| 50 | + <div data-test-message> |
| 51 | + {{t "hello.message" name=@name}} |
| 52 | + </div> |
| 53 | + </template> |
| 54 | + } |
| 55 | + FILE |
| 56 | + |
| 57 | + assert_no_errors code |
| 58 | + end |
| 59 | + |
| 60 | + it 'lexes a template-only component (1)' do |
| 61 | + code = <<~FILE |
| 62 | + import type { TOC } from '@ember/component/template-only'; |
| 63 | + import { t } from 'ember-intl'; |
| 64 | +
|
| 65 | + interface HelloSignature { |
| 66 | + Args: { |
| 67 | + name: string; |
| 68 | + }; |
| 69 | + } |
| 70 | +
|
| 71 | + const Hello: TOC<HelloSignature> = <template> |
| 72 | + <div data-test-message> |
| 73 | + {{t "hello.message" name=@name}} |
| 74 | + </div> |
| 75 | + </template>; |
| 76 | +
|
| 77 | + export default Hello; |
| 78 | + FILE |
| 79 | + |
| 80 | + assert_no_errors code |
| 81 | + end |
| 82 | + |
| 83 | + it 'lexes a template-only component (2)' do |
| 84 | + code = <<~FILE |
| 85 | + import type { TOC } from '@ember/component/template-only'; |
| 86 | + import { t } from 'ember-intl'; |
| 87 | +
|
| 88 | + interface HelloSignature { |
| 89 | + Args: { |
| 90 | + name: string; |
| 91 | + }; |
| 92 | + } |
| 93 | +
|
| 94 | + <template> |
| 95 | + <div data-test-message> |
| 96 | + {{t "hello.message" name=@name}} |
| 97 | + </div> |
| 98 | + </template> satisfies TOC<HelloSignature>; |
| 99 | + FILE |
| 100 | + |
| 101 | + assert_no_errors code |
| 102 | + end |
| 103 | + |
| 104 | + it 'lexes a rendering test' do |
| 105 | + code = <<~FILE |
| 106 | + import { render } from '@ember/test-helpers'; |
| 107 | + import { setupIntl } from 'ember-intl/test-support'; |
| 108 | + import { setupRenderingTest } from 'ember-qunit'; |
| 109 | + import Hello from 'my-app/components/hello'; |
| 110 | + import { module, test } from 'qunit'; |
| 111 | +
|
| 112 | + module('Integration | Component | hello', function (hooks) { |
| 113 | + setupRenderingTest(hooks); |
| 114 | + setupIntl(hooks, 'en-us'); |
| 115 | +
|
| 116 | + test('it renders', async function (assert) { |
| 117 | + await render( |
| 118 | + <template> |
| 119 | + <Hello @name="Zoey" /> |
| 120 | + </template> |
| 121 | + ); |
| 122 | +
|
| 123 | + assert.dom('[data-test-message]').hasText('Hello, Zoey!'); |
| 124 | + }); |
| 125 | + }); |
| 126 | + FILE |
| 127 | + |
| 128 | + # Currently unable to assert with `assert_no_errors` because |
| 129 | + # the `handlebars` lexer doesn't support arguments like `@name` |
| 130 | + assert_tokens_includes code, |
| 131 | + ["Name.Tag", "<"], ["Keyword", "template"], ["Name.Tag", ">"] |
| 132 | + end |
| 133 | + end |
| 134 | +end |
0 commit comments