use assert_cmd::Command;
use assert_fs::prelude::*;
use predicates::prelude::*;
use serde_json::Value;
#[test]
fn test_construct_create_with_nonexistent_file() {
let mut cmd = Command::cargo_bin("ggen").unwrap();
cmd.arg("construct")
.arg("create")
.arg("/nonexistent/spec.ttl");
cmd.assert()
.failure()
.stdout(predicate::str::contains("not found"))
.stdout(predicate::str::contains("error"));
}
#[test]
fn test_construct_create_with_non_ttl_file() {
let temp_dir = assert_fs::TempDir::new().unwrap();
let spec_file = temp_dir.child("spec.txt");
spec_file
.write_str("@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .")
.unwrap();
let mut cmd = Command::cargo_bin("ggen").unwrap();
cmd.arg("construct").arg("create").arg(spec_file.path());
cmd.assert()
.failure()
.stdout(predicate::str::contains("Turtle"))
.stdout(predicate::str::contains(".ttl"));
temp_dir.close().unwrap();
}
#[test]
fn test_construct_create_with_valid_ttl_file_returns_not_implemented() {
let temp_dir = assert_fs::TempDir::new().unwrap();
let spec_file = temp_dir.child("bond.ttl");
spec_file
.write_str(
r#"
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix fibo: <https://spec.edmcouncil.org/fibo/ontology/> .
fibo:Bond a owl:Class ;
rdfs:label "Bond" ;
rdfs:comment "A debt security" .
"#,
)
.unwrap();
let mut cmd = Command::cargo_bin("ggen").unwrap();
cmd.arg("construct").arg("create").arg(spec_file.path());
cmd.assert()
.success()
.stdout(predicate::str::contains("not_implemented"));
temp_dir.close().unwrap();
}
#[test]
fn test_construct_create_json_output_structure() {
let temp_dir = assert_fs::TempDir::new().unwrap();
let spec_file = temp_dir.child("test.ttl");
spec_file
.write_str(
r#"
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
"#,
)
.unwrap();
let mut cmd = Command::cargo_bin("ggen").unwrap();
cmd.arg("construct").arg("create").arg(spec_file.path());
let output = cmd.output().unwrap();
let stdout = String::from_utf8(output.stdout).unwrap();
let json: Value = serde_json::from_str(&stdout).unwrap();
assert!(json.get("status").is_some());
assert!(json.get("spec_path").is_some());
assert!(json.get("output_dir").is_some());
assert!(json.get("next_steps").is_some());
temp_dir.close().unwrap();
}
#[test]
fn test_construct_validate_returns_not_implemented() {
let mut cmd = Command::cargo_bin("ggen").unwrap();
cmd.arg("construct").arg("validate").arg("bond_extractor");
cmd.assert()
.success()
.stdout(predicate::str::contains("not_implemented"));
}
#[test]
fn test_construct_validate_json_output_structure() {
let mut cmd = Command::cargo_bin("ggen").unwrap();
cmd.arg("construct").arg("validate").arg("test_module");
let output = cmd.output().unwrap();
let stdout = String::from_utf8(output.stdout).unwrap();
let json: Value = serde_json::from_str(&stdout).unwrap();
assert!(json.get("status").is_some());
assert!(json.get("module_name").is_some());
assert_eq!(json["module_name"], "test_module");
assert!(json.get("next_steps").is_some());
}
#[test]
fn test_construct_create_with_custom_output_dir() {
let temp_dir = assert_fs::TempDir::new().unwrap();
let spec_file = temp_dir.child("spec.ttl");
spec_file
.write_str(
r#"
@prefix owl: <http://www.w3.org/2002/07/owl#> .
"#,
)
.unwrap();
let mut cmd = Command::cargo_bin("ggen").unwrap();
cmd.arg("construct")
.arg("create")
.arg(spec_file.path())
.arg("--output-dir")
.arg("custom/output");
cmd.assert()
.success()
.stdout(predicate::str::contains("custom/output"));
temp_dir.close().unwrap();
}
#[test]
fn test_to_snake_case_conversion() {
let temp_dir = assert_fs::TempDir::new().unwrap();
let spec_file = temp_dir.child("FIBOBond.ttl");
spec_file
.write_str(
r#"
@prefix owl: <http://www.w3.org/2002/07/owl#> .
"#,
)
.unwrap();
let mut cmd = Command::cargo_bin("ggen").unwrap();
cmd.arg("construct").arg("create").arg(spec_file.path());
cmd.assert().success();
temp_dir.close().unwrap();
}