@@ -26,6 +26,15 @@ public function testPreLex(string $input, string $expectedOutput): void
2626 $ this ->assertSame ($ expectedOutput , $ lexer ->preLexComponents ($ input ));
2727 }
2828
29+ /**
30+ * @dataProvider getLexTestsWhithShortOptions
31+ */
32+ public function testPreLexWithShortSyntax (string $ input , string $ expectedOutput ): void
33+ {
34+ $ lexer = new TwigPreLexer (withShortSyntax: true );
35+ $ this ->assertSame ($ expectedOutput , $ lexer ->preLexComponents ($ input ));
36+ }
37+
2938 /**
3039 * @dataProvider getInvalidSyntaxTests
3140 */
@@ -376,6 +385,12 @@ public static function getLexTests(): iterable
376385 '<twig:foobar bar="baz" {{ ...attr }}>content</twig:foobar> ' ,
377386 '{% component \'foobar \' with { bar: \'baz \', ...attr } %}{% block content %}content{% endblock %}{% endcomponent %} ' ,
378387 ];
388+
389+ yield 'jsx_component_simple_component_not_enabled_by_default ' => [
390+ '<Foo /> ' ,
391+ '<Foo /> ' ,
392+ ];
393+
379394 yield 'component_with_comment_line ' => [
380395 "<twig:foo \n # bar \n /> " ,
381396 '{{ component( \'foo \') }} ' ,
@@ -437,4 +452,79 @@ public static function getLexTests(): iterable
437452 TWIG ,
438453 ];
439454 }
455+
456+ public function getLexTestsWhithShortOptions ()
457+ {
458+ yield 'not_a_component ' => [
459+ '<foo /> ' ,
460+ '<foo /> ' ,
461+ ];
462+
463+ yield 'jsx_component_simple_component ' => [
464+ '<Foo /> ' ,
465+ '{{ component( \'foo \') }} ' ,
466+ ];
467+
468+ yield 'jsx_component_attribute_with_no_value_and_no_attributes ' => [
469+ '<Foo/> ' ,
470+ '{{ component( \'foo \') }} ' ,
471+ ];
472+
473+ yield 'jsx_component_with_default_block_content ' => [
474+ '<Foo>Foo</Foo> ' ,
475+ '{% component \'foo \' %}{% block content %}Foo{% endblock %}{% endcomponent %} ' ,
476+ ];
477+
478+ yield 'jsx_component_with_default_block_that_holds_a_component_and_multi_blocks ' => [
479+ '<Foo>Foo <twig:bar /><twig:block name="other_block">Other block</twig:block></Foo> ' ,
480+ '{% component \'foo \' %}{% block content %}Foo {{ component( \'bar \') }}{% endblock %}{% block other_block %}Other block{% endblock %}{% endcomponent %} ' ,
481+ ];
482+
483+ yield 'jsx_component_with_character_:_on_his_name ' => [
484+ '<Foo:bar></Foo:bar> ' ,
485+ '{% component \'foo:bar \' %}{% endcomponent %} ' ,
486+ ];
487+
488+ yield 'jsx_component_with_character_-_on_his_name ' => [
489+ '<Foo-bar></Foo-bar> ' ,
490+ '{% component \'foo-bar \' %}{% endcomponent %} ' ,
491+ ];
492+
493+ yield 'jsx_component_with_character_._on_his_name ' => [
494+ '<Foo.bar></Foo.bar> ' ,
495+ '{% component \'foo.bar \' %}{% endcomponent %} ' ,
496+ ];
497+
498+ yield 'jsx_component_with_block ' => [
499+ '<SuccessAlert>
500+ <Block name="alert_message">
501+ xxxx
502+ </Block>
503+ </SuccessAlert> ' ,
504+ '{% component \'successAlert \' %}
505+ {% block alert_message %}
506+ xxxx
507+ {% endblock %}
508+ {% endcomponent %} ' ,
509+ ];
510+
511+ yield 'jsx_component_with_sub_blocks ' => [
512+ '<SuccessAlert>
513+ <Message name="alert_message">
514+ <Icon name="success" />
515+ </Message>
516+ <Message name="alert_message">
517+ <Icon name="success" />
518+ </Message>
519+ </SuccessAlert> ' ,
520+ '{% component \'successAlert \' %}
521+ {% block content %}{% component \'message \' with { name: \'alert_message \' } %}
522+ {% block content %}{{ component( \'icon \', { name: \'success \' }) }}
523+ {% endblock %}{% endcomponent %}
524+ {% component \'message \' with { name: \'alert_message \' } %}
525+ {% block content %}{{ component( \'icon \', { name: \'success \' }) }}
526+ {% endblock %}{% endcomponent %}
527+ {% endblock %}{% endcomponent %} ' ,
528+ ];
529+ }
440530}
0 commit comments