From 1c043ac640eb45a5552301a1e376831e89c00746 Mon Sep 17 00:00:00 2001 From: Benjamin Winger Date: Thu, 23 Apr 2020 14:55:20 -0400 Subject: [PATCH] Updated morrowind plugin tests to also test for PluginMode::All --- src/plugin.rs | 252 +++++++++++++++++++++++++++----------------------- 1 file changed, 136 insertions(+), 116 deletions(-) diff --git a/src/plugin.rs b/src/plugin.rs index 9d62143..ccf4c36 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -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 = 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 = HashSet::from_iter(ids.iter().cloned()); + assert_eq!(set.len(), ids.len()); + } + _ => panic!("Expected namespaced record IDs"), } - _ => panic!("Expected namespaced record IDs"), } } @@ -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()); + } } }