As part of the test, I want to argue that the function returns a vector with the appropriate content. Therefore, I made the expected data available as static variables. However, I cannot find a suitable way to compare the contents of a managed vector with a static vector variable.
#[test] fn test_my_data_matches_expected_data () { static expected_data: [u8, ..3] = [1, 2, 3]; let my_data: ~[u8] = ~[1, 2, 3];
Update: Assigning a reference to a static vector before matching it works around the problem, so I ended up with a small macro to state the equality of vectors:
macro_rules! assert_typed_eq (($T: ty, $given: expr, $expected: expr) => ({ let given_val: &$T = $given; let expected_val: &$T = $expected; assert_eq!(given_val, expected_val); }))
Usage: assert_typed_eq([u8], my_data, expected_data);
comparison types static vector rust
Zargony
source share