1use crate::vocabulary;
2
3pub fn mime_hint(type_id: &str) -> Option<String> {
5 let vocab = vocabulary::vocabulary();
6 let mut current = type_id;
7 loop {
8 match vocab.get(current) {
9 None => return None,
10 Some(def) => {
11 if let Some(mime) = &def.mime {
12 return Some(mime.clone());
13 }
14 match def.parent.as_deref() {
15 None => return None,
16 Some(p) => current = p,
17 }
18 }
19 }
20 }
21}
22
23#[cfg(test)]
24mod tests {
25 use super::*;
26
27 #[test]
28 fn fasta_mime() {
29 assert_eq!(mime_hint("fasta").as_deref(), Some("application/x-fasta"));
30 }
31
32 #[test]
33 fn blast_tab_inherits_tabular_mime() {
34 assert_eq!(
35 mime_hint("blast_tab").as_deref(),
36 Some("text/tab-separated-values")
37 );
38 }
39
40 #[test]
41 fn blast_db_no_mime() {
42 assert_eq!(mime_hint("blast_db"), None);
43 }
44
45 #[test]
46 fn unknown_no_mime() {
47 assert_eq!(mime_hint("no_such_type"), None);
48 }
49}