use super::{combine_patches, intersect_patches, parse_patch, ParsedPatch};
#[derive(Clone, Copy)]
struct PatchScenario {
incremental: &'static [&'static str],
post_commit: &'static str,
golden: &'static str,
}
fn parse_fixtures(fixtures: &[&str]) -> Vec<ParsedPatch> {
fixtures
.iter()
.map(|fixture| parse_patch(fixture, None).expect("fixture patch should parse"))
.collect()
}
const TEXT_FILE_LIFECYCLE_RECONSTRUCTION_INCREMENTALS: &[&str] = &[
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_01.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_02.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_03.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_04.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_05.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_06.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_07.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_08.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_09.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_10.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_11.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_12.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_13.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_14.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_15.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_16.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_17.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_18.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_19.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_20.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_21.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_22.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_23.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_24.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_25.patch"),
include_str!("fixtures/text_file_lifecycle_reconstruction/incremental_26.patch"),
];
fn assert_reconstructs_post_commit(scenario: PatchScenario) {
let combined = combine_patches(&parse_fixtures(scenario.incremental));
let post_commit = parse_patch(scenario.post_commit, None).expect("fixture patch should parse");
let golden: ParsedPatch =
serde_json::from_str(scenario.golden).expect("golden json should load");
assert_eq!(intersect_patches(&combined, &post_commit), golden);
}
#[test]
fn average_age_reconstruction_matches_post_commit() {
assert_reconstructs_post_commit(PatchScenario {
incremental: &[
include_str!("fixtures/average_age_reconstruction/incremental_01.patch"),
include_str!("fixtures/average_age_reconstruction/incremental_02.patch"),
include_str!("fixtures/average_age_reconstruction/incremental_03.patch"),
include_str!("fixtures/average_age_reconstruction/incremental_04.patch"),
include_str!("fixtures/average_age_reconstruction/incremental_05.patch"),
include_str!("fixtures/average_age_reconstruction/incremental_06.patch"),
include_str!("fixtures/average_age_reconstruction/incremental_07.patch"),
],
post_commit: include_str!("fixtures/average_age_reconstruction/post_commit.patch"),
golden: include_str!("fixtures/average_age_reconstruction/golden.json"),
});
}
#[test]
fn hello_world_reconstruction_matches_post_commit() {
assert_reconstructs_post_commit(PatchScenario {
incremental: &[include_str!(
"fixtures/hello_world_reconstruction/incremental_01.patch"
)],
post_commit: include_str!("fixtures/hello_world_reconstruction/post_commit.patch"),
golden: include_str!("fixtures/hello_world_reconstruction/golden.json"),
});
}
#[test]
fn text_file_lifecycle_reconstruction_matches_post_commit() {
assert_reconstructs_post_commit(PatchScenario {
incremental: TEXT_FILE_LIFECYCLE_RECONSTRUCTION_INCREMENTALS,
post_commit: include_str!("fixtures/text_file_lifecycle_reconstruction/post_commit.patch"),
golden: include_str!("fixtures/text_file_lifecycle_reconstruction/golden.json"),
});
}
#[test]
fn poem_write_reconstruction_matches_post_commit() {
assert_reconstructs_post_commit(PatchScenario {
incremental: &[include_str!(
"fixtures/poem_write_reconstruction/incremental_01.patch"
)],
post_commit: include_str!("fixtures/poem_write_reconstruction/post_commit.patch"),
golden: include_str!("fixtures/poem_write_reconstruction/golden.json"),
});
}
#[test]
fn poem_edit_reconstruction_matches_post_commit() {
assert_reconstructs_post_commit(PatchScenario {
incremental: &[
include_str!("fixtures/poem_edit_reconstruction/incremental_01.patch"),
include_str!("fixtures/poem_edit_reconstruction/incremental_02.patch"),
],
post_commit: include_str!("fixtures/poem_edit_reconstruction/post_commit.patch"),
golden: include_str!("fixtures/poem_edit_reconstruction/golden.json"),
});
}
#[test]
fn mixed_change_reconstruction_matches_post_commit() {
assert_reconstructs_post_commit(PatchScenario {
incremental: &[
include_str!("fixtures/mixed_change_reconstruction/incremental_01.patch"),
include_str!("fixtures/mixed_change_reconstruction/incremental_02.patch"),
include_str!("fixtures/mixed_change_reconstruction/incremental_03.patch"),
include_str!("fixtures/mixed_change_reconstruction/incremental_04.patch"),
],
post_commit: include_str!("fixtures/mixed_change_reconstruction/post_commit.patch"),
golden: include_str!("fixtures/mixed_change_reconstruction/golden.json"),
});
}
#[test]
fn line_and_file_deletion_reconstruction_matches_post_commit() {
assert_reconstructs_post_commit(PatchScenario {
incremental: &[
include_str!("fixtures/line_and_file_deletion_reconstruction/incremental_01.patch"),
include_str!("fixtures/line_and_file_deletion_reconstruction/incremental_02.patch"),
],
post_commit: include_str!(
"fixtures/line_and_file_deletion_reconstruction/post_commit.patch"
),
golden: include_str!("fixtures/line_and_file_deletion_reconstruction/golden.json"),
});
}
#[test]
fn file_rename_reconstruction_matches_post_commit() {
assert_reconstructs_post_commit(PatchScenario {
incremental: &[include_str!(
"fixtures/file_rename_reconstruction/incremental_01.patch"
)],
post_commit: include_str!("fixtures/file_rename_reconstruction/post_commit.patch"),
golden: include_str!("fixtures/file_rename_reconstruction/golden.json"),
});
}