trimdown 0.1.6

Fast file compression tool for Office documents (PPTX, DOCX, XLSX), PDFs, videos, images, OpenDocument formats, and archives with streaming support
Documentation
use std::path::PathBuf;
use trimdown::{Cli, PdfQuality, PdfMethod, Commands};

#[test]
fn test_concat_command_structure() {
    let cli = Cli {
        command: Some(Commands::Concat {
            inputs: vec![
                PathBuf::from("video1.mp4"),
                PathBuf::from("video2.mp4"),
            ],
            re_encode: false,
        }),
        input: None,
        output: Some(PathBuf::from("output.mp4")),
        folder: false,
        quality: 85,
        max_width: 1920,
        video_crf: 23,
        video_max_width: 1920,
        pdf_quality: PdfQuality::Ebook,
        pdf_method: PdfMethod::Auto,
        force: false,
        verbose: false,
        dry_run: false,
        preset: None,
        parallel: false,
    preserve_metadata: false,
    streaming: false,
    memory_limit: None,
    };

    match &cli.command {
        Some(Commands::Concat { inputs, re_encode }) => {
            assert_eq!(inputs.len(), 2);
            assert!(!re_encode);
        }
        _ => panic!("Expected Concat command"),
    }
}

#[test]
fn test_concat_command_with_re_encode() {
    let cli = Cli {
        command: Some(Commands::Concat {
            inputs: vec![
                PathBuf::from("video1.mp4"),
                PathBuf::from("video2.mp4"),
                PathBuf::from("video3.mp4"),
            ],
            re_encode: true,
        }),
        input: None,
        output: Some(PathBuf::from("output.mp4")),
        folder: false,
        quality: 85,
        max_width: 1920,
        video_crf: 20,
        video_max_width: 1280,
        pdf_quality: PdfQuality::Ebook,
        pdf_method: PdfMethod::Auto,
        force: false,
        verbose: false,
        dry_run: false,
        preset: None,
        parallel: false,
    preserve_metadata: false,
    streaming: false,
    memory_limit: None,
    };

    match &cli.command {
        Some(Commands::Concat { inputs, re_encode }) => {
            assert_eq!(inputs.len(), 3);
            assert!(re_encode);
        }
        _ => panic!("Expected Concat command"),
    }
    
    assert_eq!(cli.video_crf, 20);
    assert_eq!(cli.video_max_width, 1280);
}

#[test]
fn test_video_compression_settings() {
    let crf_values = vec![0, 18, 23, 28, 51];
    let width_values = vec![720, 1280, 1920, 2560, 3840];

    for crf in &crf_values {
        for width in &width_values {
            let cli = Cli {
                command: None,
                input: Some(PathBuf::from("test.mp4")),
                output: Some(PathBuf::from("output.mp4")),
                folder: false,
                quality: 85,
                max_width: 1920,
                video_crf: *crf,
                video_max_width: *width,
                pdf_quality: PdfQuality::Ebook,
                pdf_method: PdfMethod::Auto,
                force: false,
                verbose: false,
                dry_run: false,
                preset: None,
                parallel: false,
            preserve_metadata: false,
            streaming: false,
            memory_limit: None,
            };

            assert_eq!(cli.video_crf, *crf);
            assert_eq!(cli.video_max_width, *width);
        }
    }
}

#[test]
fn test_concat_minimum_files_validation() {
    // Concat should require at least 2 files
    let single_file = vec![PathBuf::from("video1.mp4")];
    assert_eq!(single_file.len(), 1);

    let two_files = vec![
        PathBuf::from("video1.mp4"),
        PathBuf::from("video2.mp4"),
    ];
    assert!(two_files.len() >= 2);

    let many_files = vec![
        PathBuf::from("video1.mp4"),
        PathBuf::from("video2.mp4"),
        PathBuf::from("video3.mp4"),
        PathBuf::from("video4.mp4"),
    ];
    assert!(many_files.len() >= 2);
}

#[test]
fn test_video_output_path_generation() {
    let cli = Cli {
        command: None,
        input: Some(PathBuf::from("input.mp4")),
        output: None,
        folder: false,
        quality: 85,
        max_width: 1920,
        video_crf: 23,
        video_max_width: 1920,
        pdf_quality: PdfQuality::Ebook,
        pdf_method: PdfMethod::Auto,
        force: false,
        verbose: false,
        dry_run: false,
        preset: None,
        parallel: false,
    preserve_metadata: false,
    streaming: false,
    memory_limit: None,
    };

    // When output is None, it should generate a default output path
    assert!(cli.output.is_none());
    assert!(cli.input.is_some());
}

#[test]
fn test_concat_with_custom_output() {
    let custom_output = PathBuf::from("/custom/path/merged_video.mp4");
    
    let cli = Cli {
        command: Some(Commands::Concat {
            inputs: vec![
                PathBuf::from("part1.mp4"),
                PathBuf::from("part2.mp4"),
            ],
            re_encode: false,
        }),
        input: None,
        output: Some(custom_output.clone()),
        folder: false,
        quality: 85,
        max_width: 1920,
        video_crf: 23,
        video_max_width: 1920,
        pdf_quality: PdfQuality::Ebook,
        pdf_method: PdfMethod::Auto,
        force: true,
        verbose: false,
        dry_run: false,
        preset: None,
        parallel: false,
    preserve_metadata: false,
    streaming: false,
    memory_limit: None,
    };

    assert_eq!(cli.output, Some(custom_output));
    assert!(cli.force);
}

#[test]
fn test_video_compression_with_presets() {
    let presets = vec!["fast", "balanced", "maximum"];

    for preset in presets {
        let cli = Cli {
            command: None,
            input: Some(PathBuf::from("test.mp4")),
            output: Some(PathBuf::from("output.mp4")),
            folder: false,
            quality: 85,
            max_width: 1920,
            video_crf: 23,
            video_max_width: 1920,
            pdf_quality: PdfQuality::Ebook,
            pdf_method: PdfMethod::Auto,
            force: false,
            verbose: false,
            dry_run: false,
            preset: Some(preset.to_string()),
            parallel: false,
        preserve_metadata: false,
        streaming: false,
        memory_limit: None,
        };

        assert_eq!(cli.preset.as_deref(), Some(preset));
    }
}