|
1 |
| -use std::path::PathBuf; |
2 |
| - |
3 | 1 | use dt_scheduler::ParserCandidateScheduler;
|
| 2 | +use std::{collections::HashSet, path::PathBuf}; |
4 | 3 |
|
5 | 4 | #[test]
|
6 | 5 | fn topological_order() {
|
7 | 6 | let root = "tests/fixture";
|
8 | 7 | let mut scheduler = ParserCandidateScheduler::new(root);
|
9 | 8 |
|
10 |
| - let topological_order = [ |
11 |
| - "blocker.js", |
12 |
| - "reexport/default-alias.js", |
13 |
| - "reexport/wildcard-alias.js", |
14 |
| - "reexport/named-alias.js", |
15 |
| - "reexport/named.js", |
16 |
| - "reexport/default.js", |
17 |
| - "non-blocker.js", |
18 |
| - "import/side-effect.js", |
19 |
| - "import/default-alias.js", |
20 |
| - "import/named-alias.js", |
21 |
| - "import/named.js", |
22 |
| - "import/default.js", |
23 |
| - "reexport/wildcard.js", |
24 |
| - "import/namespace.js", |
25 |
| - "index.js", |
26 |
| - ]; |
| 9 | + let mut not_parsed = HashSet::from( |
| 10 | + [ |
| 11 | + "blocker.js", |
| 12 | + "reexport/default-alias.js", |
| 13 | + "reexport/wildcard-alias.js", |
| 14 | + "reexport/named-alias.js", |
| 15 | + "reexport/named.js", |
| 16 | + "reexport/default.js", |
| 17 | + "non-blocker.js", |
| 18 | + "import/side-effect.js", |
| 19 | + "import/default-alias.js", |
| 20 | + "import/named-alias.js", |
| 21 | + "import/named.js", |
| 22 | + "import/default.js", |
| 23 | + "reexport/wildcard.js", |
| 24 | + "import/namespace.js", |
| 25 | + "index.js", |
| 26 | + ] |
| 27 | + .map(|s| PathBuf::from(root).join(s).canonicalize().unwrap()), |
| 28 | + ); |
| 29 | + |
| 30 | + let wildcard_reexport = PathBuf::from(root) |
| 31 | + .join("reexport/wildcard.js") |
| 32 | + .canonicalize() |
| 33 | + .unwrap(); |
| 34 | + let namespace_import = PathBuf::from(root) |
| 35 | + .join("import/namespace.js") |
| 36 | + .canonicalize() |
| 37 | + .unwrap(); |
| 38 | + let blocker = PathBuf::from(root) |
| 39 | + .join("blocker.js") |
| 40 | + .canonicalize() |
| 41 | + .unwrap(); |
27 | 42 |
|
28 | 43 | assert_eq!(
|
29 | 44 | scheduler.get_total_remaining_candidate_count(),
|
30 |
| - topological_order.len() |
| 45 | + not_parsed.len() |
31 | 46 | );
|
32 |
| - for expected in topological_order { |
| 47 | + for _ in 0..not_parsed.len() { |
33 | 48 | let candidate = scheduler.get_one_candidate().unwrap();
|
34 |
| - assert_eq!( |
35 |
| - candidate, |
36 |
| - PathBuf::from(root).join(expected).canonicalize().unwrap() |
37 |
| - ); |
| 49 | + assert!(not_parsed.contains(&candidate)); |
| 50 | + |
| 51 | + // `reexport/wildcard.js` and `import/namespace.js` are blocked by `blocker.js` |
| 52 | + if candidate == blocker { |
| 53 | + assert!(not_parsed.contains(&wildcard_reexport)); |
| 54 | + assert!(not_parsed.contains(&namespace_import)); |
| 55 | + } |
| 56 | + |
| 57 | + not_parsed.remove(&candidate); |
38 | 58 | scheduler.mark_candidate_as_parsed(candidate);
|
39 | 59 | }
|
40 | 60 | assert_eq!(scheduler.get_total_remaining_candidate_count(), 0);
|
|
0 commit comments