Application Context Implementation #4

Closed
kayomn wants to merge 93 commits from event-loop-dev into main
3 changed files with 17 additions and 17 deletions
Showing only changes of commit c8992fec99 - Show all commits

View File

@ -135,7 +135,7 @@ pub fn Spliterator(comptime Element: type) type {
}; };
} }
test { test "Spliteration" {
const testing = std.testing; const testing = std.testing;
// Single-character delimiter. // Single-character delimiter.
@ -286,20 +286,6 @@ pub const Writer = struct {
} }
}; };
///
/// Searches the slice of `Data` referenced by `data` for the first instance of `sought_datum`,
/// returning its index or `null` if it could not be found.
///
pub fn findFirst(comptime Data: type, data: []const Data, sought_datum: Data) ?usize {
for (data) |datum, index| if (datum == sought_datum) return index;
return null;
}
test {
try std.testing.expectEqual(findFirst(u8, "1234567890", '7'), 6);
}
/// ///
/// Writer that silently throws consumed data away and never fails. /// Writer that silently throws consumed data away and never fails.
/// ///
@ -316,7 +302,7 @@ pub const null_writer = Writer{
}.write, }.write,
}; };
test { test "Null writing" {
const testing = std.testing; const testing = std.testing;
{ {

View File

@ -91,7 +91,7 @@ pub fn Fixed(comptime Element: type) type {
/// ///
pub const PushError = std.mem.Allocator.Error; pub const PushError = std.mem.Allocator.Error;
test { test "Fixed stack manipulation" {
const testing = std.testing; const testing = std.testing;
var buffer = std.mem.zeroes([4]u8); var buffer = std.mem.zeroes([4]u8);
var stack = Fixed(u8){.buffer = &buffer}; var stack = Fixed(u8){.buffer = &buffer};

View File

@ -198,3 +198,17 @@ pub const string_context = KeyContext([]const u8){
.hash = hashString, .hash = hashString,
.equals = equalsString, .equals = equalsString,
}; };
test "Hashed table manipulation with string context" {
const testing = std.testing;
var table = try Hashed([]const u8, u32, string_context).init(testing.allocator);
defer table.deinit();
const foo = @as(u32, 69);
testing.expectEqual(table.remove("foo"), null);
try table.insert("foo", foo);
testing.expectEqual(table.remove("foo"), foo);
testing.expectEqual(table.remove("foo"), null);
}