Skip to content

Commit e9c3d23

Browse files
authored
Add tests for Borrow(Mut) impls (#199)
1 parent ca9536d commit e9c3d23

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

tests/mod.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
#![allow(missing_docs, clippy::cast_possible_truncation, clippy::unwrap_used)]
1+
//! Integration tests.
22
3-
use core::mem::MaybeUninit;
3+
#![allow(clippy::cast_possible_truncation, clippy::unwrap_used)]
4+
5+
use core::{
6+
borrow::{Borrow, BorrowMut},
7+
mem::MaybeUninit,
8+
};
49
use hybrid_array::{Array, ArrayN};
510
use typenum::{U0, U2, U3, U4, U5, U6, U7};
611

@@ -67,6 +72,38 @@ fn as_mut_slice() {
6772
assert_eq!(&[1, 2], slice);
6873
}
6974

75+
#[test]
76+
fn borrow_core_array() {
77+
type A = Array<u8, U2>;
78+
let array: A = Array([1, 2]);
79+
let array_ref: &[u8; 2] = array.borrow();
80+
assert_eq!(&array, array_ref);
81+
}
82+
83+
#[test]
84+
fn borrow_identity() {
85+
type A = Array<u8, U2>;
86+
let array: A = Array([1, 2]);
87+
let array_ref: &A = array.borrow();
88+
assert_eq!(&array, array_ref);
89+
}
90+
91+
#[test]
92+
fn borrow_mut_identity() {
93+
type A = Array<u8, U2>;
94+
let mut array: A = Array([1, 2]);
95+
let array_ref: &mut A = array.borrow_mut();
96+
assert_eq!(&[1, 2], array_ref);
97+
}
98+
99+
#[test]
100+
fn borrow_mut_core_array() {
101+
type A = Array<u8, U2>;
102+
let mut array: A = Array([1, 2]);
103+
let array_ref: &mut [u8; 2] = array.borrow_mut();
104+
assert_eq!(&[1, 2], array_ref);
105+
}
106+
70107
#[test]
71108
fn cast_slice_from_core() {
72109
type A = Array<u8, U2>;

0 commit comments

Comments
 (0)