@@ -17,25 +17,25 @@ BEGIN {
1717subtest ' Character class with single quotes in range' => sub {
1818 # The problematic pattern that caused the original error
1919 my $gen = Data::Random::String::Matches-> new(qr / ^[!#-'*+\\ -\\ .\\ ^_`|~0-9A-Za-z]+$ / );
20-
20+
2121 # Should not die
2222 my $str ;
2323 eval {
2424 $str = $gen -> generate();
2525 };
26-
26+
2727 ok(!$@ , ' Generates without error' ) or diag(" Error: $@ " );
2828 ok(defined $str , ' Generated string is defined' );
29-
29+
3030 if (defined $str ) {
3131 # Verify it matches the pattern
3232 like($str , qr / ^[!#-'*+\\ -\\ .\\ ^_`|~0-9A-Za-z]+$ / , ' Generated string matches pattern' );
33-
33+
3434 # Check that string contains valid characters
3535 my @chars = split //, $str ;
3636 for my $char (@chars ) {
3737 my $ord = ord ($char );
38- # Valid ranges: ! (33), #-' (35-39), * (42), + (43), - (45), . (46),
38+ # Valid ranges: ! (33), #-' (35-39), * (42), + (43), - (45), . (46),
3939 # ^ (94), _ (95), ` (96), | (124), ~ (126), 0-9 (48-57), A-Z (65-90), a-z (97-122)
4040 ok(
4141 $char =~ / [!#-'*+\-\.\^ _`|~0-9A-Za-z]/ ,
@@ -48,11 +48,11 @@ subtest 'Character class with single quotes in range' => sub {
4848subtest ' Character class with range starting after quote' => sub {
4949 # Range #-' includes: # $ % & '
5050 my $gen = Data::Random::String::Matches-> new(qr / [#-']/ );
51-
51+
5252 my $str = $gen -> generate();
5353 ok(defined $str , ' Generated string defined' );
5454 like($str , qr / ^[#-']$ / , ' Matches range #-\' ' );
55-
55+
5656 # Verify it's one of the expected characters
5757 ok($str =~ / ^[#\$ %&']$ / , " Character is in range: $str " );
5858};
@@ -64,11 +64,11 @@ subtest 'Character class with quote as range end' => sub {
6464 qr / ["-']/ , # " # $ % & '
6565 qr / [#-']/ , # # $ % & '
6666 );
67-
67+
6868 for my $pattern (@test_patterns ) {
6969 my $gen = Data::Random::String::Matches-> new($pattern );
7070 my $str = $gen -> generate();
71-
71+
7272 ok(defined $str , " Pattern $pattern generates successfully" );
7373 like($str , $pattern , ' Generated string matches pattern' );
7474 }
@@ -77,52 +77,51 @@ subtest 'Character class with quote as range end' => sub {
7777subtest ' Character class with double quotes in range' => sub {
7878 # Range with double quotes
7979 my $gen = Data::Random::String::Matches-> new(qr / [!-"]/ );
80-
80+
8181 my $str = $gen -> generate();
8282 ok(defined $str , ' Generated with double quote range' );
8383 like($str , qr / ^[!-"]$ / , ' Matches range with double quote' );
84-
84+
8585 # Should be ! or "
8686 ok($str eq ' !' || $str eq ' "' , " Character is ! or \" : got '$str '" );
8787};
8888
8989subtest ' Character class with backtick' => sub {
9090 # Backtick in character class
9191 my $gen = Data::Random::String::Matches-> new(qr / [_`a]/ );
92-
92+
9393 my $str = $gen -> generate();
9494 ok(defined $str , ' Generated with backtick' );
9595 like($str , qr / ^[_`a]$ / , ' Matches pattern with backtick' );
96-
96+
9797 ok($str =~ / ^[_`a]$ / , " Character is valid: $str " );
9898};
9999
100100subtest ' Character class with escaped special chars' => sub {
101101 # Pattern with escaped special characters
102102 my $gen = Data::Random::String::Matches-> new(qr / [a\- z]/ );
103-
103+
104104 my $str = $gen -> generate();
105105 ok(defined $str , ' Generated with escaped dash' );
106-
106+
107107 # Should be 'a', '-', or 'z' (not a range because dash is escaped)
108108 ok($str =~ / ^[az\- ]$ / , " Character is a, z, or dash: $str " );
109109};
110110
111111subtest ' Character class with multiple quote types' => sub {
112112 # Mix of single and double quotes
113113 my $gen = Data::Random::String::Matches-> new(qr / ["'`]/ );
114-
114+
115115 my $str = $gen -> generate();
116116 ok(defined $str , ' Generated with multiple quote types' );
117- ok($str eq ' "' || $str eq " '" || $str eq ' `' ,
118- " Character is a quote type: $str " );
117+ ok($str eq ' "' || $str eq " '" || $str eq ' `' , " Character is a quote type: $str " );
119118};
120119
121120subtest ' Complex character class from original error' => sub {
122121 # Full pattern that caused the error
123122 my $pattern = qr / ^[!#-'*+\\ -\\ .\\ ^_`|~0-9A-Za-z]+$ / ;
124123 my $gen = Data::Random::String::Matches-> new($pattern );
125-
124+
126125 # Generate multiple times to ensure consistency
127126 for my $i (1..10) {
128127 my $str = $gen -> generate();
@@ -146,28 +145,27 @@ subtest 'Character class range boundaries with quotes' => sub {
146145 chars => [" '" , ' (' , ' )' , ' *' ],
147146 },
148147 );
149-
148+
150149 for my $test (@test_cases ) {
151150 my $gen = Data::Random::String::Matches-> new($test -> {pattern });
152-
151+
153152 # Generate multiple strings
154153 my %seen ;
155154 for (1..50) {
156155 my $str = $gen -> generate();
157156 $seen {$str }++;
158157 }
159-
158+
160159 # Check we only got valid characters
161160 for my $char (keys %seen ) {
162161 ok(
163162 (grep { $_ eq $char } @{$test -> {chars }}),
164163 " $test ->{desc}: Character '$char ' is valid"
165164 );
166165 }
167-
166+
168167 # Should have some variety (at least 2 different chars in 50 tries)
169- cmp_ok(scalar keys %seen , ' >=' , 2,
170- " $test ->{desc}: Generated variety" );
168+ cmp_ok(scalar keys %seen , ' >=' , 2, " $test ->{desc}: Generated variety" );
171169 }
172170};
173171
@@ -176,34 +174,33 @@ subtest 'Escaped vs unescaped dash in character class' => sub {
176174 my $gen1 = Data::Random::String::Matches-> new(qr / [a\- z]/ );
177175 my %chars1 ;
178176 $chars1 {$gen1 -> generate()}++ for (1..30);
179-
177+
180178 # Should only see a, -, z (not b, c, d, etc.)
181179 for my $char (keys %chars1 ) {
182180 ok($char =~ / ^[az\- ]$ / , " Escaped dash pattern: got '$char '" );
183181 }
184-
182+
185183 # Unescaped dash: range
186184 my $gen2 = Data::Random::String::Matches-> new(qr / [a-z]/ );
187185 my %chars2 ;
188186 $chars2 {$gen2 -> generate()}++ for (1..30);
189-
187+
190188 # Should see variety of lowercase letters
191- ok(scalar (keys %chars2 ) >= 5,
192- ' Unescaped dash creates range with variety' );
189+ ok(scalar (keys %chars2 ) >= 5, ' Unescaped dash creates range with variety' );
193190};
194191
195192subtest ' Validate pattern_info with quotes' => sub {
196193 # Ensure pattern_info doesn't crash on these patterns
197194 my $gen = Data::Random::String::Matches-> new(qr / ^[!#-'*+\\ -\\ .\\ ^_`|~0-9A-Za-z]+$ / );
198-
195+
199196 my $info ;
200197 eval {
201198 $info = $gen -> pattern_info();
202199 };
203-
200+
204201 ok(!$@ , ' pattern_info does not crash' ) or diag(" Error: $@ " );
205202 ok(defined $info , ' pattern_info returns defined value' );
206-
203+
207204 if (defined $info ) {
208205 ok(exists $info -> {min_length }, ' Has min_length' );
209206 ok(exists $info -> {max_length }, ' Has max_length' );
@@ -213,20 +210,20 @@ subtest 'Validate pattern_info with quotes' => sub {
213210
214211subtest ' Generate many with quote patterns' => sub {
215212 my $gen = Data::Random::String::Matches-> new(qr / [!#-']/ );
216-
213+
217214 # Pattern [!#-'] has 6 possible characters: ! " # $ % & '
218215 # So we can only generate at most 6 unique single-char strings
219216 my @strings = $gen -> generate_many(6, 1);
220-
217+
221218 cmp_ok(scalar @strings , ' >=' , 5, ' Generated at least 5 unique strings' )
222219 or diag(' Only got ' , scalar (@strings ));
223220 cmp_ok(scalar @strings , ' <=' , 6, ' Generated at most 6 unique strings (the maximum possible)' );
224-
221+
225222 # All should match
226223 for my $str (@strings ) {
227224 like($str , qr / ^[!#-']$ / , " String '$str ' matches pattern" );
228225 }
229-
226+
230227 # Check uniqueness
231228 my %seen ;
232229 for my $str (@strings ) {
@@ -237,14 +234,14 @@ subtest 'Generate many with quote patterns' => sub {
237234
238235subtest ' Validate with quote patterns' => sub {
239236 my $gen = Data::Random::String::Matches-> new(qr / [#-']/ );
240-
237+
241238 # Test valid characters in range
242239 ok($gen -> validate(' #' ), ' Validates #' );
243240 ok($gen -> validate(' $' ), ' Validates $' );
244241 ok($gen -> validate(' %' ), ' Validates %' );
245242 ok($gen -> validate(' &' ), ' Validates &' );
246243 ok($gen -> validate(" '" ), ' Validates \' ' );
247-
244+
248245 # Test invalid characters
249246 ok(!$gen -> validate(' !' ), ' Rejects !' );
250247 ok(!$gen -> validate(' (' ), ' Rejects (' );
0 commit comments