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 "named group: Python style (?P<name>...)" { |
| 7 | 7 | const allocator = std.testing.allocator; |
| 8 | var regex = try Regex.compile(allocator, "(?P<word>\\w+)"); | |
| 8 | var regex = try Regex.compile(allocator, std.testing.io, "(?P<word>\\w+)"); | |
| 9 | 9 | defer regex.deinit(); |
| 10 | 10 | |
| 11 | 11 | if (try regex.find("hello")) |match| { |
| @@ -33,7 +33,7 @@ test "named group: Python style (?P<name>...)" { | ||
| 33 | 33 | |
| 34 | 34 | test "named group: .NET/Perl style (?<name>...)" { |
| 35 | 35 | const allocator = std.testing.allocator; |
| 36 | var regex = try Regex.compile(allocator, "(?<digit>\\d+)"); | |
| 36 | var regex = try Regex.compile(allocator, std.testing.io, "(?<digit>\\d+)"); | |
| 37 | 37 | defer regex.deinit(); |
| 38 | 38 | |
| 39 | 39 | if (try regex.find("123")) |match| { |
| @@ -52,7 +52,7 @@ test "named group: .NET/Perl style (?<name>...)" { | ||
| 52 | 52 | |
| 53 | 53 | test "named group: multiple named groups" { |
| 54 | 54 | const allocator = std.testing.allocator; |
| 55 | var regex = try Regex.compile(allocator, "(?P<year>\\d{4})-(?P<month>\\d{2})-(?P<day>\\d{2})"); | |
| 55 | var regex = try Regex.compile(allocator, std.testing.io, "(?P<year>\\d{4})-(?P<month>\\d{2})-(?P<day>\\d{2})"); | |
| 56 | 56 | defer regex.deinit(); |
| 57 | 57 | |
| 58 | 58 | if (try regex.find("2025-10-27")) |match| { |
| @@ -79,7 +79,7 @@ test "named group: multiple named groups" { | ||
| 79 | 79 | |
| 80 | 80 | test "named group: mixed with numbered groups" { |
| 81 | 81 | const allocator = std.testing.allocator; |
| 82 | var regex = try Regex.compile(allocator, "(\\w+)@(?P<domain>\\w+\\.\\w+)"); | |
| 82 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)@(?P<domain>\\w+\\.\\w+)"); | |
| 83 | 83 | defer regex.deinit(); |
| 84 | 84 | |
| 85 | 85 | if (try regex.find("user@example.com")) |match| { |
| @@ -100,7 +100,7 @@ test "named group: mixed with numbered groups" { | ||
| 100 | 100 | |
| 101 | 101 | test "named group: non-existent name returns null" { |
| 102 | 102 | const allocator = std.testing.allocator; |
| 103 | var regex = try Regex.compile(allocator, "(?P<word>\\w+)"); | |
| 103 | var regex = try Regex.compile(allocator, std.testing.io, "(?P<word>\\w+)"); | |
| 104 | 104 | defer regex.deinit(); |
| 105 | 105 | |
| 106 | 106 | if (try regex.find("hello")) |match| { |
| @@ -119,7 +119,7 @@ test "named group: non-existent name returns null" { | ||
| 119 | 119 | |
| 120 | 120 | test "named group: with alternation" { |
| 121 | 121 | const allocator = std.testing.allocator; |
| 122 | var regex = try Regex.compile(allocator, "(?P<protocol>http|https)://(?P<host>[^/]+)"); | |
| 122 | var regex = try Regex.compile(allocator, std.testing.io, "(?P<protocol>http|https)://(?P<host>[^/]+)"); | |
| 123 | 123 | defer regex.deinit(); |
| 124 | 124 | |
| 125 | 125 | if (try regex.find("https://example.com")) |match| { |
| @@ -141,7 +141,7 @@ test "named group: with alternation" { | ||
| 141 | 141 | |
| 142 | 142 | test "named group: with quantifiers" { |
| 143 | 143 | const allocator = std.testing.allocator; |
| 144 | var regex = try Regex.compile(allocator, "(?P<tag><[^>]+>)(?P<content>.*)"); | |
| 144 | var regex = try Regex.compile(allocator, std.testing.io, "(?P<tag><[^>]+>)(?P<content>.*)"); | |
| 145 | 145 | defer regex.deinit(); |
| 146 | 146 | |
| 147 | 147 | if (try regex.find("<div>hello world</div>")) |match| { |
| @@ -163,7 +163,7 @@ test "named group: with quantifiers" { | ||
| 163 | 163 | |
| 164 | 164 | test "named group: nested groups" { |
| 165 | 165 | const allocator = std.testing.allocator; |
| 166 | var regex = try Regex.compile(allocator, "(?P<outer>(inner))"); | |
| 166 | var regex = try Regex.compile(allocator, std.testing.io, "(?P<outer>(inner))"); | |
| 167 | 167 | defer regex.deinit(); |
| 168 | 168 | |
| 169 | 169 | if (try regex.find("inner")) |match| { |
| @@ -186,7 +186,7 @@ test "named group: nested groups" { | ||
| 186 | 186 | |
| 187 | 187 | test "named group: with non-capturing group" { |
| 188 | 188 | const allocator = std.testing.allocator; |
| 189 | var regex = try Regex.compile(allocator, "(?:prefix-)?(?P<name>\\w+)"); | |
| 189 | var regex = try Regex.compile(allocator, std.testing.io, "(?:prefix-)?(?P<name>\\w+)"); | |
| 190 | 190 | defer regex.deinit(); |
| 191 | 191 | |
| 192 | 192 | if (try regex.find("prefix-test")) |match| { |
| @@ -206,7 +206,7 @@ test "named group: with non-capturing group" { | ||
| 206 | 206 | |
| 207 | 207 | test "named group: email parser example" { |
| 208 | 208 | const allocator = std.testing.allocator; |
| 209 | var regex = try Regex.compile(allocator, "(?P<user>[^@]+)@(?P<domain>[^@]+)"); | |
| 209 | var regex = try Regex.compile(allocator, std.testing.io, "(?P<user>[^@]+)@(?P<domain>[^@]+)"); | |
| 210 | 210 | defer regex.deinit(); |
| 211 | 211 | |
| 212 | 212 | if (try regex.find("john.doe@example.com")) |match| { |
| @@ -228,7 +228,7 @@ test "named group: email parser example" { | ||
| 228 | 228 | |
| 229 | 229 | test "named group: IP address parser" { |
| 230 | 230 | const allocator = std.testing.allocator; |
| 231 | var regex = try Regex.compile(allocator, "(?P<a>\\d+)\\.(?P<b>\\d+)\\.(?P<c>\\d+)\\.(?P<d>\\d+)"); | |
| 231 | var regex = try Regex.compile(allocator, std.testing.io, "(?P<a>\\d+)\\.(?P<b>\\d+)\\.(?P<c>\\d+)\\.(?P<d>\\d+)"); | |
| 232 | 232 | defer regex.deinit(); |
| 233 | 233 | |
| 234 | 234 | if (try regex.find("192.168.1.1")) |match| { |
| @@ -256,7 +256,7 @@ test "named group: IP address parser" { | ||
| 256 | 256 | |
| 257 | 257 | test "named group: findAll preserves names" { |
| 258 | 258 | const allocator = std.testing.allocator; |
| 259 | var regex = try Regex.compile(allocator, "(?P<num>\\d+)"); | |
| 259 | var regex = try Regex.compile(allocator, std.testing.io, "(?P<num>\\d+)"); | |
| 260 | 260 | defer regex.deinit(); |
| 261 | 261 | |
| 262 | 262 | var matches = try regex.findAll(allocator, "123 456 789"); |