Skip to content

Commit

Permalink
ref: move pbxproj tests out of meta
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed Jun 12, 2022
1 parent 58b5e23 commit 0e5706a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 49 deletions.
49 changes: 0 additions & 49 deletions src/pbxproj/object/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,52 +86,3 @@ pub trait PBXObjectExt {
/// generate [`PBXHashMap`]
fn to_hashmap(&self) -> PBXHashMap;
}

#[cfg(test)]
macro_rules! get_objects {
($path:expr) => {{
use super::*;
use crate::pbxproj::pest::PBXProjectParser;
use std::collections::HashMap;

let file = PBXProjectParser::try_parse_from_file($path);
if file.is_err() {
println!("Error: {:#?}", file.as_ref().unwrap_err())
}
let ref_object = Rc::new(RefCell::new(Default::default()));

assert!(file.is_ok());
file.unwrap()
.try_remove_object("objects")
.unwrap()
.0
.into_iter()
.map(|(k, v)| (k, PBXObject::new(v, Rc::downgrade(&ref_object)).unwrap()))
.collect::<HashMap<_, _>>()
}};
}

#[cfg(test)]
mod parse_tests {
macro_rules! test_samples {
($($name:ident),*) => {
$(#[test]
fn $name() {
let (root, name) = (env!("CARGO_MANIFEST_DIR"), stringify!($name));
get_objects!(format!("{root}/tests/samples/{name}.pbxproj"));
})*
};
}

test_samples![demo1, demo2, demo3, demo4, demo5, demo6, demo7, demo8, demo9];

#[test]
fn test_object_creation() {
let objects = get_objects!(format!(
"{}/tests/samples/demo1.pbxproj",
env!("CARGO_MANIFEST_DIR")
));

println!("{objects:#?}")
}
}
29 changes: 29 additions & 0 deletions src/pbxproj/rep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,32 @@ fn test_parse() {
let project = PBXRootObject::try_from(test_content).unwrap();
println!("{project:#?}");
}

#[cfg(test)]
macro_rules! test_file {
($path:expr) => {{
use super::*;

let file = PBXRootObject::try_from(PathBuf::from($path));
if file.is_err() {
println!("Error: {:#?}", file.as_ref().unwrap_err())
}
assert!(file.is_ok());
file.unwrap()
}};
}

#[cfg(test)]
mod create_tests {
macro_rules! test_samples {
($($name:ident),*) => {
$(#[test]
fn $name() {
let (root, name) = (env!("CARGO_MANIFEST_DIR"), stringify!($name));
test_file!(format!("{root}/tests/samples/{name}.pbxproj"));
})*
};
}

test_samples![demo1, demo2, demo3, demo4, demo5, demo6, demo7, demo8, demo9];
}

0 comments on commit 0e5706a

Please sign in to comment.