feat: add rendering-primitives crate, share non_import_rels across renderers
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
use archlens_domain::{
|
||||
FilePath, Relationship, RelationshipKind,
|
||||
};
|
||||
use archlens_rendering_primitives::{non_import_rels, sanitize_identifier};
|
||||
|
||||
fn rel(src: &str, tgt: &str, kind: RelationshipKind) -> Relationship {
|
||||
Relationship::new(src, tgt, kind).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_import_rels_excludes_import_relationships() {
|
||||
let rels = vec![
|
||||
rel("A", "B", RelationshipKind::Composition),
|
||||
rel("C", "D", RelationshipKind::Import),
|
||||
rel("E", "F", RelationshipKind::Inheritance),
|
||||
];
|
||||
let filtered: Vec<_> = non_import_rels(&rels).collect();
|
||||
assert_eq!(filtered.len(), 2);
|
||||
assert!(filtered.iter().all(|r| r.kind() != RelationshipKind::Import));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_import_rels_passes_all_non_import_kinds() {
|
||||
let rels = vec![
|
||||
rel("A", "B", RelationshipKind::Composition),
|
||||
rel("C", "D", RelationshipKind::Inheritance),
|
||||
];
|
||||
let filtered: Vec<_> = non_import_rels(&rels).collect();
|
||||
assert_eq!(filtered.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sanitize_identifier_replaces_double_colon_with_underscore() {
|
||||
assert_eq!(sanitize_identifier("foo::bar"), "foo_bar");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sanitize_identifier_replaces_hyphen_with_underscore() {
|
||||
assert_eq!(sanitize_identifier("my-crate"), "my_crate");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sanitize_identifier_replaces_dot_with_underscore() {
|
||||
assert_eq!(sanitize_identifier("v1.2"), "v1_2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sanitize_identifier_replaces_space_with_underscore() {
|
||||
assert_eq!(sanitize_identifier("my crate"), "my_crate");
|
||||
}
|
||||
Reference in New Issue
Block a user