#![allow(
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::needless_raw_string_hashes,
clippy::duration_suboptimal_units,
clippy::branches_sharing_code,
clippy::used_underscore_binding,
clippy::single_char_pattern,
clippy::ignore_without_reason,
clippy::cloned_ref_to_slice_refs,
clippy::doc_overindented_list_items,
clippy::match_wildcard_for_single_variants,
clippy::ignored_unit_patterns,
clippy::needless_collect,
clippy::unnecessary_map_or,
clippy::manual_flatten,
clippy::manual_strip,
clippy::future_not_send,
clippy::unnested_or_patterns,
clippy::no_effect_underscore_binding,
clippy::literal_string_with_formatting_args
)]
use std::path::PathBuf;
use ggen_core::domain::graph::{
ExportInput, ExportOutput, LoadInput, LoadOutput, QueryInput, QueryResult, RdfFormat,
VisualizeInput, VisualizeOutput,
};
#[cfg(test)]
mod load_tests {
use super::*;
#[test]
fn test_load_output_structure() {
let output = LoadOutput {
triples_loaded: 2,
total_triples: 8,
format: "Turtle".to_string(),
file_path: "test.ttl".to_string(),
};
assert_eq!(output.triples_loaded, 2);
assert_eq!(output.total_triples, 8);
assert_eq!(output.format, "Turtle");
assert_eq!(output.file_path, "test.ttl");
}
#[test]
fn test_load_input_creation() {
let input = LoadInput {
file: PathBuf::from("test.ttl"),
format: None,
base_iri: None,
merge: false,
};
assert_eq!(input.file, PathBuf::from("test.ttl"));
assert!(input.format.is_none());
assert!(input.base_iri.is_none());
assert!(!input.merge);
}
#[test]
fn test_load_input_with_format() {
let input = LoadInput {
file: PathBuf::from("data.nt"),
format: Some("ntriples".to_string()),
base_iri: Some("http://example.org/".to_string()),
merge: true,
};
assert_eq!(input.file, PathBuf::from("data.nt"));
assert_eq!(input.format, Some("ntriples".to_string()));
assert_eq!(input.base_iri, Some("http://example.org/".to_string()));
assert!(input.merge);
}
#[test]
fn test_rdf_format_turtle_detection() {
assert_eq!(RdfFormat::from_extension("data.ttl"), RdfFormat::Turtle);
assert_eq!(RdfFormat::from_extension("data.turtle"), RdfFormat::Turtle);
}
#[test]
fn test_rdf_format_ntriples_detection() {
assert_eq!(RdfFormat::from_extension("data.nt"), RdfFormat::NTriples);
assert_eq!(
RdfFormat::from_extension("data.ntriples"),
RdfFormat::NTriples
);
}
#[test]
fn test_rdf_format_rdfxml_detection() {
assert_eq!(RdfFormat::from_extension("data.rdf"), RdfFormat::RdfXml);
assert_eq!(RdfFormat::from_extension("data.xml"), RdfFormat::RdfXml);
}
#[test]
fn test_rdf_format_jsonld_detection() {
assert_eq!(RdfFormat::from_extension("data.jsonld"), RdfFormat::JsonLd);
assert_eq!(RdfFormat::from_extension("data.json"), RdfFormat::JsonLd);
}
#[test]
fn test_rdf_format_n3_detection() {
assert_eq!(RdfFormat::from_extension("data.n3"), RdfFormat::N3);
}
#[test]
fn test_rdf_format_unknown_extension() {
assert_eq!(RdfFormat::from_extension("data.unknown"), RdfFormat::Turtle);
assert_eq!(RdfFormat::from_extension("data"), RdfFormat::Turtle);
}
#[test]
fn test_rdf_format_as_str() {
assert_eq!(RdfFormat::Turtle.as_str(), "Turtle");
assert_eq!(RdfFormat::NTriples.as_str(), "N-Triples");
assert_eq!(RdfFormat::RdfXml.as_str(), "RDF/XML");
assert_eq!(RdfFormat::JsonLd.as_str(), "JSON-LD");
assert_eq!(RdfFormat::N3.as_str(), "N3");
}
}
#[cfg(test)]
mod query_tests {
use super::*;
use std::collections::HashMap;
#[test]
fn test_query_result_structure() {
let mut bindings = HashMap::new();
bindings.insert("name".to_string(), "Alice".to_string());
bindings.insert("age".to_string(), "30".to_string());
let result = QueryResult {
bindings: vec![bindings],
variables: vec!["name".to_string(), "age".to_string()],
result_count: 1,
};
assert_eq!(result.bindings.len(), 1);
assert_eq!(result.variables.len(), 2);
assert_eq!(result.result_count, 1);
}
#[test]
fn test_query_result_empty() {
let result = QueryResult {
bindings: vec![],
variables: vec![],
result_count: 0,
};
assert_eq!(result.bindings.len(), 0);
assert_eq!(result.variables.len(), 0);
assert_eq!(result.result_count, 0);
}
#[test]
fn test_query_result_multiple_bindings() {
let mut binding1 = HashMap::new();
binding1.insert("name".to_string(), "Alice".to_string());
let mut binding2 = HashMap::new();
binding2.insert("name".to_string(), "Bob".to_string());
let result = QueryResult {
bindings: vec![binding1, binding2],
variables: vec!["name".to_string()],
result_count: 2,
};
assert_eq!(result.bindings.len(), 2);
assert_eq!(result.result_count, 2);
}
#[test]
fn test_query_input_creation() {
let input = QueryInput {
query: "SELECT * WHERE { ?s ?p ?o }".to_string(),
graph_file: Some(PathBuf::from("graph.ttl")),
format: "json".to_string(),
};
assert_eq!(input.query, "SELECT * WHERE { ?s ?p ?o }");
assert_eq!(input.format, "json");
}
#[test]
fn test_query_input_no_graph() {
let input = QueryInput {
query: "ASK { ?s a :Class }".to_string(),
graph_file: None,
format: "json".to_string(),
};
assert!(input.graph_file.is_none());
}
}
#[cfg(test)]
mod export_tests {
use super::*;
#[test]
fn test_export_output_structure() {
let output = ExportOutput {
output_path: "/tmp/export.ttl".to_string(),
format: "Turtle".to_string(),
triples_exported: 100,
file_size_bytes: 5000,
};
assert_eq!(output.output_path, "/tmp/export.ttl");
assert_eq!(output.format, "Turtle");
assert_eq!(output.triples_exported, 100);
assert_eq!(output.file_size_bytes, 5000);
}
#[test]
fn test_export_output_empty() {
let output = ExportOutput {
output_path: "empty.ttl".to_string(),
format: "Turtle".to_string(),
triples_exported: 0,
file_size_bytes: 0,
};
assert_eq!(output.triples_exported, 0);
assert_eq!(output.file_size_bytes, 0);
}
#[test]
fn test_export_input_creation() {
let input = ExportInput {
input: PathBuf::from("input.ttl"),
output: PathBuf::from("output.ttl"),
format: "turtle".to_string(),
pretty: true,
};
assert_eq!(input.input, PathBuf::from("input.ttl"));
assert_eq!(input.output, PathBuf::from("output.ttl"));
assert!(input.pretty);
}
#[test]
fn test_export_input_not_pretty() {
let input = ExportInput {
input: PathBuf::from("in.ttl"),
output: PathBuf::from("out.ttl"),
format: "turtle".to_string(),
pretty: false,
};
assert!(!input.pretty);
}
}
#[cfg(test)]
mod visualize_tests {
use super::*;
#[test]
fn test_visualize_output_structure() {
let output = VisualizeOutput {
nodes_rendered: 5,
edges_rendered: 8,
output_path: "/tmp/graph.dot".to_string(),
format: "dot".to_string(),
};
assert_eq!(output.output_path, "/tmp/graph.dot");
assert_eq!(output.format, "dot");
assert_eq!(output.nodes_rendered, 5);
assert_eq!(output.edges_rendered, 8);
}
#[test]
fn test_visualize_output_empty_graph() {
let output = VisualizeOutput {
nodes_rendered: 0,
edges_rendered: 0,
output_path: "empty.dot".to_string(),
format: "dot".to_string(),
};
assert_eq!(output.nodes_rendered, 0);
assert_eq!(output.edges_rendered, 0);
}
#[test]
fn test_visualize_output_formats() {
for format in &["dot", "json", "svg", "png"] {
let output = VisualizeOutput {
nodes_rendered: 1,
edges_rendered: 0,
output_path: format!("graph.{}", format),
format: format.to_string(),
};
assert_eq!(output.format, *format);
}
}
#[test]
fn test_visualize_input_creation() {
let input = VisualizeInput {
input: PathBuf::from("graph.ttl"),
output: None,
format: "dot".to_string(),
labels: false,
max_depth: None,
subject: None,
};
assert_eq!(input.input, PathBuf::from("graph.ttl"));
assert_eq!(input.format, "dot");
assert!(!input.labels);
assert!(input.max_depth.is_none());
}
#[test]
fn test_visualize_input_full_options() {
let input = VisualizeInput {
input: PathBuf::from("graph.ttl"),
output: Some(PathBuf::from("viz.dot")),
format: "dot".to_string(),
labels: true,
max_depth: Some(5),
subject: Some("http://example.org/subject".to_string()),
};
assert_eq!(input.output, Some(PathBuf::from("viz.dot")));
assert!(input.labels);
assert_eq!(input.max_depth, Some(5));
assert_eq!(
input.subject,
Some("http://example.org/subject".to_string())
);
}
}
#[cfg(test)]
mod integration_tests {
use super::*;
#[test]
fn test_integration_load_input() {
let input = LoadInput {
file: PathBuf::from("test.ttl"),
format: None,
base_iri: None,
merge: false,
};
assert_eq!(input.file, PathBuf::from("test.ttl"));
assert!(!input.merge);
}
#[test]
fn test_integration_query_input() {
let input = QueryInput {
query: "SELECT * WHERE { ?s ?p ?o }".to_string(),
graph_file: Some(PathBuf::from("graph.ttl")),
format: "json".to_string(),
};
assert_eq!(input.query, "SELECT * WHERE { ?s ?p ?o }");
assert_eq!(input.format, "json");
}
#[test]
fn test_integration_export_input() {
let input = ExportInput {
input: PathBuf::from("input.ttl"),
output: PathBuf::from("output.ttl"),
format: "turtle".to_string(),
pretty: true,
};
assert_eq!(input.input, PathBuf::from("input.ttl"));
assert!(input.pretty);
}
#[test]
fn test_integration_visualize_input() {
let input = VisualizeInput {
input: PathBuf::from("graph.ttl"),
output: Some(PathBuf::from("viz.dot")),
format: "dot".to_string(),
labels: true,
max_depth: Some(5),
subject: Some("http://example.org/subject".to_string()),
};
assert_eq!(input.format, "dot");
assert!(input.labels);
assert_eq!(input.max_depth, Some(5));
}
}