1use crate::graph::NodeId;
23use std::collections::HashMap;
24use std::path::{Path, PathBuf};
25
26#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct SymbolEntry {
29 pub id: NodeId,
30 pub file: PathBuf,
31}
32
33#[derive(Debug, Clone, PartialEq, Eq)]
38pub enum Resolution {
39 Exact(NodeId),
41 SameFile(NodeId),
43 UniqueSuffix(NodeId),
45 ViaImport(NodeId),
51 SameDir(NodeId),
53 Ambiguous(Vec<NodeId>),
55 Unresolved,
57}
58
59impl Resolution {
60 pub fn confidence(&self) -> f32 {
66 match self {
67 Resolution::Exact(_) => 1.0,
68 Resolution::SameFile(_) => 0.95,
69 Resolution::UniqueSuffix(_) => 0.80,
70 Resolution::ViaImport(_) => 0.93,
71 Resolution::SameDir(_) => 0.55,
72 Resolution::Ambiguous(_) => 0.25,
73 Resolution::Unresolved => 0.0,
74 }
75 }
76
77 pub fn node(&self) -> Option<NodeId> {
79 match self {
80 Resolution::Exact(id)
81 | Resolution::SameFile(id)
82 | Resolution::UniqueSuffix(id)
83 | Resolution::ViaImport(id)
84 | Resolution::SameDir(id) => Some(*id),
85 Resolution::Ambiguous(_) | Resolution::Unresolved => None,
86 }
87 }
88
89 pub fn candidates(&self) -> Vec<NodeId> {
91 match self {
92 Resolution::Ambiguous(ids) => ids.clone(),
93 other => other.node().into_iter().collect(),
94 }
95 }
96
97 pub fn is_resolved(&self) -> bool {
98 !matches!(self, Resolution::Unresolved)
99 }
100}
101
102#[derive(Debug, Default, Clone)]
104pub struct SymbolTable {
105 by_fqn: HashMap<String, Vec<SymbolEntry>>,
107
108 by_suffix: HashMap<String, Vec<String>>,
114
115 exports_by_file: HashMap<PathBuf, Vec<String>>,
117}
118
119impl SymbolTable {
120 pub fn new() -> Self {
121 Self::default()
122 }
123
124 pub fn insert(&mut self, fqn: String, id: NodeId, file: PathBuf) {
128 let entry = SymbolEntry {
129 id,
130 file: file.clone(),
131 };
132
133 let entries = self.by_fqn.entry(fqn.clone()).or_default();
134 if !entries.contains(&entry) {
137 entries.push(entry);
138 }
139
140 for suffix in segment_suffixes(&fqn) {
141 let fqns = self.by_suffix.entry(suffix.to_string()).or_default();
142 if !fqns.iter().any(|f| f == &fqn) {
143 fqns.push(fqn.clone());
144 }
145 }
146
147 let exports = self.exports_by_file.entry(file).or_default();
148 if !exports.contains(&fqn) {
149 exports.push(fqn);
150 }
151 }
152
153 pub fn resolve(&self, fqn: &str) -> Option<NodeId> {
158 match self.by_fqn.get(fqn) {
159 Some(entries) if entries.len() == 1 => Some(entries[0].id),
160 _ => None,
161 }
162 }
163
164 pub fn resolve_all(&self, fqn: &str) -> Vec<NodeId> {
166 let Some(entries) = self.by_fqn.get(fqn) else {
167 return Vec::new();
168 };
169 let mut entries: Vec<&SymbolEntry> = entries.iter().collect();
170 sort_entries(&mut entries);
171 entries.into_iter().map(|e| e.id).collect()
172 }
173
174 pub fn get_file_exports(&self, file: &PathBuf) -> Option<&Vec<String>> {
176 self.exports_by_file.get(file)
177 }
178
179 pub fn clear(&mut self) {
180 self.by_fqn.clear();
181 self.by_suffix.clear();
182 self.exports_by_file.clear();
183 }
184
185 pub fn resolve_ref(&self, name: &str, context_file: &Path) -> Resolution {
196 self.resolve_ref_with_imports(name, context_file, None)
197 }
198
199 pub fn resolve_ref_with_imports(
219 &self,
220 name: &str,
221 context_file: &Path,
222 imports: Option<&HashMap<String, String>>,
223 ) -> Resolution {
224 let family = language_family(context_file);
228 let visible = |e: &SymbolEntry| same_family(family, &e.file);
229
230 let exact: Option<Vec<&SymbolEntry>> = self
231 .by_fqn
232 .get(name)
233 .map(|entries| entries.iter().filter(|e| visible(e)).collect::<Vec<_>>())
234 .filter(|entries| !entries.is_empty());
235 if let Some(entries) = &exact {
236 if entries.len() == 1 {
237 return Resolution::Exact(entries[0].id);
238 }
239 }
240 let had_exact = exact.is_some();
241
242 let mut candidates: Vec<&SymbolEntry> = Vec::new();
243 let mut seen: Vec<NodeId> = Vec::new();
244
245 if let Some(entries) = exact {
246 for e in entries {
247 if !seen.contains(&e.id) {
248 seen.push(e.id);
249 candidates.push(e);
250 }
251 }
252 }
253
254 if let Some(fqns) = self.by_suffix.get(name) {
255 let mut fqns: Vec<&String> = fqns.iter().collect();
258 fqns.sort();
259 for fqn in fqns {
260 if let Some(entries) = self.by_fqn.get(fqn) {
261 for e in entries {
262 if visible(e) && !seen.contains(&e.id) {
263 seen.push(e.id);
264 candidates.push(e);
265 }
266 }
267 }
268 }
269 }
270
271 if candidates.is_empty() {
272 return Resolution::Unresolved;
273 }
274
275 sort_entries(&mut candidates);
276
277 if candidates.len() == 1 {
278 return if had_exact {
279 Resolution::Exact(candidates[0].id)
280 } else {
281 Resolution::UniqueSuffix(candidates[0].id)
282 };
283 }
284
285 let same_file: Vec<&SymbolEntry> = candidates
286 .iter()
287 .copied()
288 .filter(|e| e.file == context_file)
289 .collect();
290 if same_file.len() == 1 {
291 return Resolution::SameFile(same_file[0].id);
292 }
293
294 if let Some(map) = imports {
301 if let Some(source_module) = map.get(name) {
302 let wanted = normalize_module_path(source_module);
303 if !wanted.is_empty() {
304 let from_import: Vec<&SymbolEntry> = candidates
305 .iter()
306 .copied()
307 .filter(|e| entry_belongs_to_module(e, &wanted))
308 .collect();
309 if from_import.len() == 1 {
310 return Resolution::ViaImport(from_import[0].id);
311 }
312 }
313 }
314 }
315
316 let context_dir = context_file.parent();
317 let same_dir: Vec<&SymbolEntry> = candidates
318 .iter()
319 .copied()
320 .filter(|e| e.file.parent() == context_dir)
321 .collect();
322 if same_dir.len() == 1 {
323 return Resolution::SameDir(same_dir[0].id);
324 }
325
326 Resolution::Ambiguous(candidates.into_iter().map(|e| e.id).collect())
327 }
328
329 pub fn resolve_path(&self, path: &str, context_file: &Path) -> Resolution {
347 let family = language_family(context_file);
348 let visible = |e: &&SymbolEntry| same_family(family, &e.file);
349
350 let verbatim = self.entries_with_suffix(path, &visible);
351 if !verbatim.is_empty() {
352 return pick(verbatim, context_file, Resolution::Exact);
353 }
354
355 let segments: Vec<&str> = path
356 .split("::")
357 .map(str::trim)
358 .filter(|s| !s.is_empty() && !matches!(*s, "crate" | "self" | "super"))
359 .collect();
360 let Some((name, qualifiers)) = segments.split_last() else {
361 return Resolution::Unresolved;
362 };
363 let Some(owner) = qualifiers.last() else {
364 return self.resolve_ref(name, context_file);
365 };
366
367 if owner.starts_with(|c: char| c.is_uppercase()) {
368 let mut entries = self.entries_with_suffix(&format!("{owner}.{name}"), &visible);
369 entries.extend(self.entries_with_suffix(&format!("{owner}::{name}"), &visible));
370 return pick(entries, context_file, Resolution::Exact);
372 }
373
374 let named: Vec<&SymbolEntry> = self
376 .by_fqn
377 .get(*name)
378 .into_iter()
379 .flatten()
380 .filter(|e| visible(e))
381 .collect();
382 for start in 0..qualifiers.len() {
383 let wanted = normalize_module_path(&qualifiers[start..].join("."));
384 if wanted.is_empty() {
385 continue;
386 }
387 let in_module: Vec<&SymbolEntry> = named
388 .iter()
389 .copied()
390 .filter(|e| module_is(e, &wanted))
391 .collect();
392 if !in_module.is_empty() {
393 return pick(in_module, context_file, Resolution::ViaImport);
394 }
395 let re_exported: Vec<&SymbolEntry> = named
396 .iter()
397 .copied()
398 .filter(|e| entry_belongs_to_module(e, &wanted))
399 .collect();
400 if !re_exported.is_empty() {
401 return pick(re_exported, context_file, Resolution::UniqueSuffix);
402 }
403 }
404 Resolution::Unresolved
405 }
406
407 fn entries_with_suffix(
409 &self,
410 fqn: &str,
411 visible: &dyn Fn(&&SymbolEntry) -> bool,
412 ) -> Vec<&SymbolEntry> {
413 let mut fqns: Vec<&String> = self.by_suffix.get(fqn).into_iter().flatten().collect();
414 fqns.sort();
415 fqns.into_iter()
416 .filter_map(|f| self.by_fqn.get(f))
417 .flatten()
418 .filter(|e| visible(e))
419 .collect()
420 }
421
422 pub fn resolve_with_context(&self, name: &str, context_file: &Path) -> Option<NodeId> {
424 self.resolve_ref(name, context_file).node()
425 }
426
427 pub fn len(&self) -> usize {
429 self.by_fqn.len()
430 }
431
432 pub fn is_empty(&self) -> bool {
433 self.by_fqn.is_empty()
434 }
435}
436
437fn normalize_module_path(raw: &str) -> String {
443 let cleaned = raw.replace("::", ".").replace(['/', '\\'], ".");
444 let cleaned = cleaned
445 .trim_start_matches('.')
446 .trim_end_matches(".py")
447 .trim_end_matches(".ts")
448 .trim_end_matches(".js")
449 .trim_end_matches(".rs")
450 .trim_end_matches(".go");
451 cleaned
452 .split('.')
453 .filter(|seg| {
454 !seg.is_empty()
455 && *seg != "index"
456 && *seg != "mod"
457 && *seg != "crate"
458 && *seg != "self"
459 && *seg != "super"
460 })
461 .collect::<Vec<_>>()
462 .join(".")
463}
464
465fn pick(
468 mut entries: Vec<&SymbolEntry>,
469 context_file: &Path,
470 unique: fn(NodeId) -> Resolution,
471) -> Resolution {
472 sort_entries(&mut entries);
473 entries.dedup_by_key(|e| e.id);
474 match entries.as_slice() {
475 [] => Resolution::Unresolved,
476 [only] => unique(only.id),
477 _ => {
478 let same_file: Vec<&&SymbolEntry> =
479 entries.iter().filter(|e| e.file == context_file).collect();
480 if same_file.len() == 1 {
481 return Resolution::SameFile(same_file[0].id);
482 }
483 let dir = context_file.parent();
484 let same_dir: Vec<&&SymbolEntry> =
485 entries.iter().filter(|e| e.file.parent() == dir).collect();
486 if same_dir.len() == 1 {
487 return Resolution::SameDir(same_dir[0].id);
488 }
489 Resolution::Ambiguous(entries.into_iter().map(|e| e.id).collect())
490 }
491 }
492}
493
494fn module_is(entry: &SymbolEntry, module: &str) -> bool {
496 let file_norm = normalize_module_path(&entry.file.to_string_lossy());
497 file_norm == module || file_norm.ends_with(&format!(".{module}"))
498}
499
500fn language_family(path: &Path) -> Option<&'static str> {
504 let ext = path.extension()?.to_str()?.to_ascii_lowercase();
505 Some(match ext.as_str() {
506 "rs" => "rust",
507 "ts" | "tsx" | "mts" | "cts" | "js" | "jsx" | "mjs" | "cjs" | "vue" | "svelte" => "js",
508 "py" | "pyi" => "python",
509 "go" => "go",
510 "java" | "kt" | "kts" | "scala" => "jvm",
511 "c" | "h" | "cc" | "cpp" | "cxx" | "hh" | "hpp" | "hxx" | "m" | "mm" => "c",
512 "cs" => "csharp",
513 "rb" => "ruby",
514 "php" | "phtml" => "php",
515 "swift" => "swift",
516 "dart" => "dart",
517 "sh" | "bash" | "zsh" => "shell",
518 _ => return None,
519 })
520}
521
522pub(crate) fn same_language(a: &Path, b: &Path) -> bool {
526 same_family(language_family(a), b)
527}
528
529fn same_family(family: Option<&'static str>, file: &Path) -> bool {
530 match (family, language_family(file)) {
531 (Some(a), Some(b)) => a == b,
532 _ => true,
533 }
534}
535
536fn entry_belongs_to_module(entry: &SymbolEntry, module: &str) -> bool {
542 let file_norm = normalize_module_path(&entry.file.to_string_lossy());
543 segment_aligned_contains(&file_norm, module)
544}
545
546fn segment_aligned_contains(haystack: &str, needle: &str) -> bool {
548 if haystack == needle {
549 return true;
550 }
551 haystack.starts_with(&format!("{needle}."))
552 || haystack.ends_with(&format!(".{needle}"))
553 || haystack.contains(&format!(".{needle}."))
554}
555
556fn sort_entries(entries: &mut [&SymbolEntry]) {
558 entries.sort_by(|a, b| {
559 a.file
560 .cmp(&b.file)
561 .then_with(|| a.id.index().cmp(&b.id.index()))
562 });
563}
564
565fn segment_suffixes(fqn: &str) -> Vec<&str> {
573 let mut out = vec![fqn];
574 let bytes = fqn.as_bytes();
575
576 for (i, c) in fqn.char_indices().skip(1) {
577 if c == '.' || c == ':' {
578 continue;
579 }
580 let prev = bytes[i - 1];
584 if prev == b'.' || prev == b':' {
585 out.push(&fqn[i..]);
586 }
587 }
588
589 out
590}
591
592#[cfg(test)]
593mod tests {
594 use super::*;
595
596 fn nid(n: usize) -> NodeId {
597 petgraph::graph::NodeIndex::new(n)
598 }
599
600 #[test]
601 fn insert_resolve() {
602 let mut table = SymbolTable::new();
603 let path = PathBuf::from("main.rs");
604 table.insert("main::foo".to_string(), nid(1), path.clone());
605
606 assert_eq!(table.resolve("main::foo"), Some(nid(1)));
607 assert_eq!(table.resolve("main::bar"), None);
608 assert_eq!(table.get_file_exports(&path).unwrap(), &vec!["main::foo"]);
609 }
610
611 #[test]
612 fn exact_match_from_any_context() {
613 let mut table = SymbolTable::new();
614 table.insert(
615 "pkg.utils.helper".to_string(),
616 nid(1),
617 PathBuf::from("src/utils.rs"),
618 );
619
620 let r = table.resolve_ref("pkg.utils.helper", Path::new("other/file.rs"));
621 assert_eq!(r, Resolution::Exact(nid(1)));
622 assert_eq!(r.confidence(), 1.0);
623 }
624
625 #[test]
626 fn unique_suffix_match() {
627 let mut table = SymbolTable::new();
628 table.insert(
629 "pkg.utils.helper".to_string(),
630 nid(1),
631 PathBuf::from("src/utils.rs"),
632 );
633
634 let r = table.resolve_ref("helper", Path::new("other/file.rs"));
635 assert_eq!(r, Resolution::UniqueSuffix(nid(1)));
636 }
637
638 #[test]
639 fn multi_segment_suffix_match() {
640 let mut table = SymbolTable::new();
641 table.insert(
642 "pkg.Utils.helper".to_string(),
643 nid(1),
644 PathBuf::from("src/utils.rs"),
645 );
646
647 let r = table.resolve_ref("Utils.helper", Path::new("other/file.rs"));
648 assert_eq!(r, Resolution::UniqueSuffix(nid(1)));
649 }
650
651 #[test]
652 fn suffix_must_be_segment_aligned() {
653 let mut table = SymbolTable::new();
654 table.insert(
655 "pkg.my_helper".to_string(),
656 nid(1),
657 PathBuf::from("src/utils.rs"),
658 );
659
660 assert_eq!(
662 table.resolve_ref("helper", Path::new("other/file.rs")),
663 Resolution::Unresolved
664 );
665 }
666
667 #[test]
668 fn ambiguous_reports_all_candidates() {
669 let mut table = SymbolTable::new();
670 table.insert(
671 "pkg.a.helper".to_string(),
672 nid(1),
673 PathBuf::from("src/a/mod.rs"),
674 );
675 table.insert(
676 "pkg.b.helper".to_string(),
677 nid(2),
678 PathBuf::from("src/b/mod.rs"),
679 );
680
681 let r = table.resolve_ref("helper", Path::new("src/c/caller.rs"));
682 assert_eq!(r, Resolution::Ambiguous(vec![nid(1), nid(2)]));
683 assert!(r.node().is_none());
684 assert_eq!(r.candidates().len(), 2);
685 }
686
687 #[test]
688 fn locality_preference_same_dir() {
689 let mut table = SymbolTable::new();
690 table.insert(
691 "pkg.a.helper".to_string(),
692 nid(1),
693 PathBuf::from("src/a/mod.rs"),
694 );
695 table.insert(
696 "pkg.b.helper".to_string(),
697 nid(2),
698 PathBuf::from("src/b/mod.rs"),
699 );
700
701 assert_eq!(
702 table.resolve_ref("helper", Path::new("src/a/caller.rs")),
703 Resolution::SameDir(nid(1))
704 );
705 assert_eq!(
706 table.resolve_ref("helper", Path::new("src/b/caller.rs")),
707 Resolution::SameDir(nid(2))
708 );
709 }
710
711 #[test]
712 fn same_file_beats_same_dir() {
713 let mut table = SymbolTable::new();
714 table.insert("A.run".to_string(), nid(1), PathBuf::from("src/a.rs"));
715 table.insert("B.run".to_string(), nid(2), PathBuf::from("src/b.rs"));
716
717 assert_eq!(
719 table.resolve_ref("run", Path::new("src/a.rs")),
720 Resolution::SameFile(nid(1))
721 );
722 }
723
724 #[test]
725 fn colliding_fqn_keeps_both_definitions() {
726 let mut table = SymbolTable::new();
727 table.insert("process".to_string(), nid(1), PathBuf::from("src/utils.py"));
728 table.insert(
729 "process".to_string(),
730 nid(2),
731 PathBuf::from("src/helpers.py"),
732 );
733
734 assert_eq!(table.resolve_all("process"), vec![nid(2), nid(1)]);
736 assert_eq!(
737 table.resolve("process"),
738 None,
739 "collision is not unambiguous"
740 );
741
742 let r = table.resolve_ref("process", Path::new("src/other.py"));
743 assert_eq!(r, Resolution::Ambiguous(vec![nid(2), nid(1)]));
744 }
745
746 #[test]
747 fn duplicate_insert_is_idempotent() {
748 let mut table = SymbolTable::new();
749 table.insert("a.b".to_string(), nid(1), PathBuf::from("x.rs"));
750 table.insert("a.b".to_string(), nid(1), PathBuf::from("x.rs"));
751
752 assert_eq!(table.resolve_all("a.b"), vec![nid(1)]);
753 assert_eq!(
754 table
755 .get_file_exports(&PathBuf::from("x.rs"))
756 .unwrap()
757 .len(),
758 1
759 );
760 }
761
762 #[test]
763 fn resolution_confidence_is_ordered() {
764 assert!(Resolution::Exact(nid(0)).confidence() > Resolution::SameFile(nid(0)).confidence());
765 assert!(
766 Resolution::SameFile(nid(0)).confidence()
767 > Resolution::UniqueSuffix(nid(0)).confidence()
768 );
769 assert!(
770 Resolution::UniqueSuffix(nid(0)).confidence()
771 > Resolution::SameDir(nid(0)).confidence()
772 );
773 assert!(
774 Resolution::SameDir(nid(0)).confidence() > Resolution::Ambiguous(vec![]).confidence()
775 );
776 assert_eq!(Resolution::Unresolved.confidence(), 0.0);
777 }
778
779 #[test]
780 fn resolution_is_order_independent() {
781 let mut a = SymbolTable::new();
783 a.insert("p.x.run".into(), nid(1), PathBuf::from("src/x/mod.rs"));
784 a.insert("p.y.run".into(), nid(2), PathBuf::from("src/y/mod.rs"));
785 a.insert("p.z.run".into(), nid(3), PathBuf::from("src/z/mod.rs"));
786
787 let mut b = SymbolTable::new();
788 b.insert("p.z.run".into(), nid(3), PathBuf::from("src/z/mod.rs"));
789 b.insert("p.y.run".into(), nid(2), PathBuf::from("src/y/mod.rs"));
790 b.insert("p.x.run".into(), nid(1), PathBuf::from("src/x/mod.rs"));
791
792 let ctx = Path::new("src/other/caller.rs");
793 assert_eq!(a.resolve_ref("run", ctx), b.resolve_ref("run", ctx));
794 }
795
796 #[test]
797 fn segment_suffixes_shapes() {
798 assert_eq!(segment_suffixes("a.b.c"), vec!["a.b.c", "b.c", "c"]);
799 assert_eq!(segment_suffixes("a::b::c"), vec!["a::b::c", "b::c", "c"]);
800 assert_eq!(segment_suffixes("solo"), vec!["solo"]);
801 }
802
803 #[test]
804 fn unicode_fqn_does_not_panic() {
805 let mut table = SymbolTable::new();
806 table.insert("módulo.función".to_string(), nid(1), PathBuf::from("a.py"));
807 assert_eq!(
808 table.resolve_ref("función", Path::new("b.py")),
809 Resolution::UniqueSuffix(nid(1))
810 );
811 }
812}
813
814#[cfg(test)]
815mod import_resolution_tests {
816 use super::*;
817
818 fn nid(i: usize) -> NodeId {
819 NodeId::new(i)
820 }
821
822 #[test]
825 fn import_breaks_a_tie_that_would_otherwise_be_ambiguous() {
826 let mut table = SymbolTable::default();
827 for layer in 0usize..10 {
828 table.insert(
829 format!("deep.l{layer}.m14.value_m14"),
830 nid(layer),
831 PathBuf::from(format!("/repo/deep/l{layer}/m14.py")),
832 );
833 }
834
835 let caller = Path::new("/repo/deep/l1/m03.py");
836
837 let bare = table.resolve_ref("value_m14", caller);
844 assert_eq!(
845 bare,
846 Resolution::SameDir(nid(1)),
847 "expected the same-directory sibling to be mis-picked, got {bare:?}"
848 );
849
850 let mut imports = HashMap::new();
852 imports.insert("value_m14".to_string(), "deep.l0.m14".to_string());
853 let resolved = table.resolve_ref_with_imports("value_m14", caller, Some(&imports));
854
855 match resolved {
856 Resolution::ViaImport(id) => {
857 assert_eq!(id, nid(0), "resolved to the wrong layer");
858 }
859 other => panic!("expected ViaImport(l0), got {other:?}"),
860 }
861 }
862
863 #[test]
865 fn local_definition_still_shadows_an_import() {
866 let mut table = SymbolTable::default();
867 table.insert(
868 "a.mod.process".to_string(),
869 nid(0),
870 PathBuf::from("/repo/a/mod.py"),
871 );
872 table.insert(
873 "b.other.process".to_string(),
874 nid(1),
875 PathBuf::from("/repo/b/other.py"),
876 );
877
878 let caller = Path::new("/repo/a/mod.py");
879 let mut imports = HashMap::new();
880 imports.insert("process".to_string(), "b.other".to_string());
881
882 let r = table.resolve_ref_with_imports("process", caller, Some(&imports));
883 assert!(
884 matches!(r, Resolution::SameFile(_)),
885 "a local definition must win over an import, got {r:?}"
886 );
887 }
888
889 #[test]
890 fn module_paths_normalize_across_separator_styles() {
891 assert_eq!(normalize_module_path("deep/l0/m14.py"), "deep.l0.m14");
892 assert_eq!(normalize_module_path("crate::deep::l0::m14"), "deep.l0.m14");
893 assert_eq!(normalize_module_path("./deep/l0/m14"), "deep.l0.m14");
894 }
895
896 #[test]
898 fn module_matching_is_segment_aligned() {
899 assert!(segment_aligned_contains("x.deep.l0.m14", "deep.l0.m14"));
900 assert!(!segment_aligned_contains("x.deep.l0.m140", "deep.l0.m14"));
901 assert!(!segment_aligned_contains("x.deep.l0.m1", "deep.l0.m14"));
902 }
903}