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 "lazy star: a*? matches minimal" { |
| 7 | 7 | const allocator = std.testing.allocator; |
| 8 | var regex = try Regex.compile(allocator, "a*?b"); | |
| 8 | var regex = try Regex.compile(allocator, std.testing.io, "a*?b"); | |
| 9 | 9 | defer regex.deinit(); |
| 10 | 10 | |
| 11 | 11 | // Greedy would match "aaab", lazy should match "b" |
| @@ -22,7 +22,7 @@ test "lazy star vs greedy star" { | ||
| 22 | 22 | const allocator = std.testing.allocator; |
| 23 | 23 | |
| 24 | 24 | // Greedy star |
| 25 | var greedy = try Regex.compile(allocator, "a*b"); | |
| 25 | var greedy = try Regex.compile(allocator, std.testing.io, "a*b"); | |
| 26 | 26 | defer greedy.deinit(); |
| 27 | 27 | |
| 28 | 28 | if (try greedy.find("aaab")) |match| { |
| @@ -35,7 +35,7 @@ test "lazy star vs greedy star" { | ||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | // Lazy star |
| 38 | var lazy = try Regex.compile(allocator, "a*?b"); | |
| 38 | var lazy = try Regex.compile(allocator, std.testing.io, "a*?b"); | |
| 39 | 39 | defer lazy.deinit(); |
| 40 | 40 | |
| 41 | 41 | if (try lazy.find("aaab")) |match| { |
| @@ -50,7 +50,7 @@ test "lazy star vs greedy star" { | ||
| 50 | 50 | |
| 51 | 51 | test "lazy plus: a+? matches minimal (at least one)" { |
| 52 | 52 | const allocator = std.testing.allocator; |
| 53 | var regex = try Regex.compile(allocator, "a+?b"); | |
| 53 | var regex = try Regex.compile(allocator, std.testing.io, "a+?b"); | |
| 54 | 54 | defer regex.deinit(); |
| 55 | 55 | |
| 56 | 56 | // Lazy plus must match at least one 'a' |
| @@ -67,7 +67,7 @@ test "lazy plus vs greedy plus" { | ||
| 67 | 67 | const allocator = std.testing.allocator; |
| 68 | 68 | |
| 69 | 69 | // Greedy plus |
| 70 | var greedy = try Regex.compile(allocator, "a+b"); | |
| 70 | var greedy = try Regex.compile(allocator, std.testing.io, "a+b"); | |
| 71 | 71 | defer greedy.deinit(); |
| 72 | 72 | |
| 73 | 73 | if (try greedy.find("aaab")) |match| { |
| @@ -80,7 +80,7 @@ test "lazy plus vs greedy plus" { | ||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // Lazy plus |
| 83 | var lazy = try Regex.compile(allocator, "a+?b"); | |
| 83 | var lazy = try Regex.compile(allocator, std.testing.io, "a+?b"); | |
| 84 | 84 | defer lazy.deinit(); |
| 85 | 85 | |
| 86 | 86 | if (try lazy.find("aaab")) |match| { |
| @@ -95,7 +95,7 @@ test "lazy plus vs greedy plus" { | ||
| 95 | 95 | |
| 96 | 96 | test "lazy optional: a?? matches minimal (zero)" { |
| 97 | 97 | const allocator = std.testing.allocator; |
| 98 | var regex = try Regex.compile(allocator, "a??b"); | |
| 98 | var regex = try Regex.compile(allocator, std.testing.io, "a??b"); | |
| 99 | 99 | defer regex.deinit(); |
| 100 | 100 | |
| 101 | 101 | // Lazy optional prefers zero matches |
| @@ -112,7 +112,7 @@ test "lazy optional vs greedy optional" { | ||
| 112 | 112 | const allocator = std.testing.allocator; |
| 113 | 113 | |
| 114 | 114 | // Greedy optional |
| 115 | var greedy = try Regex.compile(allocator, "a?b"); | |
| 115 | var greedy = try Regex.compile(allocator, std.testing.io, "a?b"); | |
| 116 | 116 | defer greedy.deinit(); |
| 117 | 117 | |
| 118 | 118 | if (try greedy.find("ab")) |match| { |
| @@ -125,7 +125,7 @@ test "lazy optional vs greedy optional" { | ||
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // Lazy optional |
| 128 | var lazy = try Regex.compile(allocator, "a??b"); | |
| 128 | var lazy = try Regex.compile(allocator, std.testing.io, "a??b"); | |
| 129 | 129 | defer lazy.deinit(); |
| 130 | 130 | |
| 131 | 131 | if (try lazy.find("ab")) |match| { |
| @@ -140,7 +140,7 @@ test "lazy optional vs greedy optional" { | ||
| 140 | 140 | |
| 141 | 141 | test "lazy repeat: a{2,4}? matches minimal" { |
| 142 | 142 | const allocator = std.testing.allocator; |
| 143 | var regex = try Regex.compile(allocator, "a{2,4}?b"); | |
| 143 | var regex = try Regex.compile(allocator, std.testing.io, "a{2,4}?b"); | |
| 144 | 144 | defer regex.deinit(); |
| 145 | 145 | |
| 146 | 146 | // Lazy repeat matches minimum (2 'a's) |
| @@ -157,7 +157,7 @@ test "lazy repeat vs greedy repeat" { | ||
| 157 | 157 | const allocator = std.testing.allocator; |
| 158 | 158 | |
| 159 | 159 | // Greedy repeat |
| 160 | var greedy = try Regex.compile(allocator, "a{2,4}b"); | |
| 160 | var greedy = try Regex.compile(allocator, std.testing.io, "a{2,4}b"); | |
| 161 | 161 | defer greedy.deinit(); |
| 162 | 162 | |
| 163 | 163 | if (try greedy.find("aaaaab")) |match| { |
| @@ -170,7 +170,7 @@ test "lazy repeat vs greedy repeat" { | ||
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // Lazy repeat |
| 173 | var lazy = try Regex.compile(allocator, "a{2,4}?b"); | |
| 173 | var lazy = try Regex.compile(allocator, std.testing.io, "a{2,4}?b"); | |
| 174 | 174 | defer lazy.deinit(); |
| 175 | 175 | |
| 176 | 176 | if (try lazy.find("aaaaab")) |match| { |
| @@ -185,7 +185,7 @@ test "lazy repeat vs greedy repeat" { | ||
| 185 | 185 | |
| 186 | 186 | test "lazy quantifier in alternation" { |
| 187 | 187 | const allocator = std.testing.allocator; |
| 188 | var regex = try Regex.compile(allocator, "a*?b|c"); | |
| 188 | var regex = try Regex.compile(allocator, std.testing.io, "a*?b|c"); | |
| 189 | 189 | defer regex.deinit(); |
| 190 | 190 | |
| 191 | 191 | try std.testing.expect(try regex.isMatch("b")); |
| @@ -195,7 +195,7 @@ test "lazy quantifier in alternation" { | ||
| 195 | 195 | |
| 196 | 196 | test "multiple lazy quantifiers" { |
| 197 | 197 | const allocator = std.testing.allocator; |
| 198 | var regex = try Regex.compile(allocator, "a*?b+?c"); | |
| 198 | var regex = try Regex.compile(allocator, std.testing.io, "a*?b+?c"); | |
| 199 | 199 | defer regex.deinit(); |
| 200 | 200 | |
| 201 | 201 | if (try regex.find("aaabbbbc")) |match| { |
| @@ -210,7 +210,7 @@ test "multiple lazy quantifiers" { | ||
| 210 | 210 | |
| 211 | 211 | test "lazy quantifier with character class" { |
| 212 | 212 | const allocator = std.testing.allocator; |
| 213 | var regex = try Regex.compile(allocator, "[a-z]+?\\d"); | |
| 213 | var regex = try Regex.compile(allocator, std.testing.io, "[a-z]+?\\d"); | |
| 214 | 214 | defer regex.deinit(); |
| 215 | 215 | |
| 216 | 216 | if (try regex.find("abc123")) |match| { |
| @@ -225,7 +225,7 @@ test "lazy quantifier with character class" { | ||
| 225 | 225 | |
| 226 | 226 | test "lazy star with dot" { |
| 227 | 227 | const allocator = std.testing.allocator; |
| 228 | var regex = try Regex.compile(allocator, ".*?x"); | |
| 228 | var regex = try Regex.compile(allocator, std.testing.io, ".*?x"); | |
| 229 | 229 | defer regex.deinit(); |
| 230 | 230 | |
| 231 | 231 | if (try regex.find("abcxyz")) |match| { |
| @@ -240,7 +240,7 @@ test "lazy star with dot" { | ||
| 240 | 240 | |
| 241 | 241 | test "lazy quantifier in capture group" { |
| 242 | 242 | const allocator = std.testing.allocator; |
| 243 | var regex = try Regex.compile(allocator, "(a+?)b"); | |
| 243 | var regex = try Regex.compile(allocator, std.testing.io, "(a+?)b"); | |
| 244 | 244 | defer regex.deinit(); |
| 245 | 245 | |
| 246 | 246 | if (try regex.find("aaab")) |match| { |
| @@ -258,7 +258,7 @@ test "lazy quantifier in capture group" { | ||
| 258 | 258 | |
| 259 | 259 | test "lazy repeat {n,}?" { |
| 260 | 260 | const allocator = std.testing.allocator; |
| 261 | var regex = try Regex.compile(allocator, "a{2,}?b"); | |
| 261 | var regex = try Regex.compile(allocator, std.testing.io, "a{2,}?b"); | |
| 262 | 262 | defer regex.deinit(); |
| 263 | 263 | |
| 264 | 264 | if (try regex.find("aaaaab")) |match| { |
| @@ -274,7 +274,7 @@ test "lazy repeat {n,}?" { | ||
| 274 | 274 | test "lazy quantifier backtracking" { |
| 275 | 275 | const allocator = std.testing.allocator; |
| 276 | 276 | // Even though lazy, it must backtrack if necessary to match |
| 277 | var regex = try Regex.compile(allocator, "a*?aab"); | |
| 277 | var regex = try Regex.compile(allocator, std.testing.io, "a*?aab"); | |
| 278 | 278 | defer regex.deinit(); |
| 279 | 279 | |
| 280 | 280 | if (try regex.find("aaab")) |match| { |
| @@ -289,7 +289,7 @@ test "lazy quantifier backtracking" { | ||
| 289 | 289 | |
| 290 | 290 | test "nested lazy quantifiers" { |
| 291 | 291 | const allocator = std.testing.allocator; |
| 292 | var regex = try Regex.compile(allocator, "(a*?b+?)*?c"); | |
| 292 | var regex = try Regex.compile(allocator, std.testing.io, "(a*?b+?)*?c"); | |
| 293 | 293 | defer regex.deinit(); |
| 294 | 294 | |
| 295 | 295 | try std.testing.expect(try regex.isMatch("c")); |
| @@ -299,7 +299,7 @@ test "nested lazy quantifiers" { | ||
| 299 | 299 | |
| 300 | 300 | test "lazy quantifier at end of pattern" { |
| 301 | 301 | const allocator = std.testing.allocator; |
| 302 | var regex = try Regex.compile(allocator, "a+?"); | |
| 302 | var regex = try Regex.compile(allocator, std.testing.io, "a+?"); | |
| 303 | 303 | defer regex.deinit(); |
| 304 | 304 | |
| 305 | 305 | if (try regex.find("aaa")) |match| { |
| @@ -318,10 +318,10 @@ test "lazy vs greedy performance comparison" { | ||
| 318 | 318 | const input = "a" ** 100 ++ "b"; |
| 319 | 319 | |
| 320 | 320 | // Both should match, but with different lengths |
| 321 | var greedy = try Regex.compile(allocator, "a*b"); | |
| 321 | var greedy = try Regex.compile(allocator, std.testing.io, "a*b"); | |
| 322 | 322 | defer greedy.deinit(); |
| 323 | 323 | |
| 324 | var lazy = try Regex.compile(allocator, "a*?b"); | |
| 324 | var lazy = try Regex.compile(allocator, std.testing.io, "a*?b"); | |
| 325 | 325 | defer lazy.deinit(); |
| 326 | 326 | |
| 327 | 327 | // Greedy matches all 100 'a's + 'b' |