about summary refs log tree commit diff
path: root/src/libcore/tests
AgeCommit message (Collapse)AuthorLines
2019-11-06Have tidy ensure that we document all `unsafe` blocks in libcoreOliver Scherer-0/+2
2019-10-24Add unit tests for `array::IntoIter`Lukas Kalbertodt-1/+207
Many tests are based on tests by Josh Stone <cuviper@gmail.com>
2019-10-10move debug_map assertions after check for errAshley Mannix-0/+40
2019-09-21Auto merge of #64047 - timvermeulen:cmp_min_max_by, r=cuviperbors-1/+24
Add `cmp::{min_by, min_by_key, max_by, max_by_key}` This adds the following functions to `core::cmp`: - `min_by` - `min_by_key` - `max_by` - `max_by_key` `min_by` and `max_by` are somewhat trivial to implement, but not entirely because `min_by` returns the first value in case the two are equal (and `max_by` the second). `min` and `max` can be implemented in terms of `min_by` and `max_by`, but not as easily the other way around. To give an example of why I think these functions could be useful: the `Iterator::{min_by, min_by_key, max_by, max_by_key}` methods all currently hard-code the behavior mentioned above which is an ever so small duplication of logic. If we delegate them to `cmp::{min_by, max_by}` methods instead, we get the correct behavior for free. (edit: this is now included in the PR) I added `min_by_key` / `max_by_key` for consistency's sake but I wouldn't mind removing them. I don't have a particular use case in mind for them, and `min_by` / `max_by` seem to be more useful. Tracking issue: #64460
2019-09-14Add cmp::{min_by, min_by_key, max_by, max_by_key}Tim Vermeulen-1/+24
2019-09-09Rollup merge of #64121 - timvermeulen:iter_step_by_internal, r=scottmcmMazdak Farrokhzad-0/+35
Override `StepBy::{try_fold, try_rfold}` Previous PR: https://github.com/rust-lang/rust/pull/51435 The previous PR was closed in favor of https://github.com/rust-lang/rust/pull/51601, which was later reverted. I don't think these implementations will make it harder to specialize `StepBy<Range<_>>` later, so we should be able to land this without any consequences. This should fix https://github.com/rust-lang/rust/issues/57517 – in my benchmarks `iter` and `iter.step_by(1)` now perform equally well, provided internal iteration is used.
2019-09-08Rollup merge of #62205 - timvermeulen:iter_order_by, r=KodrAusMazdak Farrokhzad-0/+57
Add Iterator comparison methods that take a comparison function This PR adds `Iterator::{cmp_by, partial_cmp_by, eq_by, ne_by, lt_by, le_by, gt_by, ge_by}`. We already have `Iterator::{cmp, partial_cmp, ...}` which are less general (but not any simpler) than the ones I'm proposing here. I'm submitting this PR now because #61505 has been merged, so this change should not have a noticeable effect on the `Iterator` docs page size. The diff is quite messy, here's what I changed: - The logic of `cmp` / `partial_cmp` / `eq` is moved to `cmp_by` / `partial_cmp_by` / `eq_by` respectively, changing `x.cmp(&y)` to `cmp(&x, &y)` in the `cmp` method where `cmp` is the given comparison function (and similar for `partial_cmp_by` and `eq_by`). - `ne_by` / `lt_by` / `le_by` / `gt_by` / `ge_by` are each implemented in terms of one of the three methods above. - The existing comparison methods are each forwarded to their `_by` counterpart, passing one of `Ord::cmp` / `PartialOrd::partial_cmp` / `PartialEq::eq` as the comparison function. The corresponding `_by_key` methods aren't included because they're not as fundamental as the `_by` methods and can easily be implemented in terms of them. Is that reasonable, or would adding the `_by_key` methods be desirable for the sake of completeness? I didn't add any tests – I couldn't think of any that weren't already covered by our existing tests. Let me know if there's a particular test that would be useful to add.
2019-09-07Add `bool::then` and `bool::then_with`varkor-0/+9
2019-09-06Add Iterator comparison methods that take a comparison functionTim Vermeulen-0/+57
2019-09-04Override `StepBy::{try_fold, try_rfold}`Tim Vermeulen-0/+35
2019-08-30Rev::rposition counts from the wrong endXiang Fan-0/+6
Because of a compiler bug that adding `Self: ExactSizeIterator` makes the compiler forget `Self::Item` is `<I as Iterator>::Item`, we remove this specialization for now.
2019-08-20Rollup merge of #63691 - timvermeulen:chain-size-hint, r=scottmcmMazdak Farrokhzad-0/+48
Fix bug in iter::Chain::size_hint `Chain::size_hint` currently ignores `self.state`, which means that the size hints of the underlying iterators are always combined regardless of the iteration state. This, of course, should only happen when the state is `ChainState::Both`.
2019-08-20Rollup merge of #63265 - JohnTitor:implement-nth-back-for-chunksexactmut, ↵Mazdak Farrokhzad-0/+19
r=scottmcm Implement `nth_back` for ChunksExactMut This is a part of #54054. r? @scottmcm
2019-08-18Fix bug in iter::Chain::size_hintTim Vermeulen-0/+48
2019-08-17Rollup merge of #62737 - timvermeulen:cycle_try_fold, r=scottmcmMazdak Farrokhzad-0/+12
Override Cycle::try_fold It's not very pretty, but I believe this is the simplest way to correctly implement `Cycle::try_fold`. The following may seem correct: ```rust loop { acc = self.iter.try_fold(acc, &mut f)?; self.iter = self.orig.clone(); } ``` ...but this loops infinitely in case `self.orig` is empty, as opposed to returning `acc`. So we first have to fully iterate `self.orig` to check whether it is empty or not, and before _that_, we have to iterate the remaining elements of `self.iter`. This should always call `self.orig.clone()` the same amount of times as repeated `next()` calls would. r? @scottmcm
2019-08-16Rollup merge of #60492 - acrrd:issues/54054_chain, r=SimonSapinMazdak Farrokhzad-0/+16
Add custom nth_back for Chain Implementation of nth_back for Chain. Part of #54054
2019-08-09Rollup merge of #63407 - RalfJung:miri-test-sizes, r=CentrilMazdak Farrokhzad-1/+1
reduce some test sizes in Miri
2019-08-09Rollup merge of #63404 - RalfJung:flt2dec, r=CentrilMazdak Farrokhzad-7/+42
enable flt2dec tests in Miri With ldexp implemented (thanks to @christianpoveda), we can finally enable these tests in Miri. Well, most of them -- some are just too slow.
2019-08-09Rollup merge of #63403 - sntdevco:master, r=CentrilMazdak Farrokhzad-9/+9
Improve test output I'm continuing to improve the test output for liballoc and libcore
2019-08-09explain Miri disablingRalf Jung-1/+1
2019-08-09Miri is really slowRalf Jung-4/+5
2019-08-09enable flt2dec tests in MiriRalf Jung-7/+41
2019-08-09Merge pull request #1 from rust-lang/masterSayan Nandan-216/+1141
Merge recent changes into master
2019-08-09Improve tests for libcore/sliceSayan Nandan-8/+8
2019-08-09Improve test output for libcore/timeSayan Nandan-3/+1
2019-08-09Auto merge of #61937 - AaronKutch:master, r=scottmcmbors-0/+38
Improve `ptr_rotate` performance, tests, and benches The corresponding issue is #61784. I am not actually sure if miri can handle the test, but I can change the commit if necessary.
2019-08-08Rollup merge of #63261 - RalfJung:rand, r=nikomatsakisMazdak Farrokhzad-9/+9
bump rand in libcore/liballoc test suites This pulls in the fix for https://github.com/rust-random/rand/issues/779, which trips Miri when running these test suites. `SmallRng` (formerly used by libcore) is no longer built by default, it needs a feature gate. I opted to switch to `StdRng` instead. Or should I enable the feature gate?
2019-08-06Improve `ptr_rotate` performance, tests, and benchmarksAaron Kutch-0/+38
2019-08-06Rollup merge of #62459 - timvermeulen:result_sum_internal_iteration, r=scottmcmMazdak Farrokhzad-0/+17
Use internal iteration in the Sum and Product impls of Result and Option This PR adds internal iteration to the `ResultShunt` iterator type underlying the `Sum` and `Product` impls of `Result`. I had to change `ResultShunt` to hold a mutable reference to an error instead, similar to `itertools::ProcessResults`, in order to be able to pass the `ResultShunt` itself by value (which is necessary for internal iteration). `ResultShunt::process` can unfortunately no longer be an associated function because that would make it generic over the lifetime of the error reference, which wouldn't work, so I turned it into the free function `process_results`. I removed the `OptionShunt` type and forwarded the `Sum` and `Product` impls of `Option` to their respective impls of `Result` instead, to avoid having to repeat the internal iteration logic.
2019-08-06Rollup merge of #63260 - RalfJung:ptr-test, r=matkladMazdak Farrokhzad-2/+1
fix UB in a test We used to compare two mutable references that were supposed to point to the same thing. That's no good. Compare them as raw pointers instead.
2019-08-06Rollup merge of #61457 - timvermeulen:double_ended_iters, r=scottmcmMazdak Farrokhzad-13/+179
Implement DoubleEndedIterator for iter::{StepBy, Peekable, Take} Now that `DoubleEndedIterator::nth_back` has landed, `StepBy` and `Take` can have an efficient `DoubleEndedIterator` implementation. I don't know if there was any particular reason for `Peekable` not having a `DoubleEndedIterator` implementation, but it's quite trivial and I don't see any drawbacks to having it. I'm not very happy about the implementation of `Peekable::try_rfold`, but I didn't see another way to only take the value out of `self.peeked` in case `self.iter.try_rfold` didn't exit early. I only added `Peekable::rfold` (in addition to `try_rfold`) because its `Iterator` implementation has both `fold` and `try_fold` (and for similar reasons I added `Take::try_rfold` but not `Take::rfold`). Do we have any guidelines on whether we want both? If we do want both, maybe we should investigate which iterator adaptors override `try_fold` but not `fold` and add the missing implementations. At the moment I think that it's better to always have iterator adaptors implement both, because some iterators have a simpler `fold` implementation than their `try_fold` implementation. The tests that I added may not be sufficient because they're all just existing tests where `next`/`nth`/`fold`/`try_fold` are replaced by their DEI counterparts, but I do think all paths are covered. Is there anything in particular that I should probably also test?
2019-08-05fix slice comparisonRalf Jung-1/+1
Co-Authored-By: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-08-05Test content, not valueRalf Jung-1/+1
Co-Authored-By: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-08-05Implement nth_back for ChunksExactMutYuki Okushi-0/+19
2019-08-04bump libcore tests to rand 0.7Ralf Jung-9/+9
2019-08-04fix UB in a testRalf Jung-2/+1
2019-07-29Use internal iteration in the Sum and Product impls of Result and OptionTim Vermeulen-0/+17
2019-07-28Remove lint annotations in specific crates that are already enforced by ↵Vadim Petrochenkov-1/+0
rustbuild Remove some random unnecessary lint `allow`s
2019-07-28Rollup merge of #62074 - wizAmit:feature/mut_chunks_nth_back, r=scottmcmMazdak Farrokhzad-0/+22
squash of all commits for nth_back on ChunksMut wip nth_back for chunks_mut working chunksmut fixed nth_back for chunksmut Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com> r? @timvermeulen r? @scottmcm
2019-07-26Rollup merge of #62421 - JohnTitor:U007D-master, r=alexcrichtonMazdak Farrokhzad-37/+178
Introduce `as_deref` to Option This is re-submission for #59628. Renames `deref()` to `as_deref()` and adds `deref_mut()` impls and tests. CC #50264 r? @Kimundi (I picked you as you're the previous reviewer.)
2019-07-25Rollup merge of #61884 - crlf0710:stablize_euc, r=dtolnay,CentrilMazdak Farrokhzad-1/+0
Stablize Euclidean Modulo (feature euclidean_division) Closes #49048
2019-07-18renamed `inner_deref` feature's `deref*()` methods `as_deref*()` as per ↵Brad Gibson-37/+178
discussion https://github.com/rust-lang/rust/issues/50264
2019-07-17Override Cycle::try_foldTim Vermeulen-0/+12
2019-07-09Implement DoubleEndedIterator for iter::{StepBy, Peekable, Take}Tim Vermeulen-13/+179
2019-07-09Unit test Iterator::partition_in_place and is_partitionedJosh Stone-0/+38
2019-07-09Rollup merge of #60458 - KodrAus:debug_map_entry, r=alexcrichtonMazdak Farrokhzad-8/+86
Add key and value methods to DebugMap Implementation PR for an active (not approved) RFC: https://github.com/rust-lang/rfcs/pull/2696. Add two new methods to `std::fmt::DebugMap` for writing the key and value part of a map entry separately: ```rust impl<'a, 'b: 'a> DebugMap<'a, 'b> { pub fn key(&mut self, key: &dyn Debug) -> &mut Self; pub fn value(&mut self, value: &dyn Debug) -> &mut Self; } ``` I want to do this so that I can write a `serde::Serializer` that forwards to our format builders, so that any `T: Serialize` can also be treated like a `T: Debug`.
2019-07-08add key and value methods to DebugMapAshley Mannix-8/+86
2019-07-07Stablize Euclidean Modulo (feature euclidean_division)CrLF0710-1/+0
2019-07-04Rollup merge of #62346 - RalfJung:miri-tests, r=CentrilMazdak Farrokhzad-7/+4
enable a few more tests in Miri and update the comment for others
2019-07-03enable a few more tests in Miri and update the comment for othersRalf Jung-7/+4