synthahol_dx7/
format.rs

1use std::path::Path;
2
3use crate::SYSEX_HEADER;
4
5const FORMAT_IDENTIFIER: [u8; 6] = SYSEX_HEADER;
6
7pub struct Format;
8
9impl Format {
10    pub fn name() -> &'static str {
11        "Yamaha DX7"
12    }
13
14    pub fn filename_extension() -> &'static str {
15        "syx"
16    }
17
18    pub fn is_format(_path: &Path, header: &[u8]) -> bool {
19        header.starts_with(&FORMAT_IDENTIFIER)
20    }
21}
22
23#[cfg(test)]
24mod test {
25    use std::fs::read;
26
27    use crate::tests::test_data_path;
28
29    use super::Format;
30
31    #[test]
32    fn filename_extension() {
33        assert_eq!(Format::filename_extension(), "syx");
34    }
35
36    #[test]
37    fn name() {
38        assert_eq!(Format::name(), "Yamaha DX7");
39    }
40
41    #[test]
42    fn init_version_1() {
43        let path = test_data_path(&["rom1a.syx"]);
44        let contents = read(&path).unwrap();
45        assert!(Format::is_format(&path, &contents));
46    }
47
48    #[test]
49    fn short() {
50        let path = test_data_path(&["rom1a.syx"]);
51        let contents = read(&path).unwrap();
52        let shortened = &contents[..3];
53        assert!(!Format::is_format(&path, &shortened));
54    }
55}