Skip to content

Commit

Permalink
Fix medium flag value
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Jun 18, 2024
1 parent 39f8752 commit fadd741
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 35 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push, pull_request]

env:
CARGO_TERM_COLOR: always
TESTING_PLUGINS_VERSION: "1.6.0"

jobs:
rustfmt:
Expand Down Expand Up @@ -33,9 +34,10 @@ jobs:

- name: Prepare test resources
run: |
(New-Object Net.WebClient).DownloadFile('https://github.com/WrinklyNinja/testing-plugins/archive/1.4.1.zip', "$PWD/1.4.1.zip")
7z x 1.4.1.zip
mv testing-plugins-1.4.1 testing-plugins
(New-Object Net.WebClient).DownloadFile('https://github.com/WrinklyNinja/testing-plugins/archive/$TESTING_PLUGINS_VERSION.zip', "$PWD/$TESTING_PLUGINS_VERSION.zip")
7z x $TESTING_PLUGINS_VERSION.zip
mv testing-plugins-$TESTING_PLUGINS_VERSION testing-plugins
- name: Build and run tests
run: cargo test --all --all-features

Expand Down Expand Up @@ -75,9 +77,9 @@ jobs:

- name: Prepare test resources
run: |
wget https://github.com/WrinklyNinja/testing-plugins/archive/1.4.1.tar.gz
tar -xf 1.4.1.tar.gz
mv testing-plugins-1.4.1 testing-plugins
wget https://github.com/WrinklyNinja/testing-plugins/archive/$TESTING_PLUGINS_VERSION.tar.gz
tar -xf $TESTING_PLUGINS_VERSION.tar.gz
mv testing-plugins-$TESTING_PLUGINS_VERSION testing-plugins
- name: Build and run tests with code coverage
run: cargo llvm-cov --workspace --lcov --output-path lcov.info
Expand Down
44 changes: 15 additions & 29 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl Plugin {

fn is_medium_flag_set(&self) -> bool {
let flag = match self.game_id {
GameId::Starfield => 0x10000,
GameId::Starfield => 0x400,
_ => return false,
};

Expand Down Expand Up @@ -1703,8 +1703,8 @@ mod tests {
fn is_master_file_should_use_file_extension_and_flag() {
use std::fs::copy;
copy(
Path::new("testing-plugins/Skyrim/Data/Blank.esm"),
Path::new("testing-plugins/Skyrim/Data/Blank.esm.esp"),
Path::new("testing-plugins/Starfield/Data/Blank.full.esm"),
Path::new("testing-plugins/Starfield/Data/Blank.full.esm.esp"),
)
.unwrap();

Expand All @@ -1719,14 +1719,14 @@ mod tests {

let mut plugin = Plugin::new(
GameId::Starfield,
Path::new("testing-plugins/Skyrim/Data/Blank.esp"),
Path::new("testing-plugins/Starfield/Data/Blank.esp"),
);
assert!(plugin.parse_file(true).is_ok());
assert!(!plugin.is_master_file());

let mut plugin = Plugin::new(
GameId::Starfield,
Path::new("testing-plugins/Skyrim/Data/Blank.esm.esp"),
Path::new("testing-plugins/Starfield/Data/Blank.full.esm.esp"),
);
assert!(plugin.parse_file(true).is_ok());
assert!(plugin.is_master_file());
Expand Down Expand Up @@ -1766,39 +1766,25 @@ mod tests {

#[test]
fn is_light_plugin_should_be_true_for_a_plugin_with_the_light_flag_set() {
let mut plugin = Plugin::new(GameId::Starfield, Path::new("Blank.esm"));
let file_data = &[
0x54, 0x45, 0x53, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xB2, 0x2E, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
];
plugin.data.header_record = Record::parse(file_data, GameId::Starfield, false)
.unwrap()
.1;

let mut plugin = Plugin::new(GameId::Starfield, Path::new("testing-plugins/Starfield/Data/Blank.small.esm"));
assert!(plugin.parse_file(true).is_ok());
assert!(plugin.is_light_plugin());
}

#[test]
fn is_medium_plugin_should_be_false_for_a_plugin_without_the_medium_flag_set() {
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esp"));
let plugin = Plugin::new(GameId::Starfield, Path::new("Blank.esp"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esm"));
let plugin = Plugin::new(GameId::Starfield, Path::new("Blank.esm"));
assert!(!plugin.is_medium_plugin());
let plugin = Plugin::new(GameId::Morrowind, Path::new("Blank.esl"));
let plugin = Plugin::new(GameId::Starfield, Path::new("Blank.esl"));
assert!(!plugin.is_medium_plugin());
}

#[test]
fn is_medium_plugin_should_be_true_for_a_plugin_with_the_medium_flag_set() {
let mut plugin = Plugin::new(GameId::Starfield, Path::new("Blank.esm"));
let file_data = &[
0x54, 0x45, 0x53, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0xB2, 0x2E, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
];
plugin.data.header_record = Record::parse(file_data, GameId::Starfield, false)
.unwrap()
.1;

let mut plugin = Plugin::new(GameId::Starfield, Path::new("testing-plugins/Starfield/Data/Blank.medium.esm"));
assert!(plugin.parse_file(true).is_ok());
assert!(plugin.is_medium_plugin());
}

Expand Down Expand Up @@ -1852,7 +1838,7 @@ mod tests {
fn valid_light_form_id_range_should_be_0_to_0xfff() {
let mut plugin = Plugin::new(
GameId::Starfield,
Path::new("testing-plugins/SkyrimSE/Data/Blank - Master Dependent.esm"),
Path::new("testing-plugins/Starfield/Data/Blank.small.esm"),
);
assert!(plugin.parse_file(false).is_ok());

Expand All @@ -1866,7 +1852,7 @@ mod tests {
) {
let mut plugin = Plugin::new(
GameId::Starfield,
Path::new("testing-plugins/SkyrimSE/Data/Blank - Master Dependent.esm"),
Path::new("testing-plugins/Starfield/Data/Blank.small.esm"),
);
assert!(plugin.parse_file(false).is_ok());

Expand All @@ -1888,7 +1874,7 @@ mod tests {
fn is_valid_as_override_plugin_should_be_false_if_the_plugin_has_new_records() {
let mut plugin = Plugin::new(
GameId::Starfield,
Path::new("testing-plugins/SkyrimSE/Data/Blank - Master Dependent.esm"),
Path::new("testing-plugins/Starfield/Data/Blank.full.esm"),
);
assert!(plugin.parse_file(false).is_ok());

Expand Down

0 comments on commit fadd741

Please sign in to comment.