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 | test "integration: email validation - basic pattern" { |
| 6 | 6 | const allocator = std.testing.allocator; |
| 7 | 7 | // Simplified email pattern: word@word.word |
| 8 | var regex = try Regex.compile(allocator, "\\w+@\\w+\\.\\w+"); | |
| 8 | var regex = try Regex.compile(allocator, std.testing.io, "\\w+@\\w+\\.\\w+"); | |
| 9 | 9 | defer regex.deinit(); |
| 10 | 10 | |
| 11 | 11 | try std.testing.expect(try regex.isMatch("user@example.com")); |
| @@ -16,7 +16,7 @@ test "integration: email validation - basic pattern" { | ||
| 16 | 16 | |
| 17 | 17 | test "integration: email validation - extract from text" { |
| 18 | 18 | const allocator = std.testing.allocator; |
| 19 | var regex = try Regex.compile(allocator, "\\w+@\\w+\\.\\w+"); | |
| 19 | var regex = try Regex.compile(allocator, std.testing.io, "\\w+@\\w+\\.\\w+"); | |
| 20 | 20 | defer regex.deinit(); |
| 21 | 21 | |
| 22 | 22 | const text = "Contact support@example.com for help"; |
| @@ -33,7 +33,7 @@ test "integration: email validation - extract from text" { | ||
| 33 | 33 | test "integration: URL extraction from text" { |
| 34 | 34 | const allocator = std.testing.allocator; |
| 35 | 35 | // Simplified: just match http:// or https:// followed by word.word |
| 36 | var regex = try Regex.compile(allocator, "https://\\w+\\.\\w+"); | |
| 36 | var regex = try Regex.compile(allocator, std.testing.io, "https://\\w+\\.\\w+"); | |
| 37 | 37 | defer regex.deinit(); |
| 38 | 38 | |
| 39 | 39 | const text = "Visit https://example.com for more info."; |
| @@ -49,7 +49,7 @@ test "integration: URL extraction from text" { | ||
| 49 | 49 | // Phone Number Tests |
| 50 | 50 | test "integration: US phone number validation" { |
| 51 | 51 | const allocator = std.testing.allocator; |
| 52 | var regex = try Regex.compile(allocator, "^\\d{3}-\\d{3}-\\d{4}$"); | |
| 52 | var regex = try Regex.compile(allocator, std.testing.io, "^\\d{3}-\\d{3}-\\d{4}$"); | |
| 53 | 53 | defer regex.deinit(); |
| 54 | 54 | |
| 55 | 55 | try std.testing.expect(try regex.isMatch("555-123-4567")); |
| @@ -60,7 +60,7 @@ test "integration: US phone number validation" { | ||
| 60 | 60 | |
| 61 | 61 | test "integration: extract phone numbers from text" { |
| 62 | 62 | const allocator = std.testing.allocator; |
| 63 | var regex = try Regex.compile(allocator, "\\d{3}-\\d{3}-\\d{4}"); | |
| 63 | var regex = try Regex.compile(allocator, std.testing.io, "\\d{3}-\\d{3}-\\d{4}"); | |
| 64 | 64 | defer regex.deinit(); |
| 65 | 65 | |
| 66 | 66 | const text = "Call 555-123-4567 or 800-555-9876 for support."; |
| @@ -81,7 +81,7 @@ test "integration: extract phone numbers from text" { | ||
| 81 | 81 | // Date/Time Patterns |
| 82 | 82 | test "integration: ISO date format" { |
| 83 | 83 | const allocator = std.testing.allocator; |
| 84 | var regex = try Regex.compile(allocator, "^\\d{4}-\\d{2}-\\d{2}$"); | |
| 84 | var regex = try Regex.compile(allocator, std.testing.io, "^\\d{4}-\\d{2}-\\d{2}$"); | |
| 85 | 85 | defer regex.deinit(); |
| 86 | 86 | |
| 87 | 87 | try std.testing.expect(try regex.isMatch("2025-01-26")); |
| @@ -92,7 +92,7 @@ test "integration: ISO date format" { | ||
| 92 | 92 | |
| 93 | 93 | test "integration: time format HH:MM:SS" { |
| 94 | 94 | const allocator = std.testing.allocator; |
| 95 | var regex = try Regex.compile(allocator, "^\\d{2}:\\d{2}:\\d{2}$"); | |
| 95 | var regex = try Regex.compile(allocator, std.testing.io, "^\\d{2}:\\d{2}:\\d{2}$"); | |
| 96 | 96 | defer regex.deinit(); |
| 97 | 97 | |
| 98 | 98 | try std.testing.expect(try regex.isMatch("14:30:45")); |
| @@ -106,7 +106,7 @@ test "integration: time format HH:MM:SS" { | ||
| 106 | 106 | test "integration: extract log levels" { |
| 107 | 107 | const allocator = std.testing.allocator; |
| 108 | 108 | // Match INFO specifically (alternation with 4 options seems to cause overflow) |
| 109 | var regex = try Regex.compile(allocator, "INFO"); | |
| 109 | var regex = try Regex.compile(allocator, std.testing.io, "INFO"); | |
| 110 | 110 | defer regex.deinit(); |
| 111 | 111 | |
| 112 | 112 | try std.testing.expect(try regex.isMatch("[INFO] Application started")); |
| @@ -115,7 +115,7 @@ test "integration: extract log levels" { | ||
| 115 | 115 | |
| 116 | 116 | test "integration: parse log timestamp and message" { |
| 117 | 117 | const allocator = std.testing.allocator; |
| 118 | var regex = try Regex.compile(allocator, "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}"); | |
| 118 | var regex = try Regex.compile(allocator, std.testing.io, "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}"); | |
| 119 | 119 | defer regex.deinit(); |
| 120 | 120 | |
| 121 | 121 | const log = "[2025-01-26 14:30:45] User login successful"; |
| @@ -132,7 +132,7 @@ test "integration: parse log timestamp and message" { | ||
| 132 | 132 | test "integration: IPv4 address matching" { |
| 133 | 133 | const allocator = std.testing.allocator; |
| 134 | 134 | // Simplified pattern (doesn't validate ranges) |
| 135 | var regex = try Regex.compile(allocator, "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"); | |
| 135 | var regex = try Regex.compile(allocator, std.testing.io, "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"); | |
| 136 | 136 | defer regex.deinit(); |
| 137 | 137 | |
| 138 | 138 | try std.testing.expect(try regex.isMatch("192.168.1.1")); |
| @@ -145,7 +145,7 @@ test "integration: IPv4 address matching" { | ||
| 145 | 145 | test "integration: password strength - minimum length" { |
| 146 | 146 | const allocator = std.testing.allocator; |
| 147 | 147 | // Check if string has at least 8 characters (simplified - just check length differently) |
| 148 | var regex = try Regex.compile(allocator, ".{8}"); | |
| 148 | var regex = try Regex.compile(allocator, std.testing.io, ".{8}"); | |
| 149 | 149 | defer regex.deinit(); |
| 150 | 150 | |
| 151 | 151 | try std.testing.expect(try regex.isMatch("password123")); // has 8+ chars |
| @@ -155,7 +155,7 @@ test "integration: password strength - minimum length" { | ||
| 155 | 155 | |
| 156 | 156 | test "integration: password contains digit" { |
| 157 | 157 | const allocator = std.testing.allocator; |
| 158 | var regex = try Regex.compile(allocator, "\\d"); | |
| 158 | var regex = try Regex.compile(allocator, std.testing.io, "\\d"); | |
| 159 | 159 | defer regex.deinit(); |
| 160 | 160 | |
| 161 | 161 | try std.testing.expect(try regex.isMatch("password1")); |
| @@ -167,7 +167,7 @@ test "integration: password contains digit" { | ||
| 167 | 167 | test "integration: username alphanumeric with underscores" { |
| 168 | 168 | const allocator = std.testing.allocator; |
| 169 | 169 | // Simplified - removed anchors and large quantifier bound to avoid crash |
| 170 | var regex = try Regex.compile(allocator, "[a-zA-Z0-9_]{3}"); | |
| 170 | var regex = try Regex.compile(allocator, std.testing.io, "[a-zA-Z0-9_]{3}"); | |
| 171 | 171 | defer regex.deinit(); |
| 172 | 172 | |
| 173 | 173 | try std.testing.expect(try regex.isMatch("user123")); |
| @@ -179,7 +179,7 @@ test "integration: username alphanumeric with underscores" { | ||
| 179 | 179 | // Hashtag Extraction |
| 180 | 180 | test "integration: extract hashtags from text" { |
| 181 | 181 | const allocator = std.testing.allocator; |
| 182 | var regex = try Regex.compile(allocator, "#\\w+"); | |
| 182 | var regex = try Regex.compile(allocator, std.testing.io, "#\\w+"); | |
| 183 | 183 | defer regex.deinit(); |
| 184 | 184 | |
| 185 | 185 | const tweet = "Loving #Zig programming! #opensource #systems"; |
| @@ -202,7 +202,7 @@ test "integration: extract hashtags from text" { | ||
| 202 | 202 | test "integration: match HTML tags" { |
| 203 | 203 | const allocator = std.testing.allocator; |
| 204 | 204 | // Match opening tags only (no closing tags with /) |
| 205 | var regex = try Regex.compile(allocator, "<[a-z]+>"); | |
| 205 | var regex = try Regex.compile(allocator, std.testing.io, "<[a-z]+>"); | |
| 206 | 206 | defer regex.deinit(); |
| 207 | 207 | |
| 208 | 208 | const html = "<div>content<span>text"; |
| @@ -223,7 +223,7 @@ test "integration: match HTML tags" { | ||
| 223 | 223 | // CSV Parsing |
| 224 | 224 | test "integration: split CSV line" { |
| 225 | 225 | const allocator = std.testing.allocator; |
| 226 | var regex = try Regex.compile(allocator, ","); | |
| 226 | var regex = try Regex.compile(allocator, std.testing.io, ","); | |
| 227 | 227 | defer regex.deinit(); |
| 228 | 228 | |
| 229 | 229 | const csv = "John,Doe,30,Engineer"; |
| @@ -240,7 +240,7 @@ test "integration: split CSV line" { | ||
| 240 | 240 | // Whitespace Normalization |
| 241 | 241 | test "integration: replace multiple spaces with single space" { |
| 242 | 242 | const allocator = std.testing.allocator; |
| 243 | var regex = try Regex.compile(allocator, "\\s+"); | |
| 243 | var regex = try Regex.compile(allocator, std.testing.io, "\\s+"); | |
| 244 | 244 | defer regex.deinit(); |
| 245 | 245 | |
| 246 | 246 | const text = "This has too many spaces"; |
| @@ -254,7 +254,7 @@ test "integration: replace multiple spaces with single space" { | ||
| 254 | 254 | test "integration: extract markdown links" { |
| 255 | 255 | const allocator = std.testing.allocator; |
| 256 | 256 | // Simplified pattern - just find one link |
| 257 | var regex = try Regex.compile(allocator, "\\[\\w+\\]\\(https://\\w+\\.\\w+\\)"); | |
| 257 | var regex = try Regex.compile(allocator, std.testing.io, "\\[\\w+\\]\\(https://\\w+\\.\\w+\\)"); | |
| 258 | 258 | defer regex.deinit(); |
| 259 | 259 | |
| 260 | 260 | const markdown = "Check [Zig](https://ziglang.org) for more info"; |
| @@ -270,7 +270,7 @@ test "integration: extract markdown links" { | ||
| 270 | 270 | // Version Number Extraction |
| 271 | 271 | test "integration: semver version numbers" { |
| 272 | 272 | const allocator = std.testing.allocator; |
| 273 | var regex = try Regex.compile(allocator, "\\d+\\.\\d+\\.\\d+"); | |
| 273 | var regex = try Regex.compile(allocator, std.testing.io, "\\d+\\.\\d+\\.\\d+"); | |
| 274 | 274 | defer regex.deinit(); |
| 275 | 275 | |
| 276 | 276 | const text = "Version 1.2.3 released. Upgrade from 1.0.0 required."; |
| @@ -291,7 +291,7 @@ test "integration: semver version numbers" { | ||
| 291 | 291 | // Hex Color Codes |
| 292 | 292 | test "integration: match hex color codes" { |
| 293 | 293 | const allocator = std.testing.allocator; |
| 294 | var regex = try Regex.compile(allocator, "#[0-9a-fA-F]{6}"); | |
| 294 | var regex = try Regex.compile(allocator, std.testing.io, "#[0-9a-fA-F]{6}"); | |
| 295 | 295 | defer regex.deinit(); |
| 296 | 296 | |
| 297 | 297 | const css = "color: #FF5733; background: #FFFFFF;"; |
| @@ -312,7 +312,7 @@ test "integration: match hex color codes" { | ||
| 312 | 312 | // Code Comment Extraction |
| 313 | 313 | test "integration: extract single-line comments" { |
| 314 | 314 | const allocator = std.testing.allocator; |
| 315 | var regex = try Regex.compile(allocator, "//.*"); | |
| 315 | var regex = try Regex.compile(allocator, std.testing.io, "//.*"); | |
| 316 | 316 | defer regex.deinit(); |
| 317 | 317 | |
| 318 | 318 | const code = "const x = 5; // This is a comment"; |
| @@ -328,7 +328,7 @@ test "integration: extract single-line comments" { | ||
| 328 | 328 | // Environment Variable Format |
| 329 | 329 | test "integration: match environment variables" { |
| 330 | 330 | const allocator = std.testing.allocator; |
| 331 | var regex = try Regex.compile(allocator, "\\$[A-Z_]+"); | |
| 331 | var regex = try Regex.compile(allocator, std.testing.io, "\\$[A-Z_]+"); | |
| 332 | 332 | defer regex.deinit(); |
| 333 | 333 | |
| 334 | 334 | const script = "export PATH=$HOME/bin:$PATH"; |