init: archlens — architecture diagram generator
Some checks failed
CI / Check / Test (push) Failing after 1m24s
Some checks failed
CI / Check / Test (push) Failing after 1m24s
Hex arch + DDD, tree-sitter parsing, Mermaid/ASCII output. Supports Rust + Python. 92 tests. CI, diff, --check for staleness detection.
This commit is contained in:
107
crates/domain/tests/code_element_tests.rs
Normal file
107
crates/domain/tests/code_element_tests.rs
Normal file
@@ -0,0 +1,107 @@
|
||||
use archlens_domain::{CodeElement, CodeElementKind, FilePath, ModuleName, Visibility};
|
||||
|
||||
#[test]
|
||||
fn code_element_is_created_with_required_fields() {
|
||||
let element = CodeElement::new(
|
||||
"OrderService",
|
||||
CodeElementKind::Class,
|
||||
FilePath::new("src/orders/service.rs").unwrap(),
|
||||
42,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(element.name(), "OrderService");
|
||||
assert_eq!(element.kind(), CodeElementKind::Class);
|
||||
assert_eq!(element.file_path().as_str(), "src/orders/service.rs");
|
||||
assert_eq!(element.line(), 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_element_with_empty_name_is_rejected() {
|
||||
let result = CodeElement::new(
|
||||
"",
|
||||
CodeElementKind::Class,
|
||||
FilePath::new("src/main.rs").unwrap(),
|
||||
1,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_element_defaults_to_public_visibility() {
|
||||
let element = CodeElement::new(
|
||||
"Order",
|
||||
CodeElementKind::Struct,
|
||||
FilePath::new("src/order.rs").unwrap(),
|
||||
1,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(element.visibility(), Visibility::Public);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_element_with_visibility() {
|
||||
let element = CodeElement::new(
|
||||
"Order",
|
||||
CodeElementKind::Struct,
|
||||
FilePath::new("src/order.rs").unwrap(),
|
||||
1,
|
||||
)
|
||||
.unwrap()
|
||||
.with_visibility(Visibility::Private);
|
||||
|
||||
assert_eq!(element.visibility(), Visibility::Private);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_element_with_module_path() {
|
||||
let module = ModuleName::new("Orders").unwrap();
|
||||
let element = CodeElement::new(
|
||||
"Order",
|
||||
CodeElementKind::Struct,
|
||||
FilePath::new("src/orders/order.rs").unwrap(),
|
||||
1,
|
||||
)
|
||||
.unwrap()
|
||||
.with_module(module.clone());
|
||||
|
||||
assert_eq!(element.module(), Some(&module));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_element_with_generics() {
|
||||
let element = CodeElement::new(
|
||||
"Repository",
|
||||
CodeElementKind::Trait,
|
||||
FilePath::new("src/repo.rs").unwrap(),
|
||||
1,
|
||||
)
|
||||
.unwrap()
|
||||
.with_generics(vec!["T".to_string()]);
|
||||
|
||||
assert_eq!(element.generics(), &["T"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_element_with_attributes() {
|
||||
let element = CodeElement::new(
|
||||
"OrderController",
|
||||
CodeElementKind::Class,
|
||||
FilePath::new("src/controller.cs").unwrap(),
|
||||
1,
|
||||
)
|
||||
.unwrap()
|
||||
.with_attributes(vec!["ApiController".to_string()]);
|
||||
|
||||
assert_eq!(element.attributes(), &["ApiController"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_element_kinds_exist() {
|
||||
let _class = CodeElementKind::Class;
|
||||
let _struct = CodeElementKind::Struct;
|
||||
let _trait = CodeElementKind::Trait;
|
||||
let _interface = CodeElementKind::Interface;
|
||||
let _enum = CodeElementKind::Enum;
|
||||
}
|
||||
Reference in New Issue
Block a user