Skip to content

Commit

Permalink
Updated morrowind plugin tests to also test for PluginMode::All
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwinger committed Apr 23, 2020
1 parent b1e0f08 commit 1c043ac
Showing 1 changed file with 136 additions and 116 deletions.
252 changes: 136 additions & 116 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,34 +692,38 @@ mod tests {

#[test]
fn parse_file_should_succeed() {
let mut plugin = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);
for mode in vec![ParseMode::RecordIds, ParseMode::All] {
let mut plugin = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);

assert!(plugin.parse_file(ParseMode::RecordIds).is_ok());
assert!(plugin.parse_file(mode).is_ok());

match plugin.data.record_ids {
RecordIds::NamespacedIds(ids) => assert_eq!(10, ids.len()),
_ => panic!("Expected namespaced record IDs"),
match plugin.data.record_ids {
RecordIds::NamespacedIds(ids) => assert_eq!(10, ids.len()),
_ => panic!("Expected namespaced record IDs"),
}
}
}

#[test]
fn plugin_parse_should_read_a_unique_id_for_each_record() {
let mut plugin = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);

assert!(plugin.parse_file(ParseMode::RecordIds).is_ok());

match plugin.data.record_ids {
RecordIds::NamespacedIds(ids) => {
let set: HashSet<NamespacedId> = HashSet::from_iter(ids.iter().cloned());
assert_eq!(set.len(), ids.len());
for mode in vec![ParseMode::RecordIds, ParseMode::All] {
let mut plugin = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);

assert!(plugin.parse_file(mode).is_ok());

match plugin.data.record_ids {
RecordIds::NamespacedIds(ids) => {
let set: HashSet<NamespacedId> = HashSet::from_iter(ids.iter().cloned());
assert_eq!(set.len(), ids.len());
}
_ => panic!("Expected namespaced record IDs"),
}
_ => panic!("Expected namespaced record IDs"),
}
}

Expand Down Expand Up @@ -836,136 +840,152 @@ mod tests {

#[test]
fn record_and_group_count_should_match_record_ids_length() {
let mut plugin = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);

assert!(plugin.record_and_group_count().is_none());
assert!(plugin.parse_file(ParseMode::RecordIds).is_ok());
assert_eq!(10, plugin.record_and_group_count().unwrap());
match plugin.data.record_ids {
RecordIds::NamespacedIds(ids) => assert_eq!(10, ids.len()),
_ => panic!("Expected namespaced record IDs"),
for mode in vec![ParseMode::RecordIds, ParseMode::All] {
let mut plugin = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);

assert!(plugin.record_and_group_count().is_none());
assert!(plugin.parse_file(mode).is_ok());
assert_eq!(10, plugin.record_and_group_count().unwrap());
match plugin.data.record_ids {
RecordIds::NamespacedIds(ids) => assert_eq!(10, ids.len()),
_ => panic!("Expected namespaced record IDs"),
}
}
}

#[test]
fn count_override_records_should_return_0_even_when_override_records_are_present() {
let mut plugin = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank - Master Dependent.esm"),
);

assert!(plugin.parse_file(ParseMode::RecordIds).is_ok());
assert_eq!(0, plugin.count_override_records());
for mode in vec![ParseMode::RecordIds, ParseMode::All] {
let mut plugin = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank - Master Dependent.esm"),
);

assert!(plugin.parse_file(mode).is_ok());
assert_eq!(0, plugin.count_override_records());
}
}

#[test]
fn overlaps_with_should_detect_when_two_plugins_have_a_record_with_the_same_id() {
let mut plugin1 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);
let mut plugin2 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank - Different.esm"),
);

assert!(plugin1.parse_file(ParseMode::RecordIds).is_ok());
assert!(plugin2.parse_file(ParseMode::RecordIds).is_ok());

assert!(plugin1.overlaps_with(&plugin1));
assert!(!plugin1.overlaps_with(&plugin2));
for mode in vec![ParseMode::RecordIds, ParseMode::All] {
let mut plugin1 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);
let mut plugin2 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank - Different.esm"),
);

assert!(plugin1.parse_file(mode).is_ok());
assert!(plugin2.parse_file(mode).is_ok());

assert!(plugin1.overlaps_with(&plugin1));
assert!(!plugin1.overlaps_with(&plugin2));
}
}

#[test]
fn overlap_size_should_only_count_each_record_once() {
let mut plugin1 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);
let mut plugin2 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank - Master Dependent.esm"),
);

