| @@ -727,20 +725,20 @@ fn collectNamedCaptures(node: *ast.Node, map: *std.StringHashMap(usize)) !void { |
| 727 | 725 | |
| 728 | 726 | test "compile empty pattern" { |
| 729 | 727 | const allocator = std.testing.allocator; |
| 730 | | - const result = Regex.compile(allocator, ""); |
| 728 | + const result = Regex.compile(allocator, std.testing.io, ""); |
| 731 | 729 | try std.testing.expectError(RegexError.EmptyPattern, result); |
| 732 | 730 | } |
| 733 | 731 | |
| 734 | 732 | test "compile basic pattern" { |
| 735 | 733 | const allocator = std.testing.allocator; |
| 736 | | - var regex = try Regex.compile(allocator, "test"); |
| 734 | + var regex = try Regex.compile(allocator, std.testing.io, "test"); |
| 737 | 735 | defer regex.deinit(); |
| 738 | 736 | try std.testing.expectEqualStrings("test", regex.pattern); |
| 739 | 737 | } |
| 740 | 738 | |
| 741 | 739 | test "match literal" { |
| 742 | 740 | const allocator = std.testing.allocator; |
| 743 | | - var regex = try Regex.compile(allocator, "hello"); |
| 741 | + var regex = try Regex.compile(allocator, std.testing.io, "hello"); |
| 744 | 742 | defer regex.deinit(); |
| 745 | 743 | |
| 746 | 744 | try std.testing.expect(try regex.isMatch("hello")); |
| @@ -749,7 +747,7 @@ test "match literal" { |
| 749 | 747 | |
| 750 | 748 | test "find literal" { |
| 751 | 749 | const allocator = std.testing.allocator; |
| 752 | | - var regex = try Regex.compile(allocator, "world"); |
| 750 | + var regex = try Regex.compile(allocator, std.testing.io, "world"); |
| 753 | 751 | defer regex.deinit(); |
| 754 | 752 | |
| 755 | 753 | if (try regex.find("hello world")) |match_result| { |
| @@ -765,7 +763,7 @@ test "find literal" { |
| 765 | 763 | |
| 766 | 764 | test "alternation" { |
| 767 | 765 | const allocator = std.testing.allocator; |
| 768 | | - var regex = try Regex.compile(allocator, "cat|dog"); |
| 766 | + var regex = try Regex.compile(allocator, std.testing.io, "cat|dog"); |
| 769 | 767 | defer regex.deinit(); |
| 770 | 768 | |
| 771 | 769 | try std.testing.expect(try regex.isMatch("cat")); |
| @@ -775,7 +773,7 @@ test "alternation" { |
| 775 | 773 | |
| 776 | 774 | test "star quantifier" { |
| 777 | 775 | const allocator = std.testing.allocator; |
| 778 | | - var regex = try Regex.compile(allocator, "a*"); |
| 776 | + var regex = try Regex.compile(allocator, std.testing.io, "a*"); |
| 779 | 777 | defer regex.deinit(); |
| 780 | 778 | |
| 781 | 779 | try std.testing.expect(try regex.isMatch("")); |
| @@ -785,7 +783,7 @@ test "star quantifier" { |
| 785 | 783 | |
| 786 | 784 | test "plus quantifier" { |
| 787 | 785 | const allocator = std.testing.allocator; |
| 788 | | - var regex = try Regex.compile(allocator, "a+"); |
| 786 | + var regex = try Regex.compile(allocator, std.testing.io, "a+"); |
| 789 | 787 | defer regex.deinit(); |
| 790 | 788 | |
| 791 | 789 | try std.testing.expect(!try regex.isMatch("")); |
| @@ -795,7 +793,7 @@ test "plus quantifier" { |
| 795 | 793 | |
| 796 | 794 | test "optional quantifier" { |
| 797 | 795 | const allocator = std.testing.allocator; |
| 798 | | - var regex = try Regex.compile(allocator, "a?"); |
| 796 | + var regex = try Regex.compile(allocator, std.testing.io, "a?"); |
| 799 | 797 | defer regex.deinit(); |
| 800 | 798 | |
| 801 | 799 | try std.testing.expect(try regex.isMatch("")); |
| @@ -804,7 +802,7 @@ test "optional quantifier" { |
| 804 | 802 | |
| 805 | 803 | test "dot wildcard" { |
| 806 | 804 | const allocator = std.testing.allocator; |
| 807 | | - var regex = try Regex.compile(allocator, "a.c"); |
| 805 | + var regex = try Regex.compile(allocator, std.testing.io, "a.c"); |
| 808 | 806 | defer regex.deinit(); |
| 809 | 807 | |
| 810 | 808 | try std.testing.expect(try regex.isMatch("abc")); |
| @@ -814,7 +812,7 @@ test "dot wildcard" { |
| 814 | 812 | |
| 815 | 813 | test "character class \\d" { |
| 816 | 814 | const allocator = std.testing.allocator; |
| 817 | | - var regex = try Regex.compile(allocator, "\\d+"); |
| 815 | + var regex = try Regex.compile(allocator, std.testing.io, "\\d+"); |
| 818 | 816 | defer regex.deinit(); |
| 819 | 817 | |
| 820 | 818 | if (try regex.find("abc123def")) |match_result| { |
| @@ -828,7 +826,7 @@ test "character class \\d" { |
| 828 | 826 | |
| 829 | 827 | test "replace" { |
| 830 | 828 | const allocator = std.testing.allocator; |
| 831 | | - var regex = try Regex.compile(allocator, "world"); |
| 829 | + var regex = try Regex.compile(allocator, std.testing.io, "world"); |
| 832 | 830 | defer regex.deinit(); |
| 833 | 831 | |
| 834 | 832 | const result = try regex.replace(allocator, "hello world", "Zig"); |
| @@ -839,7 +837,7 @@ test "replace" { |
| 839 | 837 | |
| 840 | 838 | test "replace all" { |
| 841 | 839 | const allocator = std.testing.allocator; |
| 842 | | - var regex = try Regex.compile(allocator, "a"); |
| 840 | + var regex = try Regex.compile(allocator, std.testing.io, "a"); |
| 843 | 841 | defer regex.deinit(); |
| 844 | 842 | |
| 845 | 843 | const result = try regex.replaceAll(allocator, "banana", "o"); |
| @@ -850,7 +848,7 @@ test "replace all" { |
| 850 | 848 | |
| 851 | 849 | test "split" { |
| 852 | 850 | const allocator = std.testing.allocator; |
| 853 | | - var regex = try Regex.compile(allocator, ","); |
| 851 | + var regex = try Regex.compile(allocator, std.testing.io, ","); |
| 854 | 852 | defer regex.deinit(); |
| 855 | 853 | |
| 856 | 854 | const parts = try regex.split(allocator, "a,b,c"); |
| @@ -866,7 +864,7 @@ test "compile rejects dangerous nested quantifiers" { |
| 866 | 864 | const allocator = std.testing.allocator; |
| 867 | 865 | |
| 868 | 866 | // This pattern should be rejected as critical risk |
| 869 | | - const result = Regex.compile(allocator, "(a+)+"); |
| 867 | + const result = Regex.compile(allocator, std.testing.io, "(a+)+"); |
| 870 | 868 | try std.testing.expectError(RegexError.PatternTooComplex, result); |
| 871 | 869 | } |
| 872 | 870 | |
| @@ -874,7 +872,7 @@ test "compile rejects nested stars" { |
| 874 | 872 | const allocator = std.testing.allocator; |
| 875 | 873 | |
| 876 | 874 | // This pattern should be rejected |
| 877 | | - const result = Regex.compile(allocator, "(a*)*"); |
| 875 | + const result = Regex.compile(allocator, std.testing.io, "(a*)*"); |
| 878 | 876 | try std.testing.expectError(RegexError.PatternTooComplex, result); |
| 879 | 877 | } |
| 880 | 878 | |
| @@ -882,6 +880,6 @@ test "compile accepts safe complex patterns" { |
| 882 | 880 | const allocator = std.testing.allocator; |
| 883 | 881 | |
| 884 | 882 | // This pattern should be accepted (medium risk is OK) |
| 885 | | - var regex = try Regex.compile(allocator, "a+b*c?d{2,5}"); |
| 883 | + var regex = try Regex.compile(allocator, std.testing.io, "a+b*c?d{2,5}"); |
| 886 | 884 | defer regex.deinit(); |
| 887 | 885 | } |