84 lines
2.6 KiB
Plaintext
84 lines
2.6 KiB
Plaintext
//! Integration test for GUID resolution with .meta files
|
|
|
|
use cursebreaker_parser::parser::meta::{get_meta_path, MetaFile};
|
|
use cursebreaker_parser::UnityProject;
|
|
use std::path::Path;
|
|
|
|
#[test]
|
|
fn test_meta_file_parsing() {
|
|
// Test parsing a .meta file directly
|
|
let meta_content = r#"
|
|
fileFormatVersion: 2
|
|
guid: 4ab6bfb0ff54cdf4c8dd38ca244d6f15
|
|
PrefabImporter:
|
|
externalObjects: {}
|
|
userData:
|
|
assetBundleName:
|
|
assetBundleVariant:
|
|
"#;
|
|
|
|
let meta = MetaFile::from_str(meta_content).unwrap();
|
|
assert_eq!(meta.guid(), "4ab6bfb0ff54cdf4c8dd38ca244d6f15");
|
|
assert_eq!(meta.file_format_version(), Some(2));
|
|
}
|
|
|
|
#[test]
|
|
fn test_meta_path_generation() {
|
|
let asset_path = Path::new("Assets/Prefabs/Player.prefab");
|
|
let meta_path = get_meta_path(asset_path);
|
|
|
|
assert_eq!(
|
|
meta_path,
|
|
Path::new("Assets/Prefabs/Player.prefab.meta")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_guid_resolution_in_project() {
|
|
let mut project = UnityProject::new(100);
|
|
let test_dir = "data/tests/unity-sampleproject/PiratePanic/Assets/PiratePanic/Prefabs/Menu/Battle/Hand";
|
|
|
|
if Path::new(test_dir).exists() {
|
|
// Load all files in the directory
|
|
let loaded_files = project.load_directory(test_dir).unwrap();
|
|
|
|
if !loaded_files.is_empty() {
|
|
println!("Loaded {} files", loaded_files.len());
|
|
println!(
|
|
"Found {} GUID mappings",
|
|
project.guid_mappings().len()
|
|
);
|
|
|
|
// If we have GUID mappings, test that we can look them up
|
|
for (guid, path) in project.guid_mappings() {
|
|
let found_path = project.get_path_by_guid(guid);
|
|
assert_eq!(found_path, Some(path));
|
|
println!("GUID {} -> {:?}", guid, path);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_cross_file_reference_resolution() {
|
|
let mut project = UnityProject::new(100);
|
|
let test_dir = "data/tests/unity-sampleproject/PiratePanic/Assets/PiratePanic";
|
|
|
|
if Path::new(test_dir).exists() {
|
|
// Load multiple directories to enable cross-file resolution
|
|
let _ = project.load_directory(test_dir);
|
|
|
|
let guid_count = project.guid_mappings().len();
|
|
let file_count = project.files().len();
|
|
|
|
println!("Loaded {} files with {} GUID mappings", file_count, guid_count);
|
|
|
|
// Verify we can look up files by GUID
|
|
if guid_count > 0 {
|
|
let sample_guid = project.guid_mappings().keys().next().unwrap();
|
|
let path = project.get_path_by_guid(sample_guid);
|
|
assert!(path.is_some(), "Should be able to look up GUID");
|
|
}
|
|
}
|
|
}
|