@@ -70,4 +70,59 @@ public function testHash(): void
7070 $ hash = Utils::hash ('lorem ipsum dolor sit amet ' );
7171 self ::assertSame ('201730d4278e576b25515bd90c6072d3 ' , $ hash );
7272 }
73+
74+ /**
75+ * @dataProvider domainProvider
76+ */
77+ public function testNaturalSortOrdersDomainsCorrectly (array $ input , array $ expected ): void
78+ {
79+ $ result = Utils::naturalSort ($ input );
80+ self ::assertSame ($ expected , $ result );
81+ }
82+
83+ public function domainProvider (): array
84+ {
85+ return [
86+ 'Numerical sorting with leading zeros ' => [
87+ ['47gmail.com ' , '047gmail.com ' , '47bmt.com ' ],
88+ ['47bmt.com ' , '047gmail.com ' , '47gmail.com ' ],
89+ ],
90+ 'Mixed numerical/alpha segments ' => [
91+ ['img12.com ' , 'img2.com ' , 'img1.com ' ],
92+ ['img1.com ' , 'img2.com ' , 'img12.com ' ],
93+ ],
94+ 'Natural equivalence with string fallback ' => [
95+ ['apple01.com ' , 'apple1.com ' , 'apple001.com ' ],
96+ ['apple001.com ' , 'apple01.com ' , 'apple1.com ' ],
97+ ],
98+ 'Different TLDs with same name ' => [
99+ ['test.net ' , 'test.com ' , 'test.org ' ],
100+ ['test.com ' , 'test.net ' , 'test.org ' ],
101+ ],
102+ 'Complex domain patterns ' => [
103+ ['1a.example.com ' , 'a1.example.com ' , '01a.example.com ' ],
104+ ['01a.example.com ' , '1a.example.com ' , 'a1.example.com ' ],
105+ ],
106+ 'Subdomain sorting ' => [
107+ ['blog.47gmail.com ' , '047gmail.com ' , 'mail.47gmail.com ' ],
108+ ['047gmail.com ' , 'blog.47gmail.com ' , 'mail.47gmail.com ' ],
109+ ],
110+ 'Numerical TLDs (uncommon but valid) ' => [
111+ ['example.42 ' , 'example.7 ' , 'example.007 ' ],
112+ ['example.007 ' , 'example.7 ' , 'example.42 ' ],
113+ ],
114+ 'Empty ' => [
115+ [],
116+ [],
117+ ],
118+ 'Single ' => [
119+ ['single.com ' ],
120+ ['single.com ' ],
121+ ],
122+ 'Duplicates ' => [
123+ ['dup.com ' , 'dup.com ' ],
124+ ['dup.com ' , 'dup.com ' ],
125+ ],
126+ ];
127+ }
73128}
0 commit comments