Skip to content

Commit 693817f

Browse files
authored
Add tests for From impls for core arrays (#203)
These impls convert from `Array`, `&Array`, and `&mut Array`
1 parent d6d47ea commit 693817f

File tree

1 file changed

+42
-21
lines changed

1 file changed

+42
-21
lines changed

tests/mod.rs

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,48 @@ fn cast_slice_to_core_mut() {
155155
assert_eq!(slice[1], [3, 4]);
156156
}
157157

158+
#[test]
159+
fn from_hybrid_array_for_core_array() {
160+
let hybrid_arr: Array<u8, U2> = Array([1, 2]);
161+
let core_arr = <[u8; 2]>::from(hybrid_arr);
162+
assert_eq!(core_arr, [1, 2]);
163+
}
164+
165+
#[test]
166+
fn from_hybrid_ref_for_core_ref() {
167+
let hybrid_arr: &Array<u8, U2> = &Array([1, 2]);
168+
let core_arr = <&[u8; 2]>::from(hybrid_arr);
169+
assert_eq!(core_arr, &[1, 2]);
170+
}
171+
172+
#[test]
173+
fn from_hybrid_mut_for_core_mut() {
174+
let hybrid_arr: &mut Array<u8, U2> = &mut Array([1, 2]);
175+
let core_arr = <&mut [u8; 2]>::from(hybrid_arr);
176+
assert_eq!(core_arr, &[1, 2]);
177+
}
178+
179+
#[test]
180+
fn from_ref() {
181+
let n = 42u64;
182+
let array = Array::from_ref(&n);
183+
assert_eq!(array[0], n);
184+
}
185+
186+
#[test]
187+
fn from_mut() {
188+
let mut n = 42u64;
189+
let array = Array::from_mut(&mut n);
190+
array[0] = 43;
191+
assert_eq!(n, 43);
192+
}
193+
194+
#[test]
195+
fn from_fn() {
196+
let array = Array::<u8, U6>::from_fn(|n| (n + 1) as u8);
197+
assert_eq!(array.as_slice(), EXAMPLE_SLICE);
198+
}
199+
158200
#[test]
159201
fn tryfrom_slice_for_clonable_array() {
160202
assert!(Array::<u8, U0>::try_from(EXAMPLE_SLICE).is_err());
@@ -274,27 +316,6 @@ fn split_ref_mut() {
274316
assert_eq!(suffix.as_slice(), &EXAMPLE_SLICE[4..]);
275317
}
276318

277-
#[test]
278-
fn from_ref() {
279-
let n = 42u64;
280-
let array = Array::from_ref(&n);
281-
assert_eq!(array[0], n);
282-
}
283-
284-
#[test]
285-
fn from_mut() {
286-
let mut n = 42u64;
287-
let array = Array::from_mut(&mut n);
288-
array[0] = 43;
289-
assert_eq!(n, 43);
290-
}
291-
292-
#[test]
293-
fn from_fn() {
294-
let array = Array::<u8, U6>::from_fn(|n| (n + 1) as u8);
295-
assert_eq!(array.as_slice(), EXAMPLE_SLICE);
296-
}
297-
298319
#[test]
299320
fn try_from_fn() {
300321
let array = Array::<u8, U6>::try_from_fn::<()>(|n| Ok((n + 1) as u8)).unwrap();

0 commit comments

Comments
 (0)