protobuf_parse/
path.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::path::is_separator;

use crate::proto_path::ProtoPath;

pub(crate) fn fs_path_to_proto_path(path: &ProtoPath) -> String {
    path.to_str()
        .chars()
        .map(|c| if is_separator(c) { '/' } else { c })
        .collect()
}

#[cfg(test)]
mod test {
    use crate::path::fs_path_to_proto_path;
    use crate::ProtoPath;

    #[test]
    fn test_fs_path_to_proto_path() {
        assert_eq!(
            "foo.proto",
            fs_path_to_proto_path(ProtoPath::new("foo.proto").unwrap())
        );
        assert_eq!(
            "bar/foo.proto",
            fs_path_to_proto_path(ProtoPath::new("bar/foo.proto").unwrap())
        );
    }
}