use super::dummy_components::{A, B, C, D, E, F, G, H}; use cool_asserts::assert_panics; use dynamecs::{Component, Universe}; type StorageFor = ::Storage; type S = StorageFor; #[test] fn get_component_storages_compiles_for_tuple_arguments() { let universe = Universe::default(); let (_,): (&S,) = universe.get_component_storages::<(&A,)>(); let (_, _): (&S, &S) = universe.get_component_storages::<(&A, &B)>(); let (_, _, _): (&S, &S, &S) = universe.get_component_storages::<(&A, &B, &C)>(); let (_, _, _, _): (&S, &S, &S, &S) = universe.get_component_storages::<(&A, &B, &C, &D)>(); let (_, _, _, _, _): (&S, &S, &S, &S, &S) = universe.get_component_storages::<(&A, &B, &C, &D, &E)>(); let (_, _, _, _, _, _): (&S, &S, &S, &S, &S, &S) = universe.get_component_storages::<(&A, &B, &C, &D, &E, &F)>(); let (_, _, _, _, _, _, _): (&S, &S, &S, &S, &S, &S, &S) = universe.get_component_storages::<(&A, &B, &C, &D, &E, &F, &G)>(); let (_, _, _, _, _, _, _, _): (&S, &S, &S, &S, &S, &S, &S, &S) = universe.get_component_storages::<(&A, &B, &C, &D, &E, &F, &G, &H)>(); } #[test] fn get_component_storages_mut_compiles_for_tuple_arguments() { let mut universe = Universe::default(); // 1-element tuple let _: (&S,) = universe.get_component_storages_mut::<(&A,)>(); let _: (&mut S,) = universe.get_component_storages_mut::<(&mut A,)>(); // 2-element tuple let _: (&S, &S) = universe.get_component_storages_mut::<(&A, &B)>(); let _: (&mut S, &S) = universe.get_component_storages_mut::<(&mut A, &B)>(); let _: (&S, &mut S) = universe.get_component_storages_mut::<(&A, &mut B)>(); let _: (&mut S, &mut S) = universe.get_component_storages_mut::<(&mut A, &mut B)>(); // 3-element tuple let _: (&S, &S, &S) = universe.get_component_storages_mut::<(&A, &B, &C)>(); let _: (&mut S, &S, &S) = universe.get_component_storages_mut::<(&mut A, &B, &C)>(); let _: (&S, &mut S, &S) = universe.get_component_storages_mut::<(&A, &mut B, &C)>(); let _: (&S, &S, &mut S) = universe.get_component_storages_mut::<(&A, &B, &mut C)>(); let _: (&mut S, &mut S, &S) = universe.get_component_storages_mut::<(&mut A, &mut B, &C)>(); let _: (&S, &mut S, &mut S) = universe.get_component_storages_mut::<(&A, &mut B, &mut C)>(); let _: (&mut S, &S, &mut S) = universe.get_component_storages_mut::<(&mut A, &B, &mut C)>(); let _: (&mut S, &mut S, &mut S) = universe.get_component_storages_mut::<(&mut A, &mut B, &mut C)>(); // For larger tuples the number of combinations become too large, therefore we only // test a few combinations // 4-element tuple let _: (&S, &S, &S, &S) = universe.get_component_storages_mut::<(&A, &B, &C, &D)>(); let _: (&mut S, &S, &mut S, &S) = universe.get_component_storages_mut::<(&mut A, &B, &mut C, &D)>(); let _: (&mut S, &mut S, &mut S, &mut S) = universe.get_component_storages_mut::<(&mut A, &mut B, &mut C, &mut D)>(); // 5-element tuple let _: (&S, &S, &S, &S, &S) = universe.get_component_storages_mut::<(&A, &B, &C, &D, &E)>(); let _: (&mut S, &S, &mut S, &S, &S) = universe.get_component_storages_mut::<(&mut A, &B, &mut C, &D, &E)>(); let _: (&mut S, &mut S, &mut S, &mut S, &mut S) = universe.get_component_storages_mut::<(&mut A, &mut B, &mut C, &mut D, &mut E)>(); // 6-element tuple let _: (&S, &S, &S, &S, &S, &S) = universe.get_component_storages_mut::<(&A, &B, &C, &D, &E, &F)>(); let _: (&mut S, &S, &mut S, &S, &S, &mut S) = universe.get_component_storages_mut::<(&mut A, &B, &mut C, &D, &E, &mut F)>(); let _: (&mut S, &mut S, &mut S, &mut S, &mut S, &mut S) = universe.get_component_storages_mut::<(&mut A, &mut B, &mut C, &mut D, &mut E, &mut F)>(); // 7-element tuple let _: (&S, &S, &S, &S, &S, &S, &S) = universe.get_component_storages_mut::<(&A, &B, &C, &D, &E, &F, &G)>(); let _: (&mut S, &S, &mut S, &S, &S, &mut S, &S) = universe.get_component_storages_mut::<(&mut A, &B, &mut C, &D, &E, &mut F, &G)>(); let _: ( &mut S, &mut S, &mut S, &mut S, &mut S, &mut S, &mut S, ) = universe.get_component_storages_mut::<(&mut A, &mut B, &mut C, &mut D, &mut E, &mut F, &mut G)>(); // 8-element tuple let _: (&S, &S, &S, &S, &S, &S, &S, &S) = universe.get_component_storages_mut::<(&A, &B, &C, &D, &E, &F, &G, &H)>(); let _: (&mut S, &S, &mut S, &S, &S, &mut S, &S, &mut S) = universe.get_component_storages_mut::<(&mut A, &B, &mut C, &D, &E, &mut F, &G, &mut H)>(); let _: ( &mut S, &mut S, &mut S, &mut S, &mut S, &mut S, &mut S, &mut S, ) = universe.get_component_storages_mut::<(&mut A, &mut B, &mut C, &mut D, &mut E, &mut F, &mut G, &mut H)>(); } #[test] fn get_component_storages_mut_panics_if_duplicate_arguments_provided() { let expected_msg = "Stopped attempt to obtain multiple mutable references to the same storage. \ Can not simultaneously mutably borrow the same storage type multiple times."; assert_panics!( { let _ = Universe::default().get_component_storages_mut::<(&mut A, &mut A)>(); }, includes(expected_msg) ); assert_panics!( { let _ = Universe::default().get_component_storages_mut::<(&mut A, &A)>(); }, includes(expected_msg) ); assert_panics!( { let _ = Universe::default().get_component_storages_mut::<(&mut A, &B, &A, &mut C)>(); }, includes(expected_msg) ); }