mnx_rs/
lib.rs

1mod mnx;
2
3pub use mnx::*;
4
5#[cfg(test)]
6mod test {
7    use super::*;
8    use std::fs;
9    use std::path::PathBuf;
10
11    fn test_data_dir() -> PathBuf {
12        let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
13        path.push("docs");
14        path.push("test-data");
15        path.canonicalize().expect(&format!(
16            "failed to canonicalize {}",
17            path.to_string_lossy()
18        ))
19    }
20
21    fn test_path(s: &str) -> PathBuf {
22        let mut path = test_data_dir();
23        path.push(s);
24        path.canonicalize().expect(&format!(
25            "failed to canonicalize {}",
26            path.to_string_lossy()
27        ))
28    }
29
30    #[test]
31    fn test() {
32        let p = test_path("hello-world.json");
33        let json = fs::read_to_string(&p).unwrap();
34        let mnx = serde_json::from_str::<MnxDocument>(&json).unwrap();
35        let expected_barline_type = MnxDocumentGlobalMeasuresItemBarlineType::Regular;
36        let actual_barline_type = mnx
37            .global
38            .measures
39            .first()
40            .unwrap()
41            .barline
42            .clone()
43            .unwrap()
44            .type_;
45
46        // I tried using assert!(matches!()) but can't figure it out.
47        match expected_barline_type {
48            MnxDocumentGlobalMeasuresItemBarlineType::Regular => {}
49            _ => panic!(
50                "unexpected barline type, expected {:?}, got {:?}",
51                expected_barline_type, actual_barline_type
52            ),
53        }
54
55        // TODO: more assertions of what is in this file
56    }
57
58    // TODO: write tests for the other example files
59}