Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RoDmitry committed Mar 2, 2024
1 parent 33014e7 commit 46a1803
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ fn load_8(s: &[u8]) -> u64 {
2 => u16::from_le_bytes(s[0..2].try_into().unwrap()) as u64,
1 => s[0] as u64,
0 => 0,
_ => unsafe { ::core::hint::unreachable_unchecked() },
#[allow(unreachable_patterns)]
_ => unsafe { ::core::hint::unreachable_unchecked() }, // unreachable since 1.75
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/simd/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ unsafe fn load_8(s: &[u8]) -> uint8x8_t {
vset_lane_u8(s[0], data, 0)
}
0 => vreinterpret_u8_u32(data),
#[allow(unreachable_patterns)]
_ => ::core::hint::unreachable_unchecked(), // unreachable since 1.75
}
}
Expand Down Expand Up @@ -170,6 +171,7 @@ unsafe fn load_16(s: &[u8]) -> uint8x16_t {
vsetq_lane_u8(s[0], data, 0)
}
0 => vreinterpretq_u8_u64(data),
#[allow(unreachable_patterns)]
_ => ::core::hint::unreachable_unchecked(), // unreachable since 1.75
}
}
Expand Down Expand Up @@ -493,7 +495,8 @@ pub(crate) fn parse_simd_u128(s: &[u8]) -> Result<(u128, usize), AtoiSimdError>
16 => {
(extra, len) = parse_simd_extra(s, &mut chunk1, &mut chunk2)?;
}
_ => ::core::hint::unreachable_unchecked(),
#[allow(unreachable_patterns)]
_ => ::core::hint::unreachable_unchecked(), // unreachable since 1.75
};

let (sum1, chunk1) = odd_even_8(chunk1);
Expand Down
2 changes: 2 additions & 0 deletions src/simd/sse_avx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ unsafe fn load(s: &[u8]) -> __m128i {
),
1 => _mm_set_epi32(0, 0, 0, s[0] as i32),
0 => _mm_setzero_si128(),
#[allow(unreachable_patterns)]
_ => ::core::hint::unreachable_unchecked(), // unreachable since 1.75
}
}
Expand Down Expand Up @@ -496,6 +497,7 @@ unsafe fn load_avx(s: &[u8]) -> __m256i {
),
1 => _mm256_set_epi32(0, 0, 0, 0, 0, 0, 0, s[0] as i32),
0 => _mm256_setzero_si256(),
#[allow(unreachable_patterns)]
_ => ::core::hint::unreachable_unchecked(), // unreachable since 1.75
}
}
Expand Down
25 changes: 25 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(unused_imports)]
use ::core::cmp::PartialEq;
use ::core::fmt::Debug;
use ::core::str::FromStr;
Expand Down Expand Up @@ -526,41 +527,65 @@ fn test_parse_pos() {
let tmp: i8 = parse_pos(b"123").unwrap();
assert_eq!(tmp, 123_i8);

assert!(parse_pos::<i8>((i8::MAX as u32 + 1).to_string().as_bytes()).is_err());

let tmp: i16 = parse_pos(b"1234").unwrap();
assert_eq!(tmp, 1234_i16);

assert!(parse_pos::<i16>((i16::MAX as u32 + 1).to_string().as_bytes()).is_err());

let tmp: i32 = parse_pos(b"1234").unwrap();
assert_eq!(tmp, 1234_i32);

assert!(parse_pos::<i32>((i32::MAX as u32 + 1).to_string().as_bytes()).is_err());

let tmp: isize = parse_pos(b"1234").unwrap();
assert_eq!(tmp, 1234_isize);

assert!(parse_pos::<isize>((isize::MAX as u64 + 1).to_string().as_bytes()).is_err());

let tmp: i64 = parse_pos(b"1234").unwrap();
assert_eq!(tmp, 1234_i64);

assert!(parse_pos::<i64>((i64::MAX as u64 + 1).to_string().as_bytes()).is_err());

let tmp: i128 = parse_pos(b"999999").unwrap();
assert_eq!(tmp, 999999_i128);

assert!(parse_pos::<i128>((i128::MAX as u128 + 1).to_string().as_bytes()).is_err());
}

#[test]
fn test_parse_neg() {
let tmp: i8 = parse_neg(b"123").unwrap();
assert_eq!(tmp, -123_i8);

assert!(parse_neg::<i8>((i8::MAX as u32 + 2).to_string().as_bytes()).is_err());

let tmp: i16 = parse_neg(b"1234").unwrap();
assert_eq!(tmp, -1234_i16);

assert!(parse_neg::<i16>((i16::MAX as u32 + 2).to_string().as_bytes()).is_err());

let tmp: i32 = parse_neg(b"1234").unwrap();
assert_eq!(tmp, -1234_i32);

assert!(parse_neg::<i32>((i32::MAX as u32 + 2).to_string().as_bytes()).is_err());

let tmp: isize = parse_neg(b"1234").unwrap();
assert_eq!(tmp, -1234_isize);

assert!(parse_neg::<isize>((isize::MAX as u64 + 2).to_string().as_bytes()).is_err());

let tmp: i64 = parse_neg(b"1234").unwrap();
assert_eq!(tmp, -1234_i64);

assert!(parse_neg::<i64>((i64::MAX as u64 + 2).to_string().as_bytes()).is_err());

let tmp: i128 = parse_neg(b"999999").unwrap();
assert_eq!(tmp, -999999_i128);

assert!(parse_neg::<i128>((i128::MAX as u128 + 2).to_string().as_bytes()).is_err());
}

#[test]
Expand Down

0 comments on commit 46a1803

Please sign in to comment.