mirror of
https://github.com/ModernRelay/omnigraph.git
synced 2026-06-27 02:39:38 +02:00
Extract remaining crowded compiler test modules
Files where inline tests crowded out production code (test/prod ratio ≥ 0.8) move to sibling files via `#[path]`. Files where production dominates (query_input.rs, schema_plan.rs) stay inline — extracting would add noise, not reduce it. - ir/lower.rs: 1239 → 577 lines (ratio 1.15) - catalog/mod.rs: 594 → 326 lines (ratio 0.83) - query/lint.rs: 562 → 314 lines (ratio 0.80) catalog/tests.rs uses the shorter name since it's inside a module directory (no ambiguity with filename). All 229 compiler tests green, identical count to before. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f2c3b11508
commit
54101f7e2c
6 changed files with 1184 additions and 1184 deletions
|
|
@ -322,273 +322,5 @@ pub fn build_catalog(schema: &SchemaFile) -> Result<Catalog> {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::schema::ast::{EdgeDecl, NodeDecl};
|
||||
use crate::schema::parser::parse_schema;
|
||||
use crate::types::PropType;
|
||||
|
||||
fn test_schema() -> &'static str {
|
||||
r#"
|
||||
node Person {
|
||||
name: String
|
||||
age: I32?
|
||||
}
|
||||
node Company {
|
||||
name: String
|
||||
}
|
||||
edge Knows: Person -> Person {
|
||||
since: Date?
|
||||
}
|
||||
edge WorksAt: Person -> Company {
|
||||
title: String?
|
||||
}
|
||||
"#
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_catalog() {
|
||||
let schema = parse_schema(test_schema()).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
assert_eq!(catalog.node_types.len(), 2);
|
||||
assert_eq!(catalog.edge_types.len(), 2);
|
||||
assert!(catalog.node_types.contains_key("Person"));
|
||||
assert!(catalog.node_types.contains_key("Company"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edge_lookup() {
|
||||
let schema = parse_schema(test_schema()).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let edge = catalog.lookup_edge_by_name("knows").unwrap();
|
||||
assert_eq!(edge.from_type, "Person");
|
||||
assert_eq!(edge.to_type, "Person");
|
||||
let upper = catalog.lookup_edge_by_name("KNOWS").unwrap();
|
||||
assert_eq!(upper.name, "Knows");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_node_arrow_schema() {
|
||||
let schema = parse_schema(test_schema()).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let person = &catalog.node_types["Person"];
|
||||
assert_eq!(person.arrow_schema.fields().len(), 3); // id, name, age
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duplicate_node_error() {
|
||||
let input = r#"
|
||||
node Person { name: String }
|
||||
node Person { age: I32 }
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
assert!(build_catalog(&schema).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bad_edge_endpoint() {
|
||||
let input = r#"
|
||||
node Person { name: String }
|
||||
edge Knows: Person -> Alien
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
assert!(build_catalog(&schema).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_id_fields_are_utf8() {
|
||||
let schema = parse_schema(test_schema()).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let person = &catalog.node_types["Person"];
|
||||
assert_eq!(
|
||||
person
|
||||
.arrow_schema
|
||||
.field_with_name("id")
|
||||
.unwrap()
|
||||
.data_type(),
|
||||
&DataType::Utf8
|
||||
);
|
||||
let knows = &catalog.edge_types["Knows"];
|
||||
assert_eq!(
|
||||
knows
|
||||
.arrow_schema
|
||||
.field_with_name("id")
|
||||
.unwrap()
|
||||
.data_type(),
|
||||
&DataType::Utf8
|
||||
);
|
||||
assert_eq!(
|
||||
knows
|
||||
.arrow_schema
|
||||
.field_with_name("src")
|
||||
.unwrap()
|
||||
.data_type(),
|
||||
&DataType::Utf8
|
||||
);
|
||||
assert_eq!(
|
||||
knows
|
||||
.arrow_schema
|
||||
.field_with_name("dst")
|
||||
.unwrap()
|
||||
.data_type(),
|
||||
&DataType::Utf8
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_key_property_tracking() {
|
||||
let input = r#"
|
||||
node Signal {
|
||||
slug: String @key
|
||||
title: String
|
||||
}
|
||||
node Person {
|
||||
name: String
|
||||
}
|
||||
edge Emits: Person -> Signal
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
assert_eq!(catalog.node_types["Signal"].key_property(), Some("slug"));
|
||||
assert_eq!(catalog.node_types["Person"].key_property(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edge_lookup_handles_non_ascii_leading_character() {
|
||||
let schema = SchemaFile {
|
||||
declarations: vec![
|
||||
SchemaDecl::Node(NodeDecl {
|
||||
name: "Person".to_string(),
|
||||
annotations: vec![],
|
||||
implements: vec![],
|
||||
properties: vec![crate::schema::ast::PropDecl {
|
||||
name: "name".to_string(),
|
||||
prop_type: PropType::scalar(ScalarType::String, false),
|
||||
annotations: vec![],
|
||||
}],
|
||||
constraints: vec![],
|
||||
}),
|
||||
SchemaDecl::Edge(EdgeDecl {
|
||||
name: "Édges".to_string(),
|
||||
from_type: "Person".to_string(),
|
||||
to_type: "Person".to_string(),
|
||||
cardinality: Default::default(),
|
||||
annotations: vec![],
|
||||
properties: vec![],
|
||||
constraints: vec![],
|
||||
}),
|
||||
],
|
||||
};
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
assert!(catalog.lookup_edge_by_name("édges").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edge_lookup_rejects_case_fold_collisions() {
|
||||
let input = r#"
|
||||
node Person { name: String }
|
||||
edge Knows: Person -> Person
|
||||
edge KNOWS: Person -> Person
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let err = build_catalog(&schema).unwrap_err();
|
||||
assert!(err.to_string().contains("case folding"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_catalog_composite_unique() {
|
||||
let input = r#"
|
||||
node Person {
|
||||
first: String
|
||||
last: String
|
||||
@unique(first, last)
|
||||
}
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let person = &catalog.node_types["Person"];
|
||||
assert!(
|
||||
person
|
||||
.unique_constraints
|
||||
.contains(&vec!["first".to_string(), "last".to_string()])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_catalog_composite_index() {
|
||||
let input = r#"
|
||||
node Event {
|
||||
category: String
|
||||
date: Date
|
||||
@index(category, date)
|
||||
}
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let event = &catalog.node_types["Event"];
|
||||
assert!(
|
||||
event
|
||||
.indices
|
||||
.contains(&vec!["category".to_string(), "date".to_string()])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_catalog_edge_cardinality() {
|
||||
let input = r#"
|
||||
node Person { name: String }
|
||||
node Company { name: String }
|
||||
edge WorksAt: Person -> Company @card(0..1)
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let edge = &catalog.edge_types["WorksAt"];
|
||||
assert_eq!(edge.cardinality.min, 0);
|
||||
assert_eq!(edge.cardinality.max, Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_catalog_interfaces_stored() {
|
||||
let input = r#"
|
||||
interface Named {
|
||||
name: String
|
||||
}
|
||||
node Person implements Named {
|
||||
age: I32?
|
||||
}
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
assert!(catalog.interfaces.contains_key("Named"));
|
||||
assert!(catalog.interfaces["Named"].properties.contains_key("name"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_catalog_node_implements() {
|
||||
let input = r#"
|
||||
interface Named {
|
||||
name: String
|
||||
}
|
||||
node Person implements Named {
|
||||
age: I32?
|
||||
}
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
assert_eq!(catalog.node_types["Person"].implements, vec!["Named"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_key_implies_index() {
|
||||
let input = r#"
|
||||
node Signal {
|
||||
slug: String @key
|
||||
title: String
|
||||
}
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let signal = &catalog.node_types["Signal"];
|
||||
assert!(signal.indices.contains(&vec!["slug".to_string()]));
|
||||
}
|
||||
}
|
||||
#[path = "tests.rs"]
|
||||
mod tests;
|
||||
|
|
|
|||
268
crates/omnigraph-compiler/src/catalog/tests.rs
Normal file
268
crates/omnigraph-compiler/src/catalog/tests.rs
Normal file
|
|
@ -0,0 +1,268 @@
|
|||
use super::*;
|
||||
use crate::schema::ast::{EdgeDecl, NodeDecl};
|
||||
use crate::schema::parser::parse_schema;
|
||||
use crate::types::PropType;
|
||||
|
||||
fn test_schema() -> &'static str {
|
||||
r#"
|
||||
node Person {
|
||||
name: String
|
||||
age: I32?
|
||||
}
|
||||
node Company {
|
||||
name: String
|
||||
}
|
||||
edge Knows: Person -> Person {
|
||||
since: Date?
|
||||
}
|
||||
edge WorksAt: Person -> Company {
|
||||
title: String?
|
||||
}
|
||||
"#
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_catalog() {
|
||||
let schema = parse_schema(test_schema()).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
assert_eq!(catalog.node_types.len(), 2);
|
||||
assert_eq!(catalog.edge_types.len(), 2);
|
||||
assert!(catalog.node_types.contains_key("Person"));
|
||||
assert!(catalog.node_types.contains_key("Company"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edge_lookup() {
|
||||
let schema = parse_schema(test_schema()).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let edge = catalog.lookup_edge_by_name("knows").unwrap();
|
||||
assert_eq!(edge.from_type, "Person");
|
||||
assert_eq!(edge.to_type, "Person");
|
||||
let upper = catalog.lookup_edge_by_name("KNOWS").unwrap();
|
||||
assert_eq!(upper.name, "Knows");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_node_arrow_schema() {
|
||||
let schema = parse_schema(test_schema()).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let person = &catalog.node_types["Person"];
|
||||
assert_eq!(person.arrow_schema.fields().len(), 3); // id, name, age
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duplicate_node_error() {
|
||||
let input = r#"
|
||||
node Person { name: String }
|
||||
node Person { age: I32 }
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
assert!(build_catalog(&schema).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bad_edge_endpoint() {
|
||||
let input = r#"
|
||||
node Person { name: String }
|
||||
edge Knows: Person -> Alien
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
assert!(build_catalog(&schema).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_id_fields_are_utf8() {
|
||||
let schema = parse_schema(test_schema()).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let person = &catalog.node_types["Person"];
|
||||
assert_eq!(
|
||||
person
|
||||
.arrow_schema
|
||||
.field_with_name("id")
|
||||
.unwrap()
|
||||
.data_type(),
|
||||
&DataType::Utf8
|
||||
);
|
||||
let knows = &catalog.edge_types["Knows"];
|
||||
assert_eq!(
|
||||
knows
|
||||
.arrow_schema
|
||||
.field_with_name("id")
|
||||
.unwrap()
|
||||
.data_type(),
|
||||
&DataType::Utf8
|
||||
);
|
||||
assert_eq!(
|
||||
knows
|
||||
.arrow_schema
|
||||
.field_with_name("src")
|
||||
.unwrap()
|
||||
.data_type(),
|
||||
&DataType::Utf8
|
||||
);
|
||||
assert_eq!(
|
||||
knows
|
||||
.arrow_schema
|
||||
.field_with_name("dst")
|
||||
.unwrap()
|
||||
.data_type(),
|
||||
&DataType::Utf8
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_key_property_tracking() {
|
||||
let input = r#"
|
||||
node Signal {
|
||||
slug: String @key
|
||||
title: String
|
||||
}
|
||||
node Person {
|
||||
name: String
|
||||
}
|
||||
edge Emits: Person -> Signal
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
assert_eq!(catalog.node_types["Signal"].key_property(), Some("slug"));
|
||||
assert_eq!(catalog.node_types["Person"].key_property(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edge_lookup_handles_non_ascii_leading_character() {
|
||||
let schema = SchemaFile {
|
||||
declarations: vec![
|
||||
SchemaDecl::Node(NodeDecl {
|
||||
name: "Person".to_string(),
|
||||
annotations: vec![],
|
||||
implements: vec![],
|
||||
properties: vec![crate::schema::ast::PropDecl {
|
||||
name: "name".to_string(),
|
||||
prop_type: PropType::scalar(ScalarType::String, false),
|
||||
annotations: vec![],
|
||||
}],
|
||||
constraints: vec![],
|
||||
}),
|
||||
SchemaDecl::Edge(EdgeDecl {
|
||||
name: "Édges".to_string(),
|
||||
from_type: "Person".to_string(),
|
||||
to_type: "Person".to_string(),
|
||||
cardinality: Default::default(),
|
||||
annotations: vec![],
|
||||
properties: vec![],
|
||||
constraints: vec![],
|
||||
}),
|
||||
],
|
||||
};
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
assert!(catalog.lookup_edge_by_name("édges").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_edge_lookup_rejects_case_fold_collisions() {
|
||||
let input = r#"
|
||||
node Person { name: String }
|
||||
edge Knows: Person -> Person
|
||||
edge KNOWS: Person -> Person
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let err = build_catalog(&schema).unwrap_err();
|
||||
assert!(err.to_string().contains("case folding"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_catalog_composite_unique() {
|
||||
let input = r#"
|
||||
node Person {
|
||||
first: String
|
||||
last: String
|
||||
@unique(first, last)
|
||||
}
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let person = &catalog.node_types["Person"];
|
||||
assert!(
|
||||
person
|
||||
.unique_constraints
|
||||
.contains(&vec!["first".to_string(), "last".to_string()])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_catalog_composite_index() {
|
||||
let input = r#"
|
||||
node Event {
|
||||
category: String
|
||||
date: Date
|
||||
@index(category, date)
|
||||
}
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let event = &catalog.node_types["Event"];
|
||||
assert!(
|
||||
event
|
||||
.indices
|
||||
.contains(&vec!["category".to_string(), "date".to_string()])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_catalog_edge_cardinality() {
|
||||
let input = r#"
|
||||
node Person { name: String }
|
||||
node Company { name: String }
|
||||
edge WorksAt: Person -> Company @card(0..1)
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let edge = &catalog.edge_types["WorksAt"];
|
||||
assert_eq!(edge.cardinality.min, 0);
|
||||
assert_eq!(edge.cardinality.max, Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_catalog_interfaces_stored() {
|
||||
let input = r#"
|
||||
interface Named {
|
||||
name: String
|
||||
}
|
||||
node Person implements Named {
|
||||
age: I32?
|
||||
}
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
assert!(catalog.interfaces.contains_key("Named"));
|
||||
assert!(catalog.interfaces["Named"].properties.contains_key("name"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_catalog_node_implements() {
|
||||
let input = r#"
|
||||
interface Named {
|
||||
name: String
|
||||
}
|
||||
node Person implements Named {
|
||||
age: I32?
|
||||
}
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
assert_eq!(catalog.node_types["Person"].implements, vec!["Named"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_key_implies_index() {
|
||||
let input = r#"
|
||||
node Signal {
|
||||
slug: String @key
|
||||
title: String
|
||||
}
|
||||
"#;
|
||||
let schema = parse_schema(input).unwrap();
|
||||
let catalog = build_catalog(&schema).unwrap();
|
||||
let signal = &catalog.node_types["Signal"];
|
||||
assert!(signal.indices.contains(&vec!["slug".to_string()]));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue