Skip to content

Commit 96b7c6f

Browse files
author
matheo
committed
add some tests and fix argument for self closing tags
1 parent 07ff0a3 commit 96b7c6f

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

src/TwigComponent/src/Twig/ComponentLexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ComponentLexer extends Lexer
1212
const COMPONENTS_REGEX = [
1313
'open_tags' => '/<\s*([A-Z][\w\-\:\.]+)\s*' . self::ATTRIBUTES_REGEX . '(\s?)+>/',
1414
'close_tags' => '/<\/\s*([A-Z][\w\-\:\.]+)\s*>/',
15-
'self_close_tags' => '/<\s*([A-Z][\w\-\:\.]+)\s*' . self::ATTRIBUTES_REGEX . '*(\s?)+\/>/',
15+
'self_close_tags' => '/<\s*([A-Z][\w\-\:\.]+)\s*' . self::ATTRIBUTES_REGEX . '(\s?)+\/>/',
1616
];
1717

1818
public function tokenize(Source $source): TokenStream
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<Component_a propA propB='hello'>
2+
</Component_a>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<Component_a propA propB='hello'/>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Symfony\UX\TwigComponent\Tests\Integration;
4+
5+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6+
use Twig\Environment;
7+
8+
class ComponentLexerTest extends KernelTestCase
9+
{
10+
public function testComponentSyntaxOpenTags(): void
11+
{
12+
$output = self::getContainer()->get(Environment::class)->render('tags/open_tag.html.twig');
13+
14+
$this->assertStringContainsString('propA: 1', $output);
15+
$this->assertStringContainsString('propB: hello', $output);
16+
}
17+
18+
public function testComponentSyntaxSelfClosingTags(): void
19+
{
20+
$output = self::getContainer()->get(Environment::class)->render('tags/self_closing_tag.html.twig');
21+
22+
$this->assertStringContainsString('propA: 1', $output);
23+
$this->assertStringContainsString('propB: hello', $output);
24+
}
25+
}

0 commit comments

Comments
 (0)