Skip to content

Commit 41d9f61

Browse files
committed
FEAT: make textroles case insentive
fixes: 1195
1 parent 70c3d24 commit 41d9f61

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/guides-restructured-text/src/RestructuredText/TextRoles/DefaultTextRoleFactory.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ public function replaceTextRole(TextRole $newTextRole): void
5353

5454
public function getTextRole(string $name, string|null $domain = null): TextRole
5555
{
56-
if ($name === 'default') {
56+
$normalizedName = strtolower($name);
57+
if ($normalizedName === 'default') {
5758
return $this->defaultTextRole;
5859
}
5960

6061
if ($domain === null) {
61-
return $this->findTextRole($this->textRoles, $name);
62+
return $this->findTextRole($this->textRoles, $normalizedName);
6263
}
6364

6465
if (isset($this->domains[$domain])) {
65-
return $this->findTextRole($this->domains[$domain], $name);
66+
return $this->findTextRole($this->domains[$domain], $normalizedName);
6667
}
6768

6869
return $this->genericTextRole;

packages/guides-restructured-text/tests/unit/TextRoles/DefaultTextRoleFactoryTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function setUp(): void
2626
{
2727
$this->logger = new Logger('test');
2828
$this->defaultTextRoleFactory = new DefaultTextRoleFactory(
29-
new GenericTextRole(self::createMock(SettingsManager::class)),
29+
new GenericTextRole($this->createMock(SettingsManager::class)),
3030
new LiteralTextRole(),
3131
[],
3232
[],
@@ -45,4 +45,11 @@ public function testRegisteredTextRoleIsReturned(): void
4545
$textRole = $this->defaultTextRoleFactory->getTextRole('abbreviation');
4646
self::assertInstanceOf(AbbreviationTextRole::class, $textRole);
4747
}
48+
49+
public function testRegisteredTextRoleIsCaseInSensitive(): void
50+
{
51+
$this->defaultTextRoleFactory->registerTextRole(new AbbreviationTextRole($this->logger));
52+
$textRole = $this->defaultTextRoleFactory->getTextRole('ABbreviation');
53+
self::assertInstanceOf(AbbreviationTextRole::class, $textRole);
54+
}
4855
}

0 commit comments

Comments
 (0)