Skip to content

Commit

Permalink
add serialize test
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 19, 2024
1 parent b09018d commit 6171d52
Show file tree
Hide file tree
Showing 2 changed files with 504 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tooling/cli/src/helpers/pbxproj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ impl Pbxproj {
!self.additions.is_empty() || self.has_changes
}

pub fn save(&self) -> std::io::Result<()> {
fn serialize(&self) -> String {
let mut proj = String::new();
let last_line_number = self.raw_lines.len() - 1;

for (number, line) in self.raw_lines.iter().enumerate() {
if let Some(new) = self.additions.get(&number) {
proj.push_str(new);
Expand All @@ -202,7 +203,11 @@ impl Pbxproj {
}
}

std::fs::write(&self.path, proj)
proj
}

pub fn save(&self) -> std::io::Result<()> {
std::fs::write(&self.path, self.serialize())
}

pub fn set_build_settings(&mut self, build_configuration_id: &str, key: &str, value: &str) {
Expand Down Expand Up @@ -287,4 +292,22 @@ mod tests {
super::parse(fixtures_path.join("project.pbxproj")).expect("failed to parse pbxproj")
);
}

#[test]
fn modify() {
let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
let fixtures_path = manifest_dir.join("tests").join("fixtures").join("pbxproj");

let mut settings = insta::Settings::clone_current();
settings.set_snapshot_path(fixtures_path.join("snapshots"));
let _guard = settings.bind_to_scope();

let mut pbxproj =
super::parse(fixtures_path.join("project.pbxproj")).expect("failed to parse pbxproj");

pbxproj.set_build_settings("DB0E254D0FD84970B57F6410", "PRODUCT_NAME", "\"Tauri Test\"");
pbxproj.set_build_settings("DB0E254D0FD84970B57F6410", "UNKNOWN", "9283j49238h");

insta::assert_snapshot!("project-modified.pbxproj", pbxproj.serialize());
}
}
Loading

0 comments on commit 6171d52

Please sign in to comment.