Skip to content

Commit

Permalink
test: system call for filesystem might be different for different OS
Browse files Browse the repository at this point in the history
  • Loading branch information
wtlin1228 committed Oct 5, 2024
1 parent 47589d3 commit f21993d
Showing 1 changed file with 45 additions and 25 deletions.
70 changes: 45 additions & 25 deletions crates/dt_scheduler/tests/scheduler.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,60 @@
use std::path::PathBuf;

use dt_scheduler::ParserCandidateScheduler;
use std::{collections::HashSet, path::PathBuf};

#[test]
fn topological_order() {
let root = "tests/fixture";
let mut scheduler = ParserCandidateScheduler::new(root);

let topological_order = [
"blocker.js",
"reexport/default-alias.js",
"reexport/wildcard-alias.js",
"reexport/named-alias.js",
"reexport/named.js",
"reexport/default.js",
"non-blocker.js",
"import/side-effect.js",
"import/default-alias.js",
"import/named-alias.js",
"import/named.js",
"import/default.js",
"reexport/wildcard.js",
"import/namespace.js",
"index.js",
];
let mut not_parsed = HashSet::from(
[
"blocker.js",
"reexport/default-alias.js",
"reexport/wildcard-alias.js",
"reexport/named-alias.js",
"reexport/named.js",
"reexport/default.js",
"non-blocker.js",
"import/side-effect.js",
"import/default-alias.js",
"import/named-alias.js",
"import/named.js",
"import/default.js",
"reexport/wildcard.js",
"import/namespace.js",
"index.js",
]
.map(|s| PathBuf::from(root).join(s).canonicalize().unwrap()),
);

let wildcard_reexport = PathBuf::from(root)
.join("reexport/wildcard.js")
.canonicalize()
.unwrap();
let namespace_import = PathBuf::from(root)
.join("import/namespace.js")
.canonicalize()
.unwrap();
let blocker = PathBuf::from(root)
.join("blocker.js")
.canonicalize()
.unwrap();

assert_eq!(
scheduler.get_total_remaining_candidate_count(),
topological_order.len()
not_parsed.len()
);
for expected in topological_order {
for _ in 0..not_parsed.len() {
let candidate = scheduler.get_one_candidate().unwrap();
assert_eq!(
candidate,
PathBuf::from(root).join(expected).canonicalize().unwrap()
);
assert!(not_parsed.contains(&candidate));

// `reexport/wildcard.js` and `import/namespace.js` are blocked by `blocker.js`
if candidate == blocker {
assert!(not_parsed.contains(&wildcard_reexport));
assert!(not_parsed.contains(&namespace_import));
}

not_parsed.remove(&candidate);
scheduler.mark_candidate_as_parsed(candidate);
}
assert_eq!(scheduler.get_total_remaining_candidate_count(), 0);
Expand Down

0 comments on commit f21993d

Please sign in to comment.