diff options
| author | Lzu Tao <taolzu@gmail.com> | 2020-08-27 13:45:01 +0000 | 
|---|---|---|
| committer | Lzu Tao <taolzu@gmail.com> | 2020-08-31 02:56:59 +0000 | 
| commit | a4e926daeeaedc9178846711daf1f4cb6ce505fb (patch) | |
| tree | 0c830f716f6f5ad17736d459f5de9b9199006d54 /library/std/src/memchr.rs | |
| parent | db6cbfc49ca655739ba8caae43ebd7c77c8a1179 (diff) | |
| download | rust-a4e926daeeaedc9178846711daf1f4cb6ce505fb.tar.gz rust-a4e926daeeaedc9178846711daf1f4cb6ce505fb.zip | |
std: move "mod tests/benches" to separate files
Also doing fmt inplace as requested.
Diffstat (limited to 'library/std/src/memchr.rs')
| -rw-r--r-- | library/std/src/memchr.rs | 90 | 
1 files changed, 3 insertions, 87 deletions
| diff --git a/library/std/src/memchr.rs b/library/std/src/memchr.rs index d69294b2d20..86a08f75a8d 100644 --- a/library/std/src/memchr.rs +++ b/library/std/src/memchr.rs @@ -1,6 +1,9 @@ // Original implementation taken from rust-memchr. // Copyright 2015 Andrew Gallant, bluss and Nicolas Koch +#[cfg(test)] +mod tests; + /// A safe interface to `memchr`. /// /// Returns the index corresponding to the first occurrence of `needle` in @@ -44,90 +47,3 @@ pub fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> { pub fn memrchr(needle: u8, haystack: &[u8]) -> Option<usize> { crate::sys::memchr::memrchr(needle, haystack) } - -#[cfg(test)] -mod tests { - // test the implementations for the current platform - use super::{memchr, memrchr}; - - #[test] - fn matches_one() { - assert_eq!(Some(0), memchr(b'a', b"a")); - } - - #[test] - fn matches_begin() { - assert_eq!(Some(0), memchr(b'a', b"aaaa")); - } - - #[test] - fn matches_end() { - assert_eq!(Some(4), memchr(b'z', b"aaaaz")); - } - - #[test] - fn matches_nul() { - assert_eq!(Some(4), memchr(b'\x00', b"aaaa\x00")); - } - - #[test] - fn matches_past_nul() { - assert_eq!(Some(5), memchr(b'z', b"aaaa\x00z")); - } - - #[test] - fn no_match_empty() { - assert_eq!(None, memchr(b'a', b"")); - } - - #[test] - fn no_match() { - assert_eq!(None, memchr(b'a', b"xyz")); - } - - #[test] - fn matches_one_reversed() { - assert_eq!(Some(0), memrchr(b'a', b"a")); - } - - #[test] - fn matches_begin_reversed() { - assert_eq!(Some(3), memrchr(b'a', b"aaaa")); - } - - #[test] - fn matches_end_reversed() { - assert_eq!(Some(0), memrchr(b'z', b"zaaaa")); - } - - #[test] - fn matches_nul_reversed() { - assert_eq!(Some(4), memrchr(b'\x00', b"aaaa\x00")); - } - - #[test] - fn matches_past_nul_reversed() { - assert_eq!(Some(0), memrchr(b'z', b"z\x00aaaa")); - } - - #[test] - fn no_match_empty_reversed() { - assert_eq!(None, memrchr(b'a', b"")); - } - - #[test] - fn no_match_reversed() { - assert_eq!(None, memrchr(b'a', b"xyz")); - } - - #[test] - fn each_alignment() { - let mut data = [1u8; 64]; - let needle = 2; - let pos = 40; - data[pos] = needle; - for start in 0..16 { - assert_eq!(Some(pos - start), memchr(needle, &data[start..])); - } - } -} | 
