also looking at this
Port to latest zig-master
#2
53 files
+1149
-1017
| @@ -10,7 +10,7 @@ const RegexError = @import("regex").RegexError; | ||
| 10 | 10 | |
| 11 | 11 | test "regression: $0 replacement expands to full match" { |
| 12 | 12 | const allocator = std.testing.allocator; |
| 13 | var regex = try Regex.compile(allocator, "\\d+"); | |
| 13 | var regex = try Regex.compile(allocator, std.testing.io, "\\d+"); | |
| 14 | 14 | defer regex.deinit(); |
| 15 | 15 | |
| 16 | 16 | const result = try regex.replace(allocator, "abc 123 def", "[$0]"); |
| @@ -20,7 +20,7 @@ test "regression: $0 replacement expands to full match" { | ||
| 20 | 20 | |
| 21 | 21 | test "regression: $0 replacement with captures" { |
| 22 | 22 | const allocator = std.testing.allocator; |
| 23 | var regex = try Regex.compile(allocator, "(\\w+)@(\\w+)"); | |
| 23 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)@(\\w+)"); | |
| 24 | 24 | defer regex.deinit(); |
| 25 | 25 | |
| 26 | 26 | const result = try regex.replace(allocator, "email: user@host ok", "match=$0,user=$1,host=$2"); |
| @@ -30,7 +30,7 @@ test "regression: $0 replacement with captures" { | ||
| 30 | 30 | |
| 31 | 31 | test "regression: $0 in replaceAll" { |
| 32 | 32 | const allocator = std.testing.allocator; |
| 33 | var regex = try Regex.compile(allocator, "\\w+"); | |
| 33 | var regex = try Regex.compile(allocator, std.testing.io, "\\w+"); | |
| 34 | 34 | defer regex.deinit(); |
| 35 | 35 | |
| 36 | 36 | const result = try regex.replaceAll(allocator, "a b c", "[$0]"); |
| @@ -42,7 +42,7 @@ test "regression: $0 in replaceAll" { | ||
| 42 | 42 | |
| 43 | 43 | test "regression: case-insensitive backreference" { |
| 44 | 44 | const allocator = std.testing.allocator; |
| 45 | var regex = try Regex.compileWithFlags(allocator, "(\\w+) \\1", .{ .case_insensitive = true }); | |
| 45 | var regex = try Regex.compileWithFlags(allocator, std.testing.io, "(\\w+) \\1", .{ .case_insensitive = true }); | |
| 46 | 46 | defer regex.deinit(); |
| 47 | 47 | |
| 48 | 48 | try std.testing.expect(try regex.isMatch("hello HELLO")); |
| @@ -52,7 +52,7 @@ test "regression: case-insensitive backreference" { | ||
| 52 | 52 | |
| 53 | 53 | test "regression: case-sensitive backreference rejects case mismatch" { |
| 54 | 54 | const allocator = std.testing.allocator; |
| 55 | var regex = try Regex.compile(allocator, "(\\w+) \\1"); | |
| 55 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) \\1"); | |
| 56 | 56 | defer regex.deinit(); |
| 57 | 57 | |
| 58 | 58 | try std.testing.expect(!try regex.isMatch("hello HELLO")); |
| @@ -63,19 +63,19 @@ test "regression: case-sensitive backreference rejects case mismatch" { | ||
| 63 | 63 | |
| 64 | 64 | test "regression: {10,5} is rejected as invalid" { |
| 65 | 65 | const allocator = std.testing.allocator; |
| 66 | const result = Regex.compile(allocator, "a{10,5}"); | |
| 66 | const result = Regex.compile(allocator, std.testing.io, "a{10,5}"); | |
| 67 | 67 | try std.testing.expectError(RegexError.InvalidQuantifier, result); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | test "regression: {5,3} is rejected" { |
| 71 | 71 | const allocator = std.testing.allocator; |
| 72 | const result = Regex.compile(allocator, "x{5,3}"); | |
| 72 | const result = Regex.compile(allocator, std.testing.io, "x{5,3}"); | |
| 73 | 73 | try std.testing.expectError(RegexError.InvalidQuantifier, result); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | test "regression: {3,3} is accepted (min == max)" { |
| 77 | 77 | const allocator = std.testing.allocator; |
| 78 | var regex = try Regex.compile(allocator, "a{3,3}"); | |
| 78 | var regex = try Regex.compile(allocator, std.testing.io, "a{3,3}"); | |
| 79 | 79 | defer regex.deinit(); |
| 80 | 80 | |
| 81 | 81 | try std.testing.expect(try regex.isMatch("aaa")); |
| @@ -86,7 +86,7 @@ test "regression: {3,3} is accepted (min == max)" { | ||
| 86 | 86 | |
| 87 | 87 | test "regression: {0,3} matches 0 to 3 occurrences" { |
| 88 | 88 | const allocator = std.testing.allocator; |
| 89 | var regex = try Regex.compile(allocator, "^a{0,3}$"); | |
| 89 | var regex = try Regex.compile(allocator, std.testing.io, "^a{0,3}$"); | |
| 90 | 90 | defer regex.deinit(); |
| 91 | 91 | |
| 92 | 92 | try std.testing.expect(try regex.isMatch("")); |
| @@ -98,9 +98,9 @@ test "regression: {0,3} matches 0 to 3 occurrences" { | ||
| 98 | 98 | |
| 99 | 99 | test "regression: {0,1} is equivalent to ?" { |
| 100 | 100 | const allocator = std.testing.allocator; |
| 101 | var regex1 = try Regex.compile(allocator, "^ab{0,1}c$"); | |
| 101 | var regex1 = try Regex.compile(allocator, std.testing.io, "^ab{0,1}c$"); | |
| 102 | 102 | defer regex1.deinit(); |
| 103 | var regex2 = try Regex.compile(allocator, "^ab?c$"); | |
| 103 | var regex2 = try Regex.compile(allocator, std.testing.io, "^ab?c$"); | |
| 104 | 104 | defer regex2.deinit(); |
| 105 | 105 | |
| 106 | 106 | const inputs = [_][]const u8{ "ac", "abc", "abbc", "" }; |
| @@ -111,7 +111,7 @@ test "regression: {0,1} is equivalent to ?" { | ||
| 111 | 111 | |
| 112 | 112 | test "regression: {0,0} matches empty only" { |
| 113 | 113 | const allocator = std.testing.allocator; |
| 114 | var regex = try Regex.compile(allocator, "^a{0,0}b$"); | |
| 114 | var regex = try Regex.compile(allocator, std.testing.io, "^a{0,0}b$"); | |
| 115 | 115 | defer regex.deinit(); |
| 116 | 116 | |
| 117 | 117 | try std.testing.expect(try regex.isMatch("b")); |
| @@ -123,7 +123,7 @@ test "regression: {0,0} matches empty only" { | ||
| 123 | 123 | test "regression: prefix optimization finds match after false prefix start" { |
| 124 | 124 | const allocator = std.testing.allocator; |
| 125 | 125 | // Pattern with prefix "ab" - but first "ab" at position 0 doesn't complete the full match |
| 126 | var regex = try Regex.compile(allocator, "abc\\d+"); | |
| 126 | var regex = try Regex.compile(allocator, std.testing.io, "abc\\d+"); | |
| 127 | 127 | defer regex.deinit(); |
| 128 | 128 | |
| 129 | 129 | // "ab" appears at position 0, but "abc" + digits is only at position 5 |
| @@ -141,7 +141,7 @@ test "regression: prefix optimization finds match after false prefix start" { | ||
| 141 | 141 | test "regression: backtrack step counter resets between positions" { |
| 142 | 142 | const allocator = std.testing.allocator; |
| 143 | 143 | // This pattern uses backtracking via backreference. |
| 144 | var regex = try Regex.compile(allocator, "(\\w+) \\1"); | |
| 144 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) \\1"); | |
| 145 | 145 | defer regex.deinit(); |
| 146 | 146 | |
| 147 | 147 | // Verify basic backreference works |
| @@ -161,7 +161,7 @@ test "regression: backtrack step counter resets between positions" { | ||
| 161 | 161 | |
| 162 | 162 | test "regression: deinit on regex that was never used" { |
| 163 | 163 | const allocator = std.testing.allocator; |
| 164 | var regex = try Regex.compile(allocator, "test"); | |
| 164 | var regex = try Regex.compile(allocator, std.testing.io, "test"); | |
| 165 | 165 | regex.deinit(); |
| 166 | 166 | // Should not crash - just testing that deinit works without any find/match calls |
| 167 | 167 | } |
| @@ -169,12 +169,12 @@ test "regression: deinit on regex that was never used" { | ||
| 169 | 169 | test "regression: double pattern compile and deinit" { |
| 170 | 170 | const allocator = std.testing.allocator; |
| 171 | 171 | { |
| 172 | var regex = try Regex.compile(allocator, "abc"); | |
| 172 | var regex = try Regex.compile(allocator, std.testing.io, "abc"); | |
| 173 | 173 | defer regex.deinit(); |
| 174 | 174 | try std.testing.expect(try regex.isMatch("abc")); |
| 175 | 175 | } |
| 176 | 176 | { |
| 177 | var regex = try Regex.compile(allocator, "def"); | |
| 177 | var regex = try Regex.compile(allocator, std.testing.io, "def"); | |
| 178 | 178 | defer regex.deinit(); |
| 179 | 179 | try std.testing.expect(try regex.isMatch("def")); |
| 180 | 180 | } |