Skip to content

Commit e0b937d

Browse files
authored
Add tests for AsRef/AsMut impls (#194)
1 parent a00333e commit e0b937d

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

tests/mod.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,54 @@ const EXAMPLE_SLICE: &[u8] = &[1, 2, 3, 4, 5, 6];
99
/// Ensure `ArrayN` works as expected.
1010
const _FOO: ArrayN<u8, 4> = Array([1, 2, 3, 4]);
1111

12+
#[test]
13+
fn as_ref_core_array() {
14+
type A = Array<u8, U2>;
15+
let array: A = Array([1, 2]);
16+
let array_ref: &[u8; 2] = array.as_ref();
17+
assert_eq!(&array, array_ref);
18+
}
19+
20+
#[test]
21+
fn as_ref_identity() {
22+
type A = Array<u8, U2>;
23+
let array: A = Array([1, 2]);
24+
let array_ref: &A = array.as_ref();
25+
assert_eq!(&array, array_ref);
26+
}
27+
28+
#[test]
29+
fn as_ref_slice() {
30+
type A = Array<u8, U2>;
31+
let array: A = Array([1, 2]);
32+
let slice: &[u8] = array.as_ref();
33+
assert_eq!(array.as_slice(), slice);
34+
}
35+
36+
#[test]
37+
fn as_mut_core_array() {
38+
type A = Array<u8, U2>;
39+
let mut array: A = Array([1, 2]);
40+
let array_ref: &mut [u8; 2] = array.as_mut();
41+
assert_eq!(&[1, 2], array_ref);
42+
}
43+
44+
#[test]
45+
fn as_mut_identity() {
46+
type A = Array<u8, U2>;
47+
let mut array: A = Array([1, 2]);
48+
let array_ref: &mut A = array.as_mut();
49+
assert_eq!(&[1, 2], array_ref);
50+
}
51+
52+
#[test]
53+
fn as_mut_slice() {
54+
type A = Array<u8, U2>;
55+
let mut array: A = Array([1, 2]);
56+
let slice: &mut [u8] = array.as_mut();
57+
assert_eq!(&[1, 2], slice);
58+
}
59+
1260
#[test]
1361
fn cast_slice_from_core() {
1462
type A = Array<u8, U2>;

0 commit comments

Comments
 (0)