#![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 assert_cmd::Command;
use predicates::prelude::*;
use std::fs;
use tempfile::TempDir;
fn ggen() -> Command {
Command::cargo_bin("ggen").expect("Failed to find ggen binary")
}
fn create_test_rdf(temp_dir: &TempDir) -> std::path::PathBuf {
let rdf_file = temp_dir.path().join("test.ttl");
let rdf_content = r#"
@prefix ex: <http://example.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
ex:Person a rdfs:Class ;
rdfs:label "Person" ;
rdfs:comment "A human being" .
ex:name a rdf:Property ;
rdfs:domain ex:Person ;
rdfs:range rdfs:Literal ;
rdfs:label "name" .
ex:age a rdf:Property ;
rdfs:domain ex:Person ;
rdfs:range rdfs:Literal ;
rdfs:label "age" .
ex:john a ex:Person ;
ex:name "John Doe" ;
ex:age "30" .
ex:jane a ex:Person ;
ex:name "Jane Smith" ;
ex:age "28" .
"#;
fs::write(&rdf_file, rdf_content).expect("Failed to write RDF file");
rdf_file
}
#[test]
#[ignore]
fn test_graph_load_turtle_format() {
let temp_dir = TempDir::new().unwrap();
let rdf_file = create_test_rdf(&temp_dir);
ggen()
.arg("graph")
.arg("load")
.arg(rdf_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success();
let _graph_path = temp_dir.path().join(".ggen/graph");
}
#[test]
#[ignore]
fn test_graph_load_invalid_format() {
let temp_dir = TempDir::new().unwrap();
let invalid_file = temp_dir.path().join("invalid.ttl");
fs::write(&invalid_file, "not valid RDF @!#$%").unwrap();
ggen()
.arg("graph")
.arg("load")
.arg(invalid_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.failure()
.stderr(predicate::str::contains("error").or(predicate::str::contains("invalid")));
}
#[test]
#[ignore]
fn test_graph_query_sparql_select() {
let temp_dir = TempDir::new().unwrap();
let rdf_file = create_test_rdf(&temp_dir);
ggen()
.arg("graph")
.arg("load")
.arg(rdf_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success();
let query = "SELECT ?person WHERE { ?person a <http://example.org/Person> }";
ggen()
.arg("graph")
.arg("query")
.arg(query)
.current_dir(&temp_dir)
.assert()
.success()
.stdout(predicate::str::contains("person").or(predicate::str::contains("result")));
}
#[test]
#[ignore]
fn test_graph_query_invalid_sparql() {
let temp_dir = TempDir::new().unwrap();
ggen()
.arg("graph")
.arg("query")
.arg("INVALID SPARQL SYNTAX")
.current_dir(&temp_dir)
.assert()
.failure()
.stderr(predicate::str::contains("error").or(predicate::str::contains("invalid")));
}
#[test]
#[ignore]
fn test_graph_export_turtle() {
let temp_dir = TempDir::new().unwrap();
let rdf_file = create_test_rdf(&temp_dir);
ggen()
.arg("graph")
.arg("load")
.arg(rdf_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success();
let export_file = temp_dir.path().join("export.ttl");
ggen()
.arg("graph")
.arg("export")
.arg(export_file.to_str().unwrap())
.arg("--format")
.arg("turtle")
.current_dir(&temp_dir)
.assert()
.success();
assert!(export_file.exists(), "Export file should be created");
let content = fs::read_to_string(&export_file).unwrap();
assert!(
content.contains("@prefix") || !content.is_empty(),
"Export should contain RDF data"
);
}
#[test]
#[ignore]
fn test_graph_validate_structure() {
let temp_dir = TempDir::new().unwrap();
let rdf_file = create_test_rdf(&temp_dir);
ggen()
.arg("graph")
.arg("load")
.arg(rdf_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success();
ggen()
.arg("graph")
.arg("validate")
.current_dir(&temp_dir)
.assert()
.success();
}
#[test]
#[ignore]
fn test_graph_stats_shows_metrics() {
let temp_dir = TempDir::new().unwrap();
let rdf_file = create_test_rdf(&temp_dir);
ggen()
.arg("graph")
.arg("load")
.arg(rdf_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success();
ggen()
.arg("graph")
.arg("stats")
.current_dir(&temp_dir)
.assert()
.success()
.stdout(
predicate::str::contains("triples")
.or(predicate::str::contains("subjects"))
.or(predicate::str::contains("stats")),
);
}
#[test]
#[ignore]
fn test_graph_snapshot_create() {
let temp_dir = TempDir::new().unwrap();
let rdf_file = create_test_rdf(&temp_dir);
ggen()
.arg("graph")
.arg("load")
.arg(rdf_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success();
ggen()
.arg("graph")
.arg("snapshot")
.arg("create")
.arg("v1.0")
.current_dir(&temp_dir)
.assert()
.success();
}
#[test]
#[ignore]
fn test_graph_snapshot_list() {
let temp_dir = TempDir::new().unwrap();
ggen()
.arg("graph")
.arg("snapshot")
.arg("list")
.current_dir(&temp_dir)
.assert()
.success()
.stdout(
predicate::str::contains("snapshot")
.or(predicate::str::contains("No snapshots"))
.or(predicate::str::contains("Snapshots")),
);
}
#[test]
#[ignore]
fn test_graph_diff_snapshots() {
let temp_dir = TempDir::new().unwrap();
let rdf_file = create_test_rdf(&temp_dir);
ggen()
.arg("graph")
.arg("load")
.arg(rdf_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success();
ggen()
.arg("graph")
.arg("snapshot")
.arg("create")
.arg("v1")
.current_dir(&temp_dir)
.assert()
.success();
let _ = ggen()
.arg("graph")
.arg("diff")
.arg("v1")
.arg("v1")
.current_dir(&temp_dir)
.output();
}
#[test]
#[ignore]
fn test_graph_help_output() {
ggen()
.arg("graph")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("RDF graph operations"))
.stdout(predicate::str::contains("load"))
.stdout(predicate::str::contains("query"))
.stdout(predicate::str::contains("export"));
}
#[test]
#[ignore]
fn test_graph_query_help() {
ggen()
.arg("graph")
.arg("query")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("SPARQL").or(predicate::str::contains("query")));
}
#[test]
#[ignore]
fn test_graph_invalid_verb() {
ggen()
.arg("graph")
.arg("invalid-verb")
.assert()
.failure()
.stderr(predicate::str::contains("error").or(predicate::str::contains("invalid")));
}
#[test]
#[ignore]
fn test_graph_load_missing_file() {
let temp_dir = TempDir::new().unwrap();
ggen()
.arg("graph")
.arg("load")
.arg("/nonexistent/file.ttl")
.current_dir(&temp_dir)
.assert()
.failure()
.stderr(predicate::str::contains("not found").or(predicate::str::contains("error")));
}
#[test]
#[ignore]
fn test_graph_export_missing_graph() {
let temp_dir = TempDir::new().unwrap();
let export_file = temp_dir.path().join("export.ttl");
let _ = ggen()
.arg("graph")
.arg("export")
.arg(export_file.to_str().unwrap())
.current_dir(&temp_dir)
.output();
}
#[test]
#[ignore]
fn test_graph_performance_large_query() {
let temp_dir = TempDir::new().unwrap();
let rdf_file = create_test_rdf(&temp_dir);
ggen()
.arg("graph")
.arg("load")
.arg(rdf_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success();
let start = std::time::Instant::now();
let query = r#"
SELECT ?person ?name ?age WHERE {
?person a <http://example.org/Person> .
?person <http://example.org/name> ?name .
?person <http://example.org/age> ?age .
}
"#;
ggen()
.arg("graph")
.arg("query")
.arg(query)
.current_dir(&temp_dir)
.assert()
.success();
let duration = start.elapsed();
assert!(
duration.as_secs() < 5,
"SPARQL query should be fast: {:?}",
duration
);
}