#[cfg(not(target_family = "wasm"))]
use rudof_generate::GeneratorConfig;
#[cfg(not(target_family = "wasm"))]
use std::io::Write;
#[cfg(not(target_family = "wasm"))]
use tempfile::NamedTempFile;
#[cfg(not(target_family = "wasm"))]
#[tokio::test]
async fn test_basic_generator_creation() {
let output_file = NamedTempFile::new().unwrap();
let mut config = GeneratorConfig::default();
config.generation.entity_count = 3;
config.output.path = output_file.path().to_path_buf();
let generator = rudof_generate::DataGenerator::new(config);
assert!(generator.is_ok(), "Should be able to create a DataGenerator");
}
#[cfg(not(target_family = "wasm"))]
#[tokio::test]
async fn test_shex_schema_loading() {
let shex_schema = r#"
PREFIX ex: <http://example.org/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
ex:PersonShape {
ex:name xsd:string
}
"#;
let mut schema_file = NamedTempFile::new().unwrap();
writeln!(schema_file, "{shex_schema}").unwrap();
let output_file = NamedTempFile::new().unwrap();
let mut config = GeneratorConfig::default();
config.generation.entity_count = 2;
config.output.path = output_file.path().to_path_buf();
let mut generator = rudof_generate::DataGenerator::new(config).unwrap();
let result = generator.load_shex_schema(schema_file.path()).await;
assert!(result.is_ok(), "Should be able to load ShEx schema");
}
#[cfg(not(target_family = "wasm"))]
#[tokio::test]
async fn test_shacl_schema_loading() {
let shacl_schema = r#"
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix ex: <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:PersonShape a sh:NodeShape ;
sh:targetClass ex:Person ;
sh:property [
sh:path ex:name ;
sh:datatype xsd:string ;
sh:minCount 1 ;
sh:maxCount 1 ;
] .
"#;
let mut schema_file = NamedTempFile::new().unwrap();
writeln!(schema_file, "{shacl_schema}").unwrap();
let output_file = NamedTempFile::new().unwrap();
let mut config = GeneratorConfig::default();
config.generation.entity_count = 2;
config.output.path = output_file.path().to_path_buf();
let mut generator = rudof_generate::DataGenerator::new(config).unwrap();
let result = generator.load_shacl_schema(schema_file.path()).await;
assert!(result.is_ok(), "Should be able to load SHACL schema");
}
#[cfg(not(target_family = "wasm"))]
#[tokio::test]
async fn test_data_generation_produces_output() {
let shacl_schema = r#"
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix ex: <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:PersonShape a sh:NodeShape ;
sh:targetClass ex:Person ;
sh:property [
sh:path ex:name ;
sh:datatype xsd:string ;
sh:minCount 1 ;
sh:maxCount 1 ;
] .
"#;
let mut schema_file = NamedTempFile::new().unwrap();
writeln!(schema_file, "{shacl_schema}").unwrap();
let output_file = NamedTempFile::new().unwrap();
let mut config = GeneratorConfig::default();
config.generation.entity_count = 2;
config.output.path = output_file.path().to_path_buf();
let mut generator = rudof_generate::DataGenerator::new(config).unwrap();
generator.load_shacl_schema(schema_file.path()).await.unwrap();
generator.load_shacl_schema(schema_file.path()).await.unwrap();
let result = generator.generate().await;
assert!(result.is_ok(), "Should be able to generate data");
assert!(output_file.path().exists(), "Output file should exist");
let content = std::fs::read_to_string(output_file.path()).unwrap();
assert!(!content.is_empty(), "Output file should have content");
}