Application Context Implementation #4
| @ -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; | ||||||
| 
 | 
 | ||||||
|     { |     { | ||||||
|  | |||||||
| @ -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}; | ||||||
|  | |||||||
| @ -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); | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user