clean up std.ArrayList
* add `std.debug.assertError` * `std.ArrayList` update everything to follow `self` convention * rename `std.ArrayList.set` to `std.ArrayList.setOrError` * add `std.ArrayList.set` which asserts Before 1.0.0 we might remove some of this API, because you can use `toSlice()` for everything, but it's ok to add these functions as an experiment before then.
This commit is contained in:
@@ -88,6 +88,16 @@ pub fn assert(ok: bool) void {
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO: add `==` operator for `error_union == error_set`, and then
|
||||
/// remove this function
|
||||
pub fn assertError(value: var, expected_error: error) void {
|
||||
if (value) {
|
||||
@panic("expected error");
|
||||
} else |actual_error| {
|
||||
assert(actual_error == expected_error);
|
||||
}
|
||||
}
|
||||
|
||||
/// Call this function when you want to panic if the condition is not true.
|
||||
/// If `ok` is `false`, this function will panic in every release mode.
|
||||
pub fn assertOrPanic(ok: bool) void {
|
||||
|
||||
Reference in New Issue
Block a user