about summary refs log tree commit diff
path: root/library/alloc/tests
AgeCommit message (Collapse)AuthorLines
2021-03-27Auto merge of #78618 - workingjubilee:ieee754-fmt, r=m-ou-sebors-2/+1
Add IEEE 754 compliant fmt/parse of -0, infinity, NaN This pull request improves the Rust float formatting/parsing libraries to comply with IEEE 754's formatting expectations around certain special values, namely signed zero, the infinities, and NaN. It also adds IEEE 754 compliance tests that, while less stringent in certain places than many of the existing flt2dec/dec2flt capability tests, are intended to serve as the beginning of a roadmap to future compliance with the standard. Some relevant documentation is also adjusted with clarifying remarks. This PR follows from discussion in https://github.com/rust-lang/rfcs/issues/1074, and closes #24623. The most controversial change here is likely to be that -0 is now printed as -0. Allow me to explain: While there appears to be community support for an opt-in toggle of printing floats as if they exist in the naively expected domain of numbers, i.e. not the extended reals (where floats live), IEEE 754-2019 is clear that a float converted to a string should be capable of being transformed into the original floating point bit-pattern when it satisfies certain conditions (namely, when it is an actual numeric value i.e. not a NaN and the original and destination float width are the same). -0 is given special attention here as a value that should have its sign preserved. In addition, the vast majority of other programming languages not only output `-0` but output `-0.0` here. While IEEE 754 offers a broad leeway in how to handle producing what it calls a "decimal character sequence", it is clear that the operations a language provides should be capable of round tripping, and it is confusing to advertise the f32 and f64 types as binary32 and binary64 yet have the most basic way of producing a string and then reading it back into a floating point number be non-conformant with the standard. Further, existing documentation suggested that e.g. -0 would be printed with -0 regardless of the presence of the `+` fmt character, but it prints "+0" instead if given such (which was what led to the opening of #24623). There are other parsing and formatting issues for floating point numbers which prevent Rust from complying with the standard, as well as other well-documented challenges on the arithmetic level, but I hope that this can be the beginning of motion towards solving those challenges.
2021-03-26Update char::escape_debug_ext to handle different escapes in strings vs. charsÖmer Sinan Ağacan-4/+1
Fixes #83046 The program fn main() { println!("{:?}", '"'); println!("{:?}", "'"); } would previously print '\"' "\'" With this patch it now prints: '"' "'"
2021-03-24Revert "Revert stabilizing integer::BITS."Mara Bos-1/+0
2021-03-22Preserve signed zero on roundtripJubilee Young-2/+1
This commit removes the previous mechanism of differentiating between "Debug" and "Display" formattings for the sign of -0 so as to comply with the IEEE 754 standard's requirements on external character sequences preserving various attributes of a floating point representation. In addition, numerous tests are fixed.
2021-03-19Auto merge of #71780 - jcotton42:string_remove_matches, r=joshtriplettbors-0/+28
Implement String::remove_matches Closes #50206. I lifted the function help from `@frewsxcv's` original PR (#50015), hope they don't mind. I'm also wondering whether it would be useful for `remove_matches` to collect up the removed substrings into a `Vec` and return them, right now they're just overwritten by the copy and lost.
2021-03-16Vec::dedup optimization - add benchesSoveu-1/+1
2021-03-15Merge branch 'master' into dedupSoveu-3/+48
2021-03-15Vec::dedup optimization - add test for panicSoveu-0/+54
2021-03-15Vec::dedup optimization - add testsSoveu-0/+74
2021-03-05Implement String::remove_matchesJosh Cotton-0/+28
2021-03-04Add regression test for `Vec::extend_from_within` leakWaffle-0/+42
2021-03-04Rollup merge of #82564 - WaffleLapkin:revert_spare_mut, r=RalfJungYuki Okushi-0/+5
Revert `Vec::spare_capacity_mut` impl to prevent pointers invalidation The implementation was changed in #79015. Later it was [pointed out](https://github.com/rust-lang/rust/issues/81944#issuecomment-782849785) that the implementation invalidates pointers to the buffer (initialized elements) by creating a unique reference to the buffer. This PR reverts the implementation. r? ```@RalfJung```
2021-03-03Add test that Vec::spare_capacity_mut doesn't invalidate pointersWaffle-0/+5
2021-02-26Rollup merge of #81940 - jhpratt:stabilize-str_split_once, r=m-ou-seGuillaume Gomez-1/+0
Stabilize str_split_once Closes #74773
2021-02-20Update the bootstrap compilerJoshua Nelson-1/+1
Note this does not change `core::derive` since it was merged after the beta bump.
2021-02-13Added tests to drain an empty vecHanif Bin Ariffin-0/+11
Discovered this kind of issue in an unrelated library. The author copied the tests from here and AFAIK, there are no tests for this particular case. Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-02-11Auto merge of #81126 - oxalica:retain-early-drop, r=m-ou-sebors-0/+61
Optimize Vec::retain Use `copy_non_overlapping` instead of `swap` to reduce memory writes, like what we've done in #44355 and `String::retain`. #48065 already tried to do this optimization but it is reverted in #67300 due to bad codegen of `DrainFilter::drop`. This PR re-implement the drop-then-move approach. I did a [benchmark](https://gist.github.com/oxalica/3360eec9376f22533fcecff02798b698) on small-no-drop, small-need-drop, large-no-drop elements with different predicate functions. It turns out that the new implementation is >20% faster in average for almost all cases. Only 2/24 cases are slower by 3% and 5%. See the link above for more detail. I think regression in may-panic cases is due to drop-guard preventing some optimization. If it's permitted to leak elements when predicate function of element's `drop` panic, the new implementation should be almost always faster than current one. I'm not sure if we should leak on panic, since there is indeed an issue (#52267) complains about it before.
2021-02-09Stabilize str_split_onceJacob Pratt-1/+0
2021-02-03Revert stabilizing integer::BITS.Mara Bos-0/+1
2021-02-02Auto merge of #79015 - WaffleLapkin:vec_append_from_within, r=KodrAusbors-0/+71
add `Vec::extend_from_within` method under `vec_extend_from_within` feature gate Implement <https://github.com/rust-lang/rfcs/pull/2714> ### tl;dr This PR adds a `extend_from_within` method to `Vec` which allows copying elements from a range to the end: ```rust #![feature(vec_extend_from_within)] let mut vec = vec![0, 1, 2, 3, 4]; vec.extend_from_within(2..); assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4]); vec.extend_from_within(..2); assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1]); vec.extend_from_within(4..8); assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1, 4, 2, 3, 4]); ``` ### Implementation notes Originally I've copied `@Shnatsel's` [implementation](https://github.com/WanzenBug/rle-decode-helper/blob/690742a0de158d391b7bde1a0c71cccfdad33ab3/src/lib.rs#L74) with some minor changes to support other ranges: ```rust pub fn append_from_within<R>(&mut self, src: R) where T: Copy, R: RangeBounds<usize>, { let len = self.len(); let Range { start, end } = src.assert_len(len);; let count = end - start; self.reserve(count); unsafe { // This is safe because `reserve()` above succeeded, // so `self.len() + count` did not overflow usize ptr::copy_nonoverlapping( self.get_unchecked(src.start), self.as_mut_ptr().add(len), count, ); self.set_len(len + count); } } ``` But then I've realized that this duplicates most of the code from (private) `Vec::append_elements`, so I've used it instead. Then I've applied `@KodrAus` suggestions from https://github.com/rust-lang/rust/pull/79015#issuecomment-727200852.
2021-01-31add `Vec::extend_from_within` methodWaffle-0/+71
Implement <https://github.com/rust-lang/rfcs/pull/2714>, changes from the RFC: - Rename the method `append_from_within` => `extend_from_within` - Loose :Copy bound => :Clone - Specialize in case of :Copy This commit also adds `Vec::split_at_spare` private method and use it to implement `Vec::spare_capacity_mut` and `Vec::extend_from_within`. This method returns 2 slices - initialized elements (same as `&mut vec[..]`) and uninitialized but allocated space (same as `vec.spare_capacity_mut()`).
2021-01-31stabilize int_bits_constAshley Mannix-1/+0
2021-01-24Simplify and fix testsoxalica-51/+40
2021-01-18Fix soundness issue for `replace_range` and `range`dylni-0/+50
2021-01-18Optimize Vec::retainoxalica-0/+72
2021-01-04Stabilize split_inclusiveIan Jackson-1/+0
Closes #72360. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-12-31Auto merge of #79895 - Kerollmops:slice-group-by, r=m-ou-sebors-0/+59
The return of the GroupBy and GroupByMut iterators on slice According to https://github.com/rust-lang/rfcs/pull/2477#issuecomment-742034372, I am opening this PR again, this time I implemented it in safe Rust only, it is therefore much easier to read and is completely safe. This PR proposes to add two new methods to the slice, the `group_by` and `group_by_mut`. These two methods provide a way to iterate over non-overlapping sub-slices of a base slice that are separated by the predicate given by the user (e.g. `Partial::eq`, `|a, b| a.abs() < b.abs()`). ```rust let slice = &[1, 1, 1, 3, 3, 2, 2, 2]; let mut iter = slice.group_by(|a, b| a == b); assert_eq!(iter.next(), Some(&[1, 1, 1][..])); assert_eq!(iter.next(), Some(&[3, 3][..])); assert_eq!(iter.next(), Some(&[2, 2, 2][..])); assert_eq!(iter.next(), None); ``` [An RFC](https://github.com/rust-lang/rfcs/pull/2477) was open 2 years ago but wasn't necessary.
2020-12-26Auto merge of #79022 - SpyrosRoum:stabilize-deque_range, r=m-ou-sebors-1/+0
stabilize deque_range Make #74217 stable, stabilizing `VecDeque::range` and `VecDeque::range_mut`. Pr: #74099 r? `@m-ou-se`
2020-12-13replace assert! with assert_eq!Justus K-1/+1
2020-12-13fix panic if converting ZST Vec to VecDequeJustus K-0/+7
2020-12-10Update the slice GroupBy/Mut testClément Renault-4/+16
2020-12-10Implement it with only safe codeClément Renault-10/+29
2020-12-10Introduce the GroupBy and GroupByMut IteratorsClément Renault-0/+28
2020-12-04 Rename `AllocRef` to `Allocator` and `(de)alloc` to `(de)allocate`Tim Diekmann-4/+4
2020-12-02break formatting so rustfmt is happyRalf Jung-1/+2
2020-12-02disable a ptr equality test on MiriRalf Jung-1/+5
2020-11-30Make ui test that are run-pass and do not test the compiler itself library testsChristiaan Dirkx-1/+95
2020-11-26Fix new 'unnecessary trailing semicolon' warningsAaron Hill-3/+3
2020-11-15stabilize deque_rangeSpyros Roum-1/+0
2020-11-05Rollup merge of #76718 - poliorcetics:vec-ui-to-unit-test, r=jyn514Mara Bos-1/+193
Move Vec UI tests to unit tests when possible Helps with #76268. I'm moving the tests using `Vec` or `VecDeque`. ````@rustbot```` modify labels: A-testsuite C-cleanup T-libs
2020-10-29Added test for issue #78498Giacomo Stevanato-0/+15
2020-10-20Check for exhaustion in SliceIndex for RangeInclusiveJosh Stone-0/+29
2020-10-17Move subslice pattern tests to alloc/tests/slice.rsAlexis Bourget-0/+120
2020-10-17Move vec swap testAlexis Bourget-1/+13
2020-10-17Move vec-macro-repeat testAlexis Bourget-0/+13
2020-10-17Rebase conflictsAlexis Bourget-0/+30
2020-10-17Move zero-sized-vec-push testAlexis Bourget-0/+17
2020-10-09liballoc: VecDeque: Add binary search functionsVojtech Kral-0/+40
2020-10-07Auto merge of #74194 - mbrubeck:slice-eq, r=sfacklerbors-1/+2
Add PartialEq impls for Vec <-> slice This is a follow-up to #71660 and rust-lang/rfcs#2917 to add two more missing vec/slice PartialEq impls: ``` impl<A, B> PartialEq<[B]> for Vec<A> where A: PartialEq<B> { .. } impl<A, B> PartialEq<Vec<B>> for [A] where A: PartialEq<B> { .. } ``` Since this is insta-stable, it should go through the `@rust-lang/libs` FCP process. Note that I used version 1.47.0 for the `stable` attribute because I assume this will not merge before the 1.46.0 branch is cut next week.
2020-09-28Rollup merge of #76454 - poliorcetics:ui-to-unit-test-1, r=matkladRalf Jung-1/+409
UI to unit test for those using Cell/RefCell/UnsafeCell Helps with #76268. I'm working on all files using `Cell` and moving them to unit tests when possible. r? @matklad