yarn.rs

 1use project::yarn::*;
 2use std::path::Path;
 3
 4#[test]
 5fn test_resolve_virtual() {
 6    let test_cases = vec![
 7        (
 8            "/path/to/some/folder/__virtual__/a0b1c2d3/0/subpath/to/file.dat",
 9            Some(Path::new("/path/to/some/folder/subpath/to/file.dat")),
10        ),
11        (
12            "/path/to/some/folder/__virtual__/e4f5a0b1/0/subpath/to/file.dat",
13            Some(Path::new("/path/to/some/folder/subpath/to/file.dat")),
14        ),
15        (
16            "/path/to/some/folder/__virtual__/a0b1c2d3/1/subpath/to/file.dat",
17            Some(Path::new("/path/to/some/subpath/to/file.dat")),
18        ),
19        (
20            "/path/to/some/folder/__virtual__/a0b1c2d3/3/subpath/to/file.dat",
21            Some(Path::new("/path/subpath/to/file.dat")),
22        ),
23        ("/path/to/nonvirtual/", None),
24        ("/path/to/malformed/__virtual__", None),
25        ("/path/to/malformed/__virtual__/a0b1c2d3", None),
26        (
27            "/path/to/malformed/__virtual__/a0b1c2d3/this-should-be-a-number",
28            None,
29        ),
30    ];
31
32    for (input, expected) in test_cases {
33        let input_path = Path::new(input);
34        let resolved_path = resolve_virtual(input_path);
35        assert_eq!(resolved_path.as_deref(), expected);
36    }
37}