| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | |
| 5 | pub fn matchesAll(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 | const S = struct { |
| 15 | fn needle(item: u8) bool { |
| 16 | return item == 4; |
| 17 | } |
| 18 | }; |
| 19 | test { |
| 20 | try std.testing.expect(matchesAll(u8, &.{ 4, 4, 4, 4, 4, 4 }, S.needle)); |
| 21 | } |
| 22 | test { |
| 23 | try std.testing.expect(!matchesAll(u8, &.{ 4, 4, 4, 3, 4, 4 }, S.needle)); |
| 24 | } |
| 25 | test { |
| 26 | try std.testing.expect(!matchesAll(u8, &.{ 0, 1, 2, 3, 4, 5 }, S.needle)); |
| 27 | } |
| 28 | test { |
| 29 | try std.testing.expect(!matchesAll(u8, &.{ 5, 6, 7, 8, 9, 0 }, S.needle)); |
| 30 | } |