From c65c220f3c3d97f1f79062a8b9b57486eafe0aef Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 16 Mar 2026 14:44:30 +0000 Subject: [PATCH 1/2] Add tests for AnchorUtilities::compute Co-authored-by: ineersa <4228843+ineersa@users.noreply.github.com> --- tests/AnchorUtilitiesTest.php | 149 ++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 tests/AnchorUtilitiesTest.php diff --git a/tests/AnchorUtilitiesTest.php b/tests/AnchorUtilitiesTest.php new file mode 100644 index 0000000..75bad89 --- /dev/null +++ b/tests/AnchorUtilitiesTest.php @@ -0,0 +1,149 @@ + $expectedStart + * @param list $expectedClose + * @param list $expectedText + */ + #[DataProvider('provideComputeSamples')] + public function testCompute(string $html, array $expectedStart, array $expectedClose, array $expectedText): void + { + $result = AnchorUtilities::compute($html); + + $this->assertSame([$expectedStart, $expectedClose, $expectedText], $result); + } + + /** + * @return array, 2: list, 3: list}> + */ + public static function provideComputeSamples(): array + { + return [ + 'plain text' => [ + 'Just some plain text.', + [], + [], + [ + ['text' => 'Just some plain text.', 'depth' => 0], + ], + ], + 'single anchor' => [ + 'Text link text.', + [1], + [1], + [ + ['text' => 'Text ', 'depth' => 0], + ['text' => 'link', 'depth' => 1], + ['text' => ' text.', 'depth' => 0], + ], + ], + 'nested anchors' => [ + '
link1 link2 link1 again
', + [1, 2], + [2, 1], + [ + ['text' => 'link1 ', 'depth' => 1], + ['text' => 'link2', 'depth' => 2], + ['text' => ' link1 again', 'depth' => 1], + ], + ], + 'sibling anchors' => [ + 'first and second', + [1, 1], + [1, 1], + [ + ['text' => 'first', 'depth' => 1], + ['text' => ' and ', 'depth' => 0], + ['text' => 'second', 'depth' => 1], + ], + ], + 'anchor with attributes and uppercase' => [ + 'caps', + [1], + [1], + [ + ['text' => 'caps', 'depth' => 1], + ], + ], + 'self-closing anchor' => [ + 'Before After', + [1], + [1], + [ + ['text' => 'Before ', 'depth' => 0], + ['text' => ' After', 'depth' => 0], + ], + ], + 'unclosed anchor' => [ + 'Text link', + [1], + [], + [ + ['text' => 'Text ', 'depth' => 0], + ['text' => 'link', 'depth' => 1], + ], + ], + 'extra closing anchor' => [ + 'Text link', + [], + [], + [ + ['text' => 'Text ', 'depth' => 0], + ['text' => ' link', 'depth' => 0], + ], + ], + 'mixed tags' => [ + '

Title

A link here.

', + [1], + [1], + [ + ['text' => 'Title', 'depth' => 0], + ['text' => 'A ', 'depth' => 0], + ['text' => 'link', 'depth' => 1], + ['text' => ' here.', 'depth' => 0], + ], + ], + 'anchor tag starting with spaces' => [ + '< a href="x">space', + [1], + [1], + [ + ['text' => 'space', 'depth' => 1], + ], + ], + 'non-anchor tag closing with />' => [ + '
text', + [], + [], + [ + ['text' => 'text', 'depth' => 0], + ], + ], + 'empty token simulation' => [ + '', + [1], + [1], + [], + ], + 'tag-like text but not tags' => [ + 'a < b and c > d', + [], + [], + [ + ['text' => 'a ', 'depth' => 0], + ['text' => ' d', 'depth' => 0], + ], + ], + ]; + } +} From 58f20c1ce745b4058a287223a473daa2691661b3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 16 Mar 2026 14:46:15 +0000 Subject: [PATCH 2/2] Fix code style in AnchorUtilitiesTest.php Co-authored-by: ineersa <4228843+ineersa@users.noreply.github.com> --- tests/AnchorUtilitiesTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/AnchorUtilitiesTest.php b/tests/AnchorUtilitiesTest.php index 75bad89..da5a754 100644 --- a/tests/AnchorUtilitiesTest.php +++ b/tests/AnchorUtilitiesTest.php @@ -11,8 +11,8 @@ final class AnchorUtilitiesTest extends TestCase { /** - * @param list $expectedStart - * @param list $expectedClose + * @param list $expectedStart + * @param list $expectedClose * @param list $expectedText */ #[DataProvider('provideComputeSamples')]