also looking at this
Port to latest zig-master
#2
53 files
+1149
-1017
| @@ -5,7 +5,7 @@ const RegexError = @import("regex").RegexError; | ||
| 5 | 5 | // Edge case: Empty input |
| 6 | 6 | test "edge: empty input with star" { |
| 7 | 7 | const allocator = std.testing.allocator; |
| 8 | var regex = try Regex.compile(allocator, "a*"); | |
| 8 | var regex = try Regex.compile(allocator, std.testing.io, "a*"); | |
| 9 | 9 | defer regex.deinit(); |
| 10 | 10 | |
| 11 | 11 | try std.testing.expect(try regex.isMatch("")); |
| @@ -13,7 +13,7 @@ test "edge: empty input with star" { | ||
| 13 | 13 | |
| 14 | 14 | test "edge: empty input with plus should fail" { |
| 15 | 15 | const allocator = std.testing.allocator; |
| 16 | var regex = try Regex.compile(allocator, "a+"); | |
| 16 | var regex = try Regex.compile(allocator, std.testing.io, "a+"); | |
| 17 | 17 | defer regex.deinit(); |
| 18 | 18 | |
| 19 | 19 | try std.testing.expect(!try regex.isMatch("")); |
| @@ -22,7 +22,7 @@ test "edge: empty input with plus should fail" { | ||
| 22 | 22 | // Edge case: Single character patterns |
| 23 | 23 | test "edge: single character literal" { |
| 24 | 24 | const allocator = std.testing.allocator; |
| 25 | var regex = try Regex.compile(allocator, "x"); | |
| 25 | var regex = try Regex.compile(allocator, std.testing.io, "x"); | |
| 26 | 26 | defer regex.deinit(); |
| 27 | 27 | |
| 28 | 28 | try std.testing.expect(try regex.isMatch("x")); |
| @@ -33,7 +33,7 @@ test "edge: single character literal" { | ||
| 33 | 33 | // Edge case: Nested quantifiers behavior |
| 34 | 34 | test "edge: star after plus" { |
| 35 | 35 | const allocator = std.testing.allocator; |
| 36 | var regex = try Regex.compile(allocator, "a+b*"); | |
| 36 | var regex = try Regex.compile(allocator, std.testing.io, "a+b*"); | |
| 37 | 37 | defer regex.deinit(); |
| 38 | 38 | |
| 39 | 39 | try std.testing.expect(try regex.isMatch("a")); |
| @@ -44,7 +44,7 @@ test "edge: star after plus" { | ||
| 44 | 44 | // Edge case: Multiple alternations |
| 45 | 45 | test "edge: multiple alternations" { |
| 46 | 46 | const allocator = std.testing.allocator; |
| 47 | var regex = try Regex.compile(allocator, "a|b|c|d"); | |
| 47 | var regex = try Regex.compile(allocator, std.testing.io, "a|b|c|d"); | |
| 48 | 48 | defer regex.deinit(); |
| 49 | 49 | |
| 50 | 50 | try std.testing.expect(try regex.isMatch("a")); |
| @@ -57,7 +57,7 @@ test "edge: multiple alternations" { | ||
| 57 | 57 | // Edge case: Alternation with empty branch |
| 58 | 58 | test "edge: alternation with quantifiers" { |
| 59 | 59 | const allocator = std.testing.allocator; |
| 60 | var regex = try Regex.compile(allocator, "a*|b+"); | |
| 60 | var regex = try Regex.compile(allocator, std.testing.io, "a*|b+"); | |
| 61 | 61 | defer regex.deinit(); |
| 62 | 62 | |
| 63 | 63 | try std.testing.expect(try regex.isMatch("")); |
| @@ -68,7 +68,7 @@ test "edge: alternation with quantifiers" { | ||
| 68 | 68 | // Edge case: Complex nested groups |
| 69 | 69 | test "edge: nested groups" { |
| 70 | 70 | const allocator = std.testing.allocator; |
| 71 | var regex = try Regex.compile(allocator, "((a))"); | |
| 71 | var regex = try Regex.compile(allocator, std.testing.io, "((a))"); | |
| 72 | 72 | defer regex.deinit(); |
| 73 | 73 | |
| 74 | 74 | try std.testing.expect(try regex.isMatch("a")); |
| @@ -77,7 +77,7 @@ test "edge: nested groups" { | ||
| 77 | 77 | // Edge case: Character class edge cases |
| 78 | 78 | test "edge: empty character class range" { |
| 79 | 79 | const allocator = std.testing.allocator; |
| 80 | var regex = try Regex.compile(allocator, "[a]"); | |
| 80 | var regex = try Regex.compile(allocator, std.testing.io, "[a]"); | |
| 81 | 81 | defer regex.deinit(); |
| 82 | 82 | |
| 83 | 83 | try std.testing.expect(try regex.isMatch("a")); |
| @@ -86,7 +86,7 @@ test "edge: empty character class range" { | ||
| 86 | 86 | |
| 87 | 87 | test "edge: character class with single range" { |
| 88 | 88 | const allocator = std.testing.allocator; |
| 89 | var regex = try Regex.compile(allocator, "[a-a]"); | |
| 89 | var regex = try Regex.compile(allocator, std.testing.io, "[a-a]"); | |
| 90 | 90 | defer regex.deinit(); |
| 91 | 91 | |
| 92 | 92 | try std.testing.expect(try regex.isMatch("a")); |
| @@ -95,7 +95,7 @@ test "edge: character class with single range" { | ||
| 95 | 95 | |
| 96 | 96 | test "edge: negated character class matching nothing in range" { |
| 97 | 97 | const allocator = std.testing.allocator; |
| 98 | var regex = try Regex.compile(allocator, "[^a-z]"); | |
| 98 | var regex = try Regex.compile(allocator, std.testing.io, "[^a-z]"); | |
| 99 | 99 | defer regex.deinit(); |
| 100 | 100 | |
| 101 | 101 | try std.testing.expect(try regex.isMatch("A")); |
| @@ -106,7 +106,7 @@ test "edge: negated character class matching nothing in range" { | ||
| 106 | 106 | // Edge case: Anchors at different positions |
| 107 | 107 | test "edge: start anchor not at beginning" { |
| 108 | 108 | const allocator = std.testing.allocator; |
| 109 | var regex = try Regex.compile(allocator, "a^b"); | |
| 109 | var regex = try Regex.compile(allocator, std.testing.io, "a^b"); | |
| 110 | 110 | defer regex.deinit(); |
| 111 | 111 | |
| 112 | 112 | // This should not match anything since ^ is not at the start |
| @@ -115,7 +115,7 @@ test "edge: start anchor not at beginning" { | ||
| 115 | 115 | |
| 116 | 116 | test "edge: end anchor not at end" { |
| 117 | 117 | const allocator = std.testing.allocator; |
| 118 | var regex = try Regex.compile(allocator, "a$b"); | |
| 118 | var regex = try Regex.compile(allocator, std.testing.io, "a$b"); | |
| 119 | 119 | defer regex.deinit(); |
| 120 | 120 | |
| 121 | 121 | // This should not match anything since $ is not at the end |
| @@ -125,7 +125,7 @@ test "edge: end anchor not at end" { | ||
| 125 | 125 | // Edge case: Dot matching |
| 126 | 126 | test "edge: dot with quantifiers" { |
| 127 | 127 | const allocator = std.testing.allocator; |
| 128 | var regex = try Regex.compile(allocator, ".*"); | |
| 128 | var regex = try Regex.compile(allocator, std.testing.io, ".*"); | |
| 129 | 129 | defer regex.deinit(); |
| 130 | 130 | |
| 131 | 131 | try std.testing.expect(try regex.isMatch("")); |
| @@ -136,7 +136,7 @@ test "edge: dot with quantifiers" { | ||
| 136 | 136 | // Edge case: Escape sequences |
| 137 | 137 | test "edge: escaped backslash" { |
| 138 | 138 | const allocator = std.testing.allocator; |
| 139 | var regex = try Regex.compile(allocator, "\\\\"); | |
| 139 | var regex = try Regex.compile(allocator, std.testing.io, "\\\\"); | |
| 140 | 140 | defer regex.deinit(); |
| 141 | 141 | |
| 142 | 142 | try std.testing.expect(try regex.isMatch("\\")); |
| @@ -145,7 +145,7 @@ test "edge: escaped backslash" { | ||
| 145 | 145 | |
| 146 | 146 | test "edge: escaped dot" { |
| 147 | 147 | const allocator = std.testing.allocator; |
| 148 | var regex = try Regex.compile(allocator, "\\."); | |
| 148 | var regex = try Regex.compile(allocator, std.testing.io, "\\."); | |
| 149 | 149 | defer regex.deinit(); |
| 150 | 150 | |
| 151 | 151 | try std.testing.expect(try regex.isMatch(".")); |
| @@ -155,7 +155,7 @@ test "edge: escaped dot" { | ||
| 155 | 155 | // Edge case: findAll edge cases |
| 156 | 156 | test "edge: findAll with no matches" { |
| 157 | 157 | const allocator = std.testing.allocator; |
| 158 | var regex = try Regex.compile(allocator, "x"); | |
| 158 | var regex = try Regex.compile(allocator, std.testing.io, "x"); | |
| 159 | 159 | defer regex.deinit(); |
| 160 | 160 | |
| 161 | 161 | const matches = try regex.findAll(allocator, "aaabbb"); |
| @@ -166,7 +166,7 @@ test "edge: findAll with no matches" { | ||
| 166 | 166 | |
| 167 | 167 | test "edge: findAll with overlapping potential matches" { |
| 168 | 168 | const allocator = std.testing.allocator; |
| 169 | var regex = try Regex.compile(allocator, "a+"); | |
| 169 | var regex = try Regex.compile(allocator, std.testing.io, "a+"); | |
| 170 | 170 | defer regex.deinit(); |
| 171 | 171 | |
| 172 | 172 | const matches = try regex.findAll(allocator, "aaa"); |
| @@ -186,7 +186,7 @@ test "edge: findAll with overlapping potential matches" { | ||
| 186 | 186 | // Edge case: replace edge cases |
| 187 | 187 | test "edge: replace with empty string" { |
| 188 | 188 | const allocator = std.testing.allocator; |
| 189 | var regex = try Regex.compile(allocator, "a"); | |
| 189 | var regex = try Regex.compile(allocator, std.testing.io, "a"); | |
| 190 | 190 | defer regex.deinit(); |
| 191 | 191 | |
| 192 | 192 | const result = try regex.replace(allocator, "banana", ""); |
| @@ -197,7 +197,7 @@ test "edge: replace with empty string" { | ||
| 197 | 197 | |
| 198 | 198 | test "edge: replace in empty string" { |
| 199 | 199 | const allocator = std.testing.allocator; |
| 200 | var regex = try Regex.compile(allocator, "a"); | |
| 200 | var regex = try Regex.compile(allocator, std.testing.io, "a"); | |
| 201 | 201 | defer regex.deinit(); |
| 202 | 202 | |
| 203 | 203 | const result = try regex.replace(allocator, "", "x"); |
| @@ -209,7 +209,7 @@ test "edge: replace in empty string" { | ||
| 209 | 209 | // Edge case: split edge cases |
| 210 | 210 | test "edge: split empty string" { |
| 211 | 211 | const allocator = std.testing.allocator; |
| 212 | var regex = try Regex.compile(allocator, ","); | |
| 212 | var regex = try Regex.compile(allocator, std.testing.io, ","); | |
| 213 | 213 | defer regex.deinit(); |
| 214 | 214 | |
| 215 | 215 | const parts = try regex.split(allocator, ""); |
| @@ -221,7 +221,7 @@ test "edge: split empty string" { | ||
| 221 | 221 | |
| 222 | 222 | test "edge: split with no delimiter found" { |
| 223 | 223 | const allocator = std.testing.allocator; |
| 224 | var regex = try Regex.compile(allocator, ","); | |
| 224 | var regex = try Regex.compile(allocator, std.testing.io, ","); | |
| 225 | 225 | defer regex.deinit(); |
| 226 | 226 | |
| 227 | 227 | const parts = try regex.split(allocator, "hello"); |
| @@ -234,7 +234,7 @@ test "edge: split with no delimiter found" { | ||
| 234 | 234 | // Edge case: Word boundaries |
| 235 | 235 | test "edge: word boundary at start" { |
| 236 | 236 | const allocator = std.testing.allocator; |
| 237 | var regex = try Regex.compile(allocator, "\\bword"); | |
| 237 | var regex = try Regex.compile(allocator, std.testing.io, "\\bword"); | |
| 238 | 238 | defer regex.deinit(); |
| 239 | 239 | |
| 240 | 240 | if (try regex.find("word here")) |match| { |
| @@ -248,7 +248,7 @@ test "edge: word boundary at start" { | ||
| 248 | 248 | |
| 249 | 249 | test "edge: word boundary at end" { |
| 250 | 250 | const allocator = std.testing.allocator; |
| 251 | var regex = try Regex.compile(allocator, "word\\b"); | |
| 251 | var regex = try Regex.compile(allocator, std.testing.io, "word\\b"); | |
| 252 | 252 | defer regex.deinit(); |
| 253 | 253 | |
| 254 | 254 | if (try regex.find("a word")) |match| { |
| @@ -263,7 +263,7 @@ test "edge: word boundary at end" { | ||
| 263 | 263 | // Edge case: Character classes with special chars |
| 264 | 264 | test "edge: whitespace character class" { |
| 265 | 265 | const allocator = std.testing.allocator; |
| 266 | var regex = try Regex.compile(allocator, "\\s+"); | |
| 266 | var regex = try Regex.compile(allocator, std.testing.io, "\\s+"); | |
| 267 | 267 | defer regex.deinit(); |
| 268 | 268 | |
| 269 | 269 | if (try regex.find("hello world")) |match| { |
| @@ -277,7 +277,7 @@ test "edge: whitespace character class" { | ||
| 277 | 277 | |
| 278 | 278 | test "edge: digit character class at boundaries" { |
| 279 | 279 | const allocator = std.testing.allocator; |
| 280 | var regex = try Regex.compile(allocator, "^\\d+$"); | |
| 280 | var regex = try Regex.compile(allocator, std.testing.io, "^\\d+$"); | |
| 281 | 281 | defer regex.deinit(); |
| 282 | 282 | |
| 283 | 283 | try std.testing.expect(try regex.isMatch("123")); |