Compare commits

..

No commits in common. "ba2e782af5a3efd3b147fec7b9f338fa8c4973ec" and "d6cb0fba1aefa40235c7a4d0ed6f4397fb35dbe4" have entirely different histories.

3 changed files with 40 additions and 21 deletions

View File

@ -10,7 +10,8 @@ description = "Crossplatform (and web-compatible) graphing calculator"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib"]
[features] [features]
wayland-native = ["eframe/wayland"] # Enable wayland support for running tests on native targets
native-test = ["eframe/wayland"]
[profile.release] [profile.release]
debug = false debug = false

View File

@ -77,7 +77,7 @@
'' ''
runHook preCheck runHook preCheck
export LD_LIBRARY_PATH="${libPath}:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH="${libPath}:$LD_LIBRARY_PATH"
cargo test --workspace --features wayland-native cargo test --workspace --features native-test
runHook postCheck runHook postCheck
''; '';

View File

@ -9,35 +9,53 @@ use std::hash::{Hash, Hasher};
use std::ops::BitXorAssign; use std::ops::BitXorAssign;
type Functions = Vec<(Id, FunctionEntry)>; type Functions = Vec<(Id, FunctionEntry)>;
#[derive(Serialize, Deserialize)]
pub struct FunctionManager { pub struct FunctionManager {
functions: Functions, functions: Functions,
} }
impl Default for FunctionManager { impl Default for FunctionManager {
fn default() -> Self { fn default() -> Self {
let mut d = Self { let mut vec: Functions = Vec::with_capacity(COLORS.len());
functions: Vec::new() vec.push((
}; Id::new(11414819524356497634_u64), // Random number here to avoid call to crate::misc::random_u64()
d.push_empty(); FunctionEntry::default(),
d ));
Self { functions: vec }
} }
} }
#[test] impl Serialize for FunctionManager {
fn func_manager_roundtrip_serdes() { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
let mut func_manager = FunctionManager { where
functions: Vec::new(), S: Serializer,
}; {
let mut s = serializer.serialize_struct("FunctionManager", 1)?;
s.serialize_field(
"data",
&self
.functions
.iter()
.map(|(id, func)| (*id, func.clone()))
.collect::<Vec<(Id, FunctionEntry)>>(),
)?;
s.end()
}
}
func_manager.push_empty(); impl<'de> Deserialize<'de> for FunctionManager {
let ser = bincode::serialize(&func_manager).expect("unable to serialize"); fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
let des: FunctionManager = bincode::deserialize(&ser).expect("unable to deserialize"); where
assert_eq!( D: Deserializer<'de>,
func_manager.functions[0].1.raw_func_str, {
des.functions[0].1.raw_func_str #[derive(Deserialize)]
); struct Helper(Vec<(Id, FunctionEntry)>);
let helper = Helper::deserialize(deserializer)?;
Ok(FunctionManager {
functions: helper.0.to_vec(),
})
}
} }
/// Function that creates button that's used with the `button_area` /// Function that creates button that's used with the `button_area`