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 "non-capturing: basic non-capturing group" { |
| 7 | 7 | const allocator = std.testing.allocator; |
| 8 | var regex = try Regex.compile(allocator, "(?:\\d+)"); | |
| 8 | var regex = try Regex.compile(allocator, std.testing.io, "(?:\\d+)"); | |
| 9 | 9 | defer regex.deinit(); |
| 10 | 10 | |
| 11 | 11 | const result = try regex.find("123"); |
| @@ -22,7 +22,7 @@ test "non-capturing: basic non-capturing group" { | ||
| 22 | 22 | |
| 23 | 23 | test "non-capturing: mixed capturing and non-capturing" { |
| 24 | 24 | const allocator = std.testing.allocator; |
| 25 | var regex = try Regex.compile(allocator, "(\\w+)@(?:\\w+)\\.(\\w+)"); | |
| 25 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)@(?:\\w+)\\.(\\w+)"); | |
| 26 | 26 | defer regex.deinit(); |
| 27 | 27 | |
| 28 | 28 | const result = try regex.find("user@example.com"); |
| @@ -41,7 +41,7 @@ test "non-capturing: mixed capturing and non-capturing" { | ||
| 41 | 41 | |
| 42 | 42 | test "non-capturing: alternation in non-capturing group" { |
| 43 | 43 | const allocator = std.testing.allocator; |
| 44 | var regex = try Regex.compile(allocator, "(?:cat|dog) (\\w+)"); | |
| 44 | var regex = try Regex.compile(allocator, std.testing.io, "(?:cat|dog) (\\w+)"); | |
| 45 | 45 | defer regex.deinit(); |
| 46 | 46 | |
| 47 | 47 | const result1 = try regex.find("cat food"); |
| @@ -69,7 +69,7 @@ test "non-capturing: alternation in non-capturing group" { | ||
| 69 | 69 | |
| 70 | 70 | test "non-capturing: nested non-capturing groups" { |
| 71 | 71 | const allocator = std.testing.allocator; |
| 72 | var regex = try Regex.compile(allocator, "(?:(?:a|b)(?:c|d))"); | |
| 72 | var regex = try Regex.compile(allocator, std.testing.io, "(?:(?:a|b)(?:c|d))"); | |
| 73 | 73 | defer regex.deinit(); |
| 74 | 74 | |
| 75 | 75 | try std.testing.expect(try regex.isMatch("ac")); |
| @@ -82,7 +82,7 @@ test "non-capturing: nested non-capturing groups" { | ||
| 82 | 82 | test "non-capturing: capture numbering with non-capturing groups" { |
| 83 | 83 | const allocator = std.testing.allocator; |
| 84 | 84 | // (a) (?:b) (c) - should have captures $1=a, $2=c (not $1=a, $2=b, $3=c) |
| 85 | var regex = try Regex.compile(allocator, "(a)(?:b)(c)"); | |
| 85 | var regex = try Regex.compile(allocator, std.testing.io, "(a)(?:b)(c)"); | |
| 86 | 86 | defer regex.deinit(); |
| 87 | 87 | |
| 88 | 88 | const result = try regex.find("abc"); |
| @@ -100,7 +100,7 @@ test "non-capturing: capture numbering with non-capturing groups" { | ||
| 100 | 100 | |
| 101 | 101 | test "non-capturing: with quantifiers" { |
| 102 | 102 | const allocator = std.testing.allocator; |
| 103 | var regex = try Regex.compile(allocator, "(?:\\d+)+"); | |
| 103 | var regex = try Regex.compile(allocator, std.testing.io, "(?:\\d+)+"); | |
| 104 | 104 | defer regex.deinit(); |
| 105 | 105 | |
| 106 | 106 | try std.testing.expect(try regex.isMatch("123")); |
| @@ -110,7 +110,7 @@ test "non-capturing: with quantifiers" { | ||
| 110 | 110 | test "non-capturing: complex pattern" { |
| 111 | 111 | const allocator = std.testing.allocator; |
| 112 | 112 | // Simplified pattern - removed [\w.] which has parsing issues |
| 113 | var regex = try Regex.compile(allocator, "(?:https?://)?([a-z]+)(?:/\\w+)*"); | |
| 113 | var regex = try Regex.compile(allocator, std.testing.io, "(?:https?://)?([a-z]+)(?:/\\w+)*"); | |
| 114 | 114 | defer regex.deinit(); |
| 115 | 115 | |
| 116 | 116 | const result1 = try regex.find("http://example/path/to/page"); |
| @@ -138,7 +138,7 @@ test "non-capturing: complex pattern" { | ||
| 138 | 138 | |
| 139 | 139 | test "non-capturing: in replacement" { |
| 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"); |
| @@ -149,7 +149,7 @@ test "non-capturing: in replacement" { | ||
| 149 | 149 | |
| 150 | 150 | test "non-capturing: multiple non-capturing with one capturing" { |
| 151 | 151 | const allocator = std.testing.allocator; |
| 152 | var regex = try Regex.compile(allocator, "(?:a)(?:b)(c)(?:d)"); | |
| 152 | var regex = try Regex.compile(allocator, std.testing.io, "(?:a)(?:b)(c)(?:d)"); | |
| 153 | 153 | defer regex.deinit(); |
| 154 | 154 | |
| 155 | 155 | const result = try regex.find("abcd"); |
| @@ -166,7 +166,7 @@ test "non-capturing: multiple non-capturing with one capturing" { | ||
| 166 | 166 | |
| 167 | 167 | test "non-capturing: with character classes" { |
| 168 | 168 | const allocator = std.testing.allocator; |
| 169 | var regex = try Regex.compile(allocator, "(?:[a-z]+)@(\\w+)"); | |
| 169 | var regex = try Regex.compile(allocator, std.testing.io, "(?:[a-z]+)@(\\w+)"); | |
| 170 | 170 | defer regex.deinit(); |
| 171 | 171 | |
| 172 | 172 | const result = try regex.find("user@example"); |
| @@ -183,7 +183,7 @@ test "non-capturing: with character classes" { | ||
| 183 | 183 | |
| 184 | 184 | test "non-capturing: nested capturing inside non-capturing" { |
| 185 | 185 | const allocator = std.testing.allocator; |
| 186 | var regex = try Regex.compile(allocator, "(?:(\\d+):(\\d+))"); | |
| 186 | var regex = try Regex.compile(allocator, std.testing.io, "(?:(\\d+):(\\d+))"); | |
| 187 | 187 | defer regex.deinit(); |
| 188 | 188 | |
| 189 | 189 | const result = try regex.find("12:30"); |
| @@ -201,7 +201,7 @@ test "non-capturing: nested capturing inside non-capturing" { | ||
| 201 | 201 | |
| 202 | 202 | test "non-capturing: all groups non-capturing" { |
| 203 | 203 | const allocator = std.testing.allocator; |
| 204 | var regex = try Regex.compile(allocator, "(?:a)(?:b)(?:c)"); | |
| 204 | var regex = try Regex.compile(allocator, std.testing.io, "(?:a)(?:b)(?:c)"); | |
| 205 | 205 | defer regex.deinit(); |
| 206 | 206 | |
| 207 | 207 | const result = try regex.find("abc"); |
| @@ -218,7 +218,7 @@ test "non-capturing: all groups non-capturing" { | ||
| 218 | 218 | |
| 219 | 219 | test "non-capturing: with anchors" { |
| 220 | 220 | const allocator = std.testing.allocator; |
| 221 | var regex = try Regex.compile(allocator, "^(?:hello|hi) (\\w+)$"); | |
| 221 | var regex = try Regex.compile(allocator, std.testing.io, "^(?:hello|hi) (\\w+)$"); | |
| 222 | 222 | defer regex.deinit(); |
| 223 | 223 | |
| 224 | 224 | const result = try regex.find("hello world"); |
| @@ -237,7 +237,7 @@ test "non-capturing: with anchors" { | ||
| 237 | 237 | |
| 238 | 238 | test "non-capturing: replaceAll with non-capturing groups" { |
| 239 | 239 | const allocator = std.testing.allocator; |
| 240 | var regex = try Regex.compile(allocator, "(?:the|a) (\\w+)"); | |
| 240 | var regex = try Regex.compile(allocator, std.testing.io, "(?:the|a) (\\w+)"); | |
| 241 | 241 | defer regex.deinit(); |
| 242 | 242 | |
| 243 | 243 | const result = try regex.replaceAll(allocator, "the cat and a dog", "$1"); |
| @@ -248,7 +248,7 @@ test "non-capturing: replaceAll with non-capturing groups" { | ||
| 248 | 248 | |
| 249 | 249 | test "non-capturing: empty non-capturing group" { |
| 250 | 250 | const allocator = std.testing.allocator; |
| 251 | var regex = try Regex.compile(allocator, "a(?:)b"); | |
| 251 | var regex = try Regex.compile(allocator, std.testing.io, "a(?:)b"); | |
| 252 | 252 | defer regex.deinit(); |
| 253 | 253 | |
| 254 | 254 | try std.testing.expect(try regex.isMatch("ab")); |
| @@ -258,7 +258,7 @@ test "non-capturing: verify capture count" { | ||
| 258 | 258 | const allocator = std.testing.allocator; |
| 259 | 259 | |
| 260 | 260 | // Pattern with 3 non-capturing and 2 capturing groups |
| 261 | var regex = try Regex.compile(allocator, "(?:a)(b)(?:c)(d)(?:e)"); | |
| 261 | var regex = try Regex.compile(allocator, std.testing.io, "(?:a)(b)(?:c)(d)(?:e)"); | |
| 262 | 262 | defer regex.deinit(); |
| 263 | 263 | |
| 264 | 264 | // Should only have 2 captures, not 5 |