Some checks failed
Update All Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Triage Project Sync (#84) / Sync triage project (push) Has been cancelled
release_nightly / notify_on_failure (push) Has been cancelled
release_nightly / check_style (push) Has been cancelled
release_nightly / run_tests_windows (push) Has been cancelled
release_nightly / clippy_windows (push) Has been cancelled
release_nightly / bundle_linux_aarch64 (push) Has been cancelled
release_nightly / bundle_linux_x86_64 (push) Has been cancelled
release_nightly / bundle_mac_aarch64 (push) Has been cancelled
release_nightly / bundle_mac_x86_64 (push) Has been cancelled
release_nightly / bundle_windows_aarch64 (push) Has been cancelled
release_nightly / bundle_windows_x86_64 (push) Has been cancelled
release_nightly / build_nix_linux_x86_64 (push) Has been cancelled
release_nightly / build_nix_mac_aarch64 (push) Has been cancelled
release_nightly / update_nightly_tag (push) Has been cancelled
Hotfix Review Monitor / check-hotfix-reviews (push) Has been cancelled
Stale PR Review Reminder / check-stale-prs (push) Has been cancelled
Update Weekly Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Bump collab-staging Tag / update-collab-staging-tag (push) Has been cancelled
compliance_check / scheduled_compliance_check (push) Has been cancelled
Single-commit orphan branch: full zed-industries/zed @ 8c74db0 source tree with a 3-file patch applied (no upstream history). Patch (crates/gpui_linux/src/linux/wayland/): - serial.rs: add SerialKind::KeyboardEnter - client.rs: store wl_keyboard.enter serial; add latest_serial_of() - window.rs: activate() uses keyboard-enter serial (Mutter focus gate) Mutter honors window activation only when the token carries the keyboard- focus serial from wl_keyboard.enter; GPUI used a stale mouse-press serial. See docs/tray-window-focus-wayland.md in logiguard. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
125 lines
4.9 KiB
Rust
125 lines
4.9 KiB
Rust
mod path_trie {
|
|
use std::{collections::BTreeSet, ops::ControlFlow};
|
|
|
|
use util::rel_path::rel_path;
|
|
|
|
use project::manifest_tree::path_trie::*;
|
|
|
|
#[test]
|
|
fn test_insert_and_lookup() {
|
|
let mut trie = RootPathTrie::<()>::new();
|
|
trie.insert(
|
|
&TriePath::new(rel_path("a/b/c")),
|
|
(),
|
|
LabelPresence::Present,
|
|
);
|
|
|
|
trie.walk(&TriePath::new(rel_path("a/b/c")), &mut |path, nodes| {
|
|
assert_eq!(nodes.get(&()), Some(&LabelPresence::Present));
|
|
assert_eq!(path.as_unix_str(), "a/b/c");
|
|
ControlFlow::Continue(())
|
|
});
|
|
// Now let's annotate a parent with "Known missing" node.
|
|
trie.insert(
|
|
&TriePath::new(rel_path("a")),
|
|
(),
|
|
LabelPresence::KnownAbsent,
|
|
);
|
|
|
|
// Ensure that we walk from the root to the leaf.
|
|
let mut visited_paths = BTreeSet::new();
|
|
trie.walk(&TriePath::new(rel_path("a/b/c")), &mut |path, nodes| {
|
|
if path.as_unix_str() == "a/b/c" {
|
|
assert_eq!(visited_paths, BTreeSet::from_iter([rel_path("a").into()]));
|
|
assert_eq!(nodes.get(&()), Some(&LabelPresence::Present));
|
|
} else if path.as_unix_str() == "a" {
|
|
assert!(visited_paths.is_empty());
|
|
assert_eq!(nodes.get(&()), Some(&LabelPresence::KnownAbsent));
|
|
} else {
|
|
panic!("Unknown path");
|
|
}
|
|
// Assert that we only ever visit a path once.
|
|
assert!(visited_paths.insert(path.clone()));
|
|
ControlFlow::Continue(())
|
|
});
|
|
|
|
// One can also pass a path whose prefix is in the tree, but not that path itself.
|
|
let mut visited_paths = BTreeSet::new();
|
|
trie.walk(
|
|
&TriePath::new(rel_path("a/b/c/d/e/f/g")),
|
|
&mut |path, nodes| {
|
|
if path.as_unix_str() == "a/b/c" {
|
|
assert_eq!(visited_paths, BTreeSet::from_iter([rel_path("a").into()]));
|
|
assert_eq!(nodes.get(&()), Some(&LabelPresence::Present));
|
|
} else if path.as_unix_str() == "a" {
|
|
assert!(visited_paths.is_empty());
|
|
assert_eq!(nodes.get(&()), Some(&LabelPresence::KnownAbsent));
|
|
} else {
|
|
panic!("Unknown path");
|
|
}
|
|
// Assert that we only ever visit a path once.
|
|
assert!(visited_paths.insert(path.clone()));
|
|
ControlFlow::Continue(())
|
|
},
|
|
);
|
|
|
|
// Test breaking from the tree-walk.
|
|
let mut visited_paths = BTreeSet::new();
|
|
trie.walk(&TriePath::new(rel_path("a/b/c")), &mut |path, nodes| {
|
|
if path.as_unix_str() == "a" {
|
|
assert!(visited_paths.is_empty());
|
|
assert_eq!(nodes.get(&()), Some(&LabelPresence::KnownAbsent));
|
|
} else {
|
|
panic!("Unknown path");
|
|
}
|
|
// Assert that we only ever visit a path once.
|
|
assert!(visited_paths.insert(path.clone()));
|
|
ControlFlow::Break(())
|
|
});
|
|
assert_eq!(visited_paths.len(), 1);
|
|
|
|
// Entry removal.
|
|
trie.insert(
|
|
&TriePath::new(rel_path("a/b")),
|
|
(),
|
|
LabelPresence::KnownAbsent,
|
|
);
|
|
let mut visited_paths = BTreeSet::new();
|
|
trie.walk(&TriePath::new(rel_path("a/b/c")), &mut |path, _nodes| {
|
|
// Assert that we only ever visit a path once.
|
|
assert!(visited_paths.insert(path.clone()));
|
|
ControlFlow::Continue(())
|
|
});
|
|
assert_eq!(visited_paths.len(), 3);
|
|
trie.remove(&TriePath::new(rel_path("a/b")));
|
|
let mut visited_paths = BTreeSet::new();
|
|
trie.walk(&TriePath::new(rel_path("a/b/c")), &mut |path, _nodes| {
|
|
// Assert that we only ever visit a path once.
|
|
assert!(visited_paths.insert(path.clone()));
|
|
ControlFlow::Continue(())
|
|
});
|
|
assert_eq!(visited_paths.len(), 1);
|
|
assert_eq!(
|
|
visited_paths.into_iter().next().unwrap(),
|
|
rel_path("a").into()
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn path_to_a_root_can_contain_multiple_known_nodes() {
|
|
let mut trie = RootPathTrie::<()>::new();
|
|
trie.insert(&TriePath::new(rel_path("a/b")), (), LabelPresence::Present);
|
|
trie.insert(&TriePath::new(rel_path("a")), (), LabelPresence::Present);
|
|
let mut visited_paths = BTreeSet::new();
|
|
trie.walk(&TriePath::new(rel_path("a/b/c")), &mut |path, nodes| {
|
|
assert_eq!(nodes.get(&()), Some(&LabelPresence::Present));
|
|
if path.as_unix_str() != "a" && path.as_unix_str() != "a/b" {
|
|
panic!("Unexpected path: {}", path.as_unix_str());
|
|
}
|
|
assert!(visited_paths.insert(path.clone()));
|
|
ControlFlow::Continue(())
|
|
});
|
|
assert_eq!(visited_paths.len(), 2);
|
|
}
|
|
}
|