| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | |
| 5 | pub fn matchesNone(comptime T: type, haystack: []const T, comptime needle: fn (T) bool) bool { |
| 6 | for (haystack) |c| { |
| 7 | if (needle(c)) { |
| 8 | return false; |
| 9 | } |
| 10 | } |
| 11 | return true; |
| 12 | } |
| 13 | |
| 14 | test { |
| 15 | const S = struct { |
| 16 | fn needle(item: u8) bool { |
| 17 | return item > 8; |
| 18 | } |
| 19 | }; |
| 20 | try std.testing.expect(matchesNone(u8, &.{ 0, 1, 2, 3, 4, 5 }, S.needle)); |
| 21 | } |
| 22 | |
| 23 | test { |
| 24 | const S = struct { |
| 25 | fn needle(item: u8) bool { |
| 26 | return item == 4; |
| 27 | } |
| 28 | }; |
| 29 | try std.testing.expect(!matchesNone(u8, &.{ 0, 1, 2, 3, 4, 5 }, S.needle)); |
| 30 | } |