assert!(plugin1.parse_file(ParseMode::RecordIds).is_ok());
assert!(plugin2.parse_file(ParseMode::RecordIds).is_ok());

assert_eq!(4, plugin1.overlap_size(&[&plugin2, &plugin2]));
for mode in vec![ParseMode::RecordIds, ParseMode::All] {
let mut plugin1 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);
let mut plugin2 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank - Master Dependent.esm"),
);

assert!(plugin1.parse_file(mode).is_ok());
assert!(plugin2.parse_file(mode).is_ok());

assert_eq!(4, plugin1.overlap_size(&[&plugin2, &plugin2]));
}
}

#[test]
fn overlap_size_should_check_against_all_given_plugins() {
let mut plugin1 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);
let mut plugin2 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esp"),
);
let mut plugin3 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank - Master Dependent.esm"),
);

assert!(plugin1.parse_file(ParseMode::RecordIds).is_ok());
assert!(plugin2.parse_file(ParseMode::RecordIds).is_ok());
assert!(plugin3.parse_file(ParseMode::RecordIds).is_ok());

assert_eq!(4, plugin1.overlap_size(&[&plugin2, &plugin3]));
for mode in vec![ParseMode::RecordIds, ParseMode::All] {
let mut plugin1 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);
let mut plugin2 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esp"),
);
let mut plugin3 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank - Master Dependent.esm"),
);

assert!(plugin1.parse_file(mode).is_ok());
assert!(plugin2.parse_file(mode).is_ok());
assert!(plugin3.parse_file(mode).is_ok());

assert_eq!(4, plugin1.overlap_size(&[&plugin2, &plugin3]));
}
}

#[test]
fn overlap_size_should_return_0_if_plugins_have_not_been_parsed() {
let mut plugin1 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);
let mut plugin2 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank - Master Dependent.esm"),
);
for mode in vec![ParseMode::RecordIds, ParseMode::All] {
let mut plugin1 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);
let mut plugin2 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank - Master Dependent.esm"),
);

assert_eq!(0, plugin1.overlap_size(&[&plugin2]));
assert_eq!(0, plugin1.overlap_size(&[&plugin2]));

assert!(plugin1.parse_file(ParseMode::RecordIds).is_ok());
assert!(plugin1.parse_file(mode).is_ok());

assert_eq!(0, plugin1.overlap_size(&[&plugin2]));
assert_eq!(0, plugin1.overlap_size(&[&plugin2]));

assert!(plugin2.parse_file(ParseMode::RecordIds).is_ok());
assert!(plugin2.parse_file(mode).is_ok());

assert_ne!(0, plugin1.overlap_size(&[&plugin2]));
assert_ne!(0, plugin1.overlap_size(&[&plugin2]));
}
}

#[test]
fn overlap_size_should_return_0_when_there_is_no_overlap() {
let mut plugin1 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);
let mut plugin2 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esp"),
);

assert!(plugin1.parse_file(ParseMode::RecordIds).is_ok());
assert!(plugin2.parse_file(ParseMode::RecordIds).is_ok());

assert!(!plugin1.overlaps_with(&plugin2));
assert_eq!(0, plugin1.overlap_size(&[&plugin2]));
for mode in vec![ParseMode::RecordIds, ParseMode::All] {
let mut plugin1 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esm"),
);
let mut plugin2 = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank.esp"),
);

assert!(plugin1.parse_file(mode).is_ok());
assert!(plugin2.parse_file(mode).is_ok());

assert!(!plugin1.overlaps_with(&plugin2));
assert_eq!(0, plugin1.overlap_size(&[&plugin2]));
}
}

#[test]
fn is_valid_as_light_master_should_always_be_false() {
let mut plugin = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank - Master Dependent.esm"),
);
assert!(plugin.parse_file(ParseMode::RecordIds).is_ok());
assert!(!plugin.is_valid_as_light_master());
for mode in vec![ParseMode::RecordIds, ParseMode::All] {
let mut plugin = Plugin::new(
GameId::Morrowind,
Path::new("testing-plugins/Morrowind/Data Files/Blank - Master Dependent.esm"),
);
assert!(plugin.parse_file(mode).is_ok());
assert!(!plugin.is_valid_as_light_master());
}
}
}

Expand Down

0 comments on commit 1c043ac

Please sign in to comment.