Skip to main content

fastnoise2_serde/
lib.rs

1mod nodes;
2mod util;
3
4pub use nodes::*;
5pub use util::Hybrid;
6
7#[cfg(test)]
8mod tests {
9  use crate::*;
10
11  #[test]
12  fn deserialise_hybrid() {
13    let json_data = r#"{"Add": {"lhs": {"Constant": {"value": 5.0}}, "rhs": 2.5}}"#;
14    let vertex: Vertex = serde_json::from_str(json_data).unwrap();
15    assert!(matches!(vertex, Vertex::Add { .. }));
16
17    let default_json = r#"{"Constant": {}}"#;
18    let opt_vertex: Vertex = serde_json::from_str(default_json).unwrap();
19    if let Vertex::Constant { value } = opt_vertex {
20      assert_eq!(value, 1.0);
21    }
22  }
23}