Add operation configuration types: resize, convert, compress, metadata, watermark, rename
All 11 operation tests passing.
This commit is contained in:
111
pixstrip-core/tests/operations_tests.rs
Normal file
111
pixstrip-core/tests/operations_tests.rs
Normal file
@@ -0,0 +1,111 @@
|
||||
use pixstrip_core::operations::*;
|
||||
use pixstrip_core::types::*;
|
||||
|
||||
#[test]
|
||||
fn resize_config_width_only() {
|
||||
let config = ResizeConfig::ByWidth(1200);
|
||||
assert_eq!(
|
||||
config.target_for(Dimensions { width: 4000, height: 3000 }),
|
||||
Dimensions { width: 1200, height: 900 }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resize_config_fit_in_box() {
|
||||
let config = ResizeConfig::FitInBox {
|
||||
max: Dimensions { width: 1920, height: 1080 },
|
||||
allow_upscale: false,
|
||||
};
|
||||
let result = config.target_for(Dimensions { width: 4000, height: 3000 });
|
||||
assert_eq!(result.width, 1440);
|
||||
assert_eq!(result.height, 1080);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resize_config_exact() {
|
||||
let config = ResizeConfig::Exact(Dimensions { width: 1080, height: 1080 });
|
||||
assert_eq!(
|
||||
config.target_for(Dimensions { width: 4000, height: 3000 }),
|
||||
Dimensions { width: 1080, height: 1080 }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn metadata_config_strip_all() {
|
||||
let config = MetadataConfig::StripAll;
|
||||
assert!(config.should_strip_gps());
|
||||
assert!(config.should_strip_camera());
|
||||
assert!(config.should_strip_copyright());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn metadata_config_privacy() {
|
||||
let config = MetadataConfig::Privacy;
|
||||
assert!(config.should_strip_gps());
|
||||
assert!(config.should_strip_camera());
|
||||
assert!(!config.should_strip_copyright());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn metadata_config_keep_all() {
|
||||
let config = MetadataConfig::KeepAll;
|
||||
assert!(!config.should_strip_gps());
|
||||
assert!(!config.should_strip_camera());
|
||||
assert!(!config.should_strip_copyright());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_config_single_format() {
|
||||
let config = ConvertConfig::SingleFormat(ImageFormat::WebP);
|
||||
assert_eq!(config.output_format(ImageFormat::Jpeg), ImageFormat::WebP);
|
||||
assert_eq!(config.output_format(ImageFormat::Png), ImageFormat::WebP);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_config_keep_original() {
|
||||
let config = ConvertConfig::KeepOriginal;
|
||||
assert_eq!(config.output_format(ImageFormat::Jpeg), ImageFormat::Jpeg);
|
||||
assert_eq!(config.output_format(ImageFormat::Png), ImageFormat::Png);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn watermark_position_all_nine() {
|
||||
let positions = [
|
||||
WatermarkPosition::TopLeft,
|
||||
WatermarkPosition::TopCenter,
|
||||
WatermarkPosition::TopRight,
|
||||
WatermarkPosition::MiddleLeft,
|
||||
WatermarkPosition::Center,
|
||||
WatermarkPosition::MiddleRight,
|
||||
WatermarkPosition::BottomLeft,
|
||||
WatermarkPosition::BottomCenter,
|
||||
WatermarkPosition::BottomRight,
|
||||
];
|
||||
assert_eq!(positions.len(), 9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_config_simple_template() {
|
||||
let config = RenameConfig {
|
||||
prefix: "blog_".into(),
|
||||
suffix: String::new(),
|
||||
counter_start: 1,
|
||||
counter_padding: 3,
|
||||
template: None,
|
||||
};
|
||||
let result = config.apply_simple("sunset", "jpg", 1);
|
||||
assert_eq!(result, "blog_sunset_001.jpg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_config_with_suffix() {
|
||||
let config = RenameConfig {
|
||||
prefix: String::new(),
|
||||
suffix: "_web".into(),
|
||||
counter_start: 1,
|
||||
counter_padding: 2,
|
||||
template: None,
|
||||
};
|
||||
let result = config.apply_simple("photo", "webp", 5);
|
||||
assert_eq!(result, "photo_web_05.webp");
|
||||
}
|
||||
Reference in New Issue
Block a user