also looking at this
Port to latest zig-master
#2
53 files
+1149
-1017
| @@ -5,7 +5,7 @@ const Regex = @import("regex").Regex; | ||
| 5 | 5 | |
| 6 | 6 | test "backreference: simple capture group replacement" { |
| 7 | 7 | const allocator = std.testing.allocator; |
| 8 | var regex = try Regex.compile(allocator, "(\\w+)"); | |
| 8 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)"); | |
| 9 | 9 | defer regex.deinit(); |
| 10 | 10 | |
| 11 | 11 | const result = try regex.replace(allocator, "hello", "$1!"); |
| @@ -16,7 +16,7 @@ test "backreference: simple capture group replacement" { | ||
| 16 | 16 | |
| 17 | 17 | test "backreference: swap two words" { |
| 18 | 18 | const allocator = std.testing.allocator; |
| 19 | var regex = try Regex.compile(allocator, "(\\w+) (\\w+)"); | |
| 19 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) (\\w+)"); | |
| 20 | 20 | defer regex.deinit(); |
| 21 | 21 | |
| 22 | 22 | const result = try regex.replace(allocator, "hello world", "$2 $1"); |
| @@ -27,7 +27,7 @@ test "backreference: swap two words" { | ||
| 27 | 27 | |
| 28 | 28 | test "backreference: repeat capture" { |
| 29 | 29 | const allocator = std.testing.allocator; |
| 30 | var regex = try Regex.compile(allocator, "(\\w+)"); | |
| 30 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)"); | |
| 31 | 31 | defer regex.deinit(); |
| 32 | 32 | |
| 33 | 33 | const result = try regex.replace(allocator, "test", "$1-$1"); |
| @@ -38,7 +38,7 @@ test "backreference: repeat capture" { | ||
| 38 | 38 | |
| 39 | 39 | test "backreference: multiple captures" { |
| 40 | 40 | const allocator = std.testing.allocator; |
| 41 | var regex = try Regex.compile(allocator, "(\\d+)-(\\d+)-(\\d+)"); | |
| 41 | var regex = try Regex.compile(allocator, std.testing.io, "(\\d+)-(\\d+)-(\\d+)"); | |
| 42 | 42 | defer regex.deinit(); |
| 43 | 43 | |
| 44 | 44 | const result = try regex.replace(allocator, "2025-10-26", "$3/$2/$1"); |
| @@ -49,7 +49,7 @@ test "backreference: multiple captures" { | ||
| 49 | 49 | |
| 50 | 50 | test "backreference: escaped dollar sign" { |
| 51 | 51 | const allocator = std.testing.allocator; |
| 52 | var regex = try Regex.compile(allocator, "(\\d+)"); | |
| 52 | var regex = try Regex.compile(allocator, std.testing.io, "(\\d+)"); | |
| 53 | 53 | defer regex.deinit(); |
| 54 | 54 | |
| 55 | 55 | const result = try regex.replace(allocator, "100", "$$$1"); |
| @@ -60,7 +60,7 @@ test "backreference: escaped dollar sign" { | ||
| 60 | 60 | |
| 61 | 61 | test "backreference: replaceAll with captures" { |
| 62 | 62 | const allocator = std.testing.allocator; |
| 63 | var regex = try Regex.compile(allocator, "(\\w+)@(\\w+)"); | |
| 63 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)@(\\w+)"); | |
| 64 | 64 | defer regex.deinit(); |
| 65 | 65 | |
| 66 | 66 | const result = try regex.replaceAll(allocator, "user@example and admin@test", "$1 at $2"); |
| @@ -71,7 +71,7 @@ test "backreference: replaceAll with captures" { | ||
| 71 | 71 | |
| 72 | 72 | test "backreference: extract and format phone numbers" { |
| 73 | 73 | const allocator = std.testing.allocator; |
| 74 | var regex = try Regex.compile(allocator, "(\\d{3})-(\\d{3})-(\\d{4})"); | |
| 74 | var regex = try Regex.compile(allocator, std.testing.io, "(\\d{3})-(\\d{3})-(\\d{4})"); | |
| 75 | 75 | defer regex.deinit(); |
| 76 | 76 | |
| 77 | 77 | const result = try regex.replace(allocator, "555-123-4567", "($1) $2-$3"); |
| @@ -82,7 +82,7 @@ test "backreference: extract and format phone numbers" { | ||
| 82 | 82 | |
| 83 | 83 | test "backreference: reformat dates" { |
| 84 | 84 | const allocator = std.testing.allocator; |
| 85 | var regex = try Regex.compile(allocator, "(\\d{4})-(\\d{2})-(\\d{2})"); | |
| 85 | var regex = try Regex.compile(allocator, std.testing.io, "(\\d{4})-(\\d{2})-(\\d{2})"); | |
| 86 | 86 | defer regex.deinit(); |
| 87 | 87 | |
| 88 | 88 | const result = try regex.replaceAll(allocator, "2025-10-26 and 2024-12-31", "$2/$3/$1"); |
| @@ -93,7 +93,7 @@ test "backreference: reformat dates" { | ||
| 93 | 93 | |
| 94 | 94 | test "backreference: wrap matches in tags" { |
| 95 | 95 | const allocator = std.testing.allocator; |
| 96 | var regex = try Regex.compile(allocator, "(\\w+)"); | |
| 96 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)"); | |
| 97 | 97 | defer regex.deinit(); |
| 98 | 98 | |
| 99 | 99 | const result = try regex.replaceAll(allocator, "hello world", "<b>$1</b>"); |
| @@ -104,7 +104,7 @@ test "backreference: wrap matches in tags" { | ||
| 104 | 104 | |
| 105 | 105 | test "backreference: invalid capture index" { |
| 106 | 106 | const allocator = std.testing.allocator; |
| 107 | var regex = try Regex.compile(allocator, "(\\w+)"); | |
| 107 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)"); | |
| 108 | 108 | defer regex.deinit(); |
| 109 | 109 | |
| 110 | 110 | // Only one capture group, $2 should be treated as literal |
| @@ -116,7 +116,7 @@ test "backreference: invalid capture index" { | ||
| 116 | 116 | |
| 117 | 117 | test "backreference: nested captures" { |
| 118 | 118 | const allocator = std.testing.allocator; |
| 119 | var regex = try Regex.compile(allocator, "((\\w+)@(\\w+))"); | |
| 119 | var regex = try Regex.compile(allocator, std.testing.io, "((\\w+)@(\\w+))"); | |
| 120 | 120 | defer regex.deinit(); |
| 121 | 121 | |
| 122 | 122 | const result = try regex.replace(allocator, "user@example.com", "Email: $1 (user=$2, domain=$3)"); |
| @@ -127,7 +127,7 @@ test "backreference: nested captures" { | ||
| 127 | 127 | |
| 128 | 128 | test "backreference: quote words" { |
| 129 | 129 | const allocator = std.testing.allocator; |
| 130 | var regex = try Regex.compile(allocator, "\\b(\\w+)\\b"); | |
| 130 | var regex = try Regex.compile(allocator, std.testing.io, "\\b(\\w+)\\b"); | |
| 131 | 131 | defer regex.deinit(); |
| 132 | 132 | |
| 133 | 133 | const result = try regex.replaceAll(allocator, "hello world", "'$1'"); |
| @@ -138,7 +138,7 @@ test "backreference: quote words" { | ||
| 138 | 138 | |
| 139 | 139 | test "backreference: transform case context" { |
| 140 | 140 | const allocator = std.testing.allocator; |
| 141 | var regex = try Regex.compile(allocator, "(Mr|Mrs|Ms) (\\w+)"); | |
| 141 | var regex = try Regex.compile(allocator, std.testing.io, "(Mr|Mrs|Ms) (\\w+)"); | |
| 142 | 142 | defer regex.deinit(); |
| 143 | 143 | |
| 144 | 144 | const result = try regex.replace(allocator, "Hello Mr Smith", "$1. $2"); |
| @@ -151,7 +151,7 @@ test "backreference: transform case context" { | ||
| 151 | 151 | |
| 152 | 152 | test "pattern backreference: basic \\1" { |
| 153 | 153 | const allocator = std.testing.allocator; |
| 154 | var regex = try Regex.compile(allocator, "(\\w+) \\1"); | |
| 154 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) \\1"); | |
| 155 | 155 | defer regex.deinit(); |
| 156 | 156 | |
| 157 | 157 | // Should match repeated words |
| @@ -171,7 +171,7 @@ test "pattern backreference: basic \\1" { | ||
| 171 | 171 | |
| 172 | 172 | test "pattern backreference: multiple captures" { |
| 173 | 173 | const allocator = std.testing.allocator; |
| 174 | var regex = try Regex.compile(allocator, "(\\w+) (\\w+) \\1 \\2"); | |
| 174 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) (\\w+) \\1 \\2"); | |
| 175 | 175 | defer regex.deinit(); |
| 176 | 176 | |
| 177 | 177 | try std.testing.expect(try regex.isMatch("foo bar foo bar")); |
| @@ -191,7 +191,7 @@ test "pattern backreference: multiple captures" { | ||
| 191 | 191 | |
| 192 | 192 | test "pattern backreference: with quantifiers" { |
| 193 | 193 | const allocator = std.testing.allocator; |
| 194 | var regex = try Regex.compile(allocator, "(\\d+)\\+\\1"); | |
| 194 | var regex = try Regex.compile(allocator, std.testing.io, "(\\d+)\\+\\1"); | |
| 195 | 195 | defer regex.deinit(); |
| 196 | 196 | |
| 197 | 197 | // Match patterns like "5+5", "123+123" |
| @@ -202,7 +202,7 @@ test "pattern backreference: with quantifiers" { | ||
| 202 | 202 | |
| 203 | 203 | test "pattern backreference: HTML tag matching" { |
| 204 | 204 | const allocator = std.testing.allocator; |
| 205 | var regex = try Regex.compile(allocator, "<(\\w+)>.*</\\1>"); | |
| 205 | var regex = try Regex.compile(allocator, std.testing.io, "<(\\w+)>.*</\\1>"); | |
| 206 | 206 | defer regex.deinit(); |
| 207 | 207 | |
| 208 | 208 | // Match matching HTML tags |
| @@ -213,7 +213,7 @@ test "pattern backreference: HTML tag matching" { | ||
| 213 | 213 | |
| 214 | 214 | test "pattern backreference: case sensitive" { |
| 215 | 215 | const allocator = std.testing.allocator; |
| 216 | var regex = try Regex.compile(allocator, "(\\w+) \\1"); | |
| 216 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) \\1"); | |
| 217 | 217 | defer regex.deinit(); |
| 218 | 218 | |
| 219 | 219 | // Backreferences should be case sensitive |
| @@ -223,7 +223,7 @@ test "pattern backreference: case sensitive" { | ||
| 223 | 223 | |
| 224 | 224 | test "pattern backreference: nested groups" { |
| 225 | 225 | const allocator = std.testing.allocator; |
| 226 | var regex = try Regex.compile(allocator, "((\\w)\\w)\\2"); | |
| 226 | var regex = try Regex.compile(allocator, std.testing.io, "((\\w)\\w)\\2"); | |
| 227 | 227 | defer regex.deinit(); |
| 228 | 228 | |
| 229 | 229 | // \\2 refers to second group (single char), so "aba" should match: |
| @@ -246,7 +246,7 @@ test "pattern backreference: nested groups" { | ||
| 246 | 246 | |
| 247 | 247 | test "pattern backreference: with alternation" { |
| 248 | 248 | const allocator = std.testing.allocator; |
| 249 | var regex = try Regex.compile(allocator, "(a|b)\\1"); | |
| 249 | var regex = try Regex.compile(allocator, std.testing.io, "(a|b)\\1"); | |
| 250 | 250 | defer regex.deinit(); |
| 251 | 251 | |
| 252 | 252 | try std.testing.expect(try regex.isMatch("aa")); |
| @@ -257,7 +257,7 @@ test "pattern backreference: with alternation" { | ||
| 257 | 257 | |
| 258 | 258 | test "pattern backreference: multiple in same pattern" { |
| 259 | 259 | const allocator = std.testing.allocator; |
| 260 | var regex = try Regex.compile(allocator, "(\\w)\\1\\1"); | |
| 260 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w)\\1\\1"); | |
| 261 | 261 | defer regex.deinit(); |
| 262 | 262 | |
| 263 | 263 | // Match three of the same character |
| @@ -269,7 +269,7 @@ test "pattern backreference: multiple in same pattern" { | ||
| 269 | 269 | |
| 270 | 270 | test "pattern backreference: findAll" { |
| 271 | 271 | const allocator = std.testing.allocator; |
| 272 | var regex = try Regex.compile(allocator, "(\\w+) \\1"); | |
| 272 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) \\1"); | |
| 273 | 273 | defer regex.deinit(); |
| 274 | 274 | |
| 275 | 275 | const matches = try regex.findAll(allocator, "foo foo bar bar baz qux"); |
| @@ -288,7 +288,7 @@ test "pattern backreference: findAll" { | ||
| 288 | 288 | |
| 289 | 289 | test "pattern backreference: quoted strings" { |
| 290 | 290 | const allocator = std.testing.allocator; |
| 291 | var regex = try Regex.compile(allocator, "(['\"]).*\\1"); | |
| 291 | var regex = try Regex.compile(allocator, std.testing.io, "(['\"]).*\\1"); | |
| 292 | 292 | defer regex.deinit(); |
| 293 | 293 | |
| 294 | 294 | // Match quoted strings with same quote type |