protobuf_parse/
path.rs

1use std::path::is_separator;
2
3use crate::proto_path::ProtoPath;
4
5pub(crate) fn fs_path_to_proto_path(path: &ProtoPath) -> String {
6    path.to_str()
7        .chars()
8        .map(|c| if is_separator(c) { '/' } else { c })
9        .collect()
10}
11
12#[cfg(test)]
13mod test {
14    use crate::path::fs_path_to_proto_path;
15    use crate::ProtoPath;
16
17    #[test]
18    fn test_fs_path_to_proto_path() {
19        assert_eq!(
20            "foo.proto",
21            fs_path_to_proto_path(ProtoPath::new("foo.proto").unwrap())
22        );
23        assert_eq!(
24            "bar/foo.proto",
25            fs_path_to_proto_path(ProtoPath::new("bar/foo.proto").unwrap())
26        );
27    }
28}