diff options
Diffstat (limited to 'morphology-img/tests')
| -rw-r--r-- | morphology-img/tests/config.rs | 47 | ||||
| -rw-r--r-- | morphology-img/tests/integration.rs | 405 | ||||
| -rw-r--r-- | morphology-img/tests/render.rs | 428 |
3 files changed, 93 insertions, 787 deletions
diff --git a/morphology-img/tests/config.rs b/morphology-img/tests/config.rs index 7cc71cb..0ea1b0c 100644 --- a/morphology-img/tests/config.rs +++ b/morphology-img/tests/config.rs @@ -242,57 +242,14 @@ fn test_max_batch_size_field_is_public() { } #[test] -fn test_default_parallel_is_false() { - let config = RenderConfig::default(); - assert!(!config.parallel); -} - -#[test] -fn test_builder_parallel_true() { - let config = RenderConfig::new("output") - .parallel(true); - - assert!(config.parallel); - assert_eq!(config.output_dir, PathBuf::from("output")); -} - -#[test] -fn test_builder_parallel_false() { - let config = RenderConfig::new("output") - .parallel(false); - - assert!(!config.parallel); -} - -#[test] -fn test_builder_parallel_overwrites() { - let config = RenderConfig::new("output") - .parallel(true) - .parallel(false); // Override previous value - - assert!(!config.parallel); -} - -#[test] -fn test_builder_with_all_options_including_parallel() { +fn test_builder_with_all_options() { let config = RenderConfig::new("my-output") .keep_temp_files(true) .lilypond_binary("/usr/bin/lilypond") - .max_batch_size(25) - .parallel(true); + .max_batch_size(25); assert_eq!(config.output_dir, PathBuf::from("my-output")); assert!(config.keep_temp_files); assert_eq!(config.lilypond_binary, PathBuf::from("/usr/bin/lilypond")); assert_eq!(config.max_batch_size, Some(25)); - assert!(config.parallel); -} - -#[test] -fn test_parallel_field_is_public() { - let config = RenderConfig::new("output").parallel(true); - - // Should be able to access field directly - let _parallel = config.parallel; - assert!(_parallel); } diff --git a/morphology-img/tests/integration.rs b/morphology-img/tests/integration.rs index 423d668..b61f097 100644 --- a/morphology-img/tests/integration.rs +++ b/morphology-img/tests/integration.rs @@ -1,8 +1,7 @@ -use morphology_img::{render_sequences, RenderConfig, ProgressCallback}; +use morphology_img::{render_sequences, RenderConfig}; use morphology::{Sequence, Value}; use tempfile::TempDir; use std::fs; -use std::sync::{Arc, Mutex}; /// Test the complete pipeline with basic configuration #[test] @@ -365,178 +364,6 @@ fn test_render_sequences_realistic_workflow() { assert_eq!(svg_paths[3].file_name().unwrap().to_str().unwrap(), "sequence-3.svg"); } -// Tests for progress callback - -/// Test that progress callback is called correctly -#[test] -#[ignore] -fn test_progress_callback_basic() { - let sequences = vec![ - Sequence::new(vec![Value::origin()]), - Sequence::new(vec![Value::new(1, 0)]), - Sequence::new(vec![Value::new(2, 0)]), - ]; - - let progress_calls = Arc::new(Mutex::new(Vec::new())); - let progress_calls_clone = progress_calls.clone(); - - let callback: ProgressCallback = Arc::new(move |current, total| { - progress_calls_clone.lock().unwrap().push((current, total)); - }); - - let output_dir = TempDir::new().unwrap(); - let config = RenderConfig::new(output_dir.path()) - .progress_callback(callback); - - let svg_paths = render_sequences(&sequences, &config).unwrap(); - - // Verify all SVGs were created - assert_eq!(svg_paths.len(), 3); - - // Verify progress callback was called correctly - let calls = progress_calls.lock().unwrap(); - assert_eq!(calls.len(), 3, "callback should be called once per sequence"); - - // Verify calls have correct values - assert_eq!(calls[0], (1, 3), "first call should be (1, 3)"); - assert_eq!(calls[1], (2, 3), "second call should be (2, 3)"); - assert_eq!(calls[2], (3, 3), "third call should be (3, 3)"); -} - -/// Test progress callback with single sequence -#[test] -#[ignore] -fn test_progress_callback_single() { - let sequences = vec![Sequence::new(vec![Value::origin()])]; - - let progress_calls = Arc::new(Mutex::new(Vec::new())); - let progress_calls_clone = progress_calls.clone(); - - let callback: ProgressCallback = Arc::new(move |current, total| { - progress_calls_clone.lock().unwrap().push((current, total)); - }); - - let output_dir = TempDir::new().unwrap(); - let config = RenderConfig::new(output_dir.path()) - .progress_callback(callback); - - let _svg_paths = render_sequences(&sequences, &config).unwrap(); - - let calls = progress_calls.lock().unwrap(); - assert_eq!(calls.len(), 1); - assert_eq!(calls[0], (1, 1)); -} - -/// Test progress callback with many sequences -#[test] -#[ignore] -fn test_progress_callback_many() { - let sequences: Vec<Sequence> = (0..10) - .map(|i| Sequence::new(vec![Value::new(i, 0)])) - .collect(); - - let progress_calls = Arc::new(Mutex::new(Vec::new())); - let progress_calls_clone = progress_calls.clone(); - - let callback: ProgressCallback = Arc::new(move |current, total| { - progress_calls_clone.lock().unwrap().push((current, total)); - }); - - let output_dir = TempDir::new().unwrap(); - let config = RenderConfig::new(output_dir.path()) - .progress_callback(callback); - - let svg_paths = render_sequences(&sequences, &config).unwrap(); - - assert_eq!(svg_paths.len(), 10); - - let calls = progress_calls.lock().unwrap(); - assert_eq!(calls.len(), 10); - - // Verify each call has correct values - for (i, &(current, total)) in calls.iter().enumerate() { - assert_eq!(current, i + 1); - assert_eq!(total, 10); - } -} - -/// Test that rendering works without progress callback -#[test] -#[ignore] -fn test_no_progress_callback() { - let sequences = vec![ - Sequence::new(vec![Value::origin()]), - Sequence::new(vec![Value::new(1, 0)]), - ]; - - let output_dir = TempDir::new().unwrap(); - let config = RenderConfig::new(output_dir.path()); - // No progress callback set - - let svg_paths = render_sequences(&sequences, &config).unwrap(); - - // Should work normally without callback - assert_eq!(svg_paths.len(), 2); - for svg_path in &svg_paths { - assert!(svg_path.exists()); - } -} - -/// Test progress callback with empty sequence list -#[test] -#[ignore] -fn test_progress_callback_empty() { - let sequences: Vec<Sequence> = vec![]; - - let progress_calls = Arc::new(Mutex::new(Vec::new())); - let progress_calls_clone = progress_calls.clone(); - - let callback: ProgressCallback = Arc::new(move |current, total| { - progress_calls_clone.lock().unwrap().push((current, total)); - }); - - let output_dir = TempDir::new().unwrap(); - let config = RenderConfig::new(output_dir.path()) - .progress_callback(callback); - - let svg_paths = render_sequences(&sequences, &config).unwrap(); - - assert_eq!(svg_paths.len(), 0); - - // Callback should not be called for empty list - let calls = progress_calls.lock().unwrap(); - assert_eq!(calls.len(), 0, "callback should not be called for empty input"); -} - -/// Test that progress callback can track actual progress -#[test] -#[ignore] -fn test_progress_callback_tracking() { - let sequences: Vec<Sequence> = (0..5) - .map(|i| Sequence::new(vec![Value::new(i, 0)])) - .collect(); - - let last_progress = Arc::new(Mutex::new((0, 0))); - let last_progress_clone = last_progress.clone(); - - let callback: ProgressCallback = Arc::new(move |current, total| { - let mut progress = last_progress_clone.lock().unwrap(); - *progress = (current, total); - }); - - let output_dir = TempDir::new().unwrap(); - let config = RenderConfig::new(output_dir.path()) - .progress_callback(callback); - - let svg_paths = render_sequences(&sequences, &config).unwrap(); - - assert_eq!(svg_paths.len(), 5); - - // Last progress should be 5/5 - let final_progress = last_progress.lock().unwrap(); - assert_eq!(*final_progress, (5, 5), "final progress should be 5/5"); -} - // ============================================================================ // Batch Chunking Tests // ============================================================================ @@ -664,43 +491,6 @@ fn test_batch_chunking_preserves_order() { #[test] #[ignore] -fn test_batch_chunking_with_progress() { - // Test that progress callback works correctly with batching - let sequences: Vec<Sequence> = (0..8) - .map(|i| { - Sequence::new(vec![Value::new(i, 0)]) - }) - .collect(); - - let progress_calls = Arc::new(Mutex::new(Vec::new())); - let progress_calls_clone = progress_calls.clone(); - - let callback: ProgressCallback = Arc::new(move |current, total| { - progress_calls_clone.lock().unwrap().push((current, total)); - }); - - let output_dir = TempDir::new().unwrap(); - let config = RenderConfig::new(output_dir.path()) - .max_batch_size(3) - .progress_callback(callback); - - let svg_paths = render_sequences(&sequences, &config).unwrap(); - - assert_eq!(svg_paths.len(), 8); - - // Progress should track within each batch - let calls = progress_calls.lock().unwrap(); - assert!(!calls.is_empty(), "Progress callback should be called"); - - // Note: Progress is per-batch, so we should see: - // Batch 1 (3 items): (1,3), (2,3), (3,3) - // Batch 2 (3 items): (1,3), (2,3), (3,3) - // Batch 3 (2 items): (1,2), (2,2) - assert_eq!(calls.len(), 8, "Should have 8 progress calls total"); -} - -#[test] -#[ignore] fn test_batch_size_one() { // Edge case: batch size of 1 (process one at a time) let sequences: Vec<Sequence> = (0..3) @@ -720,196 +510,3 @@ fn test_batch_size_one() { assert!(path.exists()); } } - -// ============================================================================ -// Parallel Processing Tests -// ============================================================================ - -#[test] -#[ignore] -fn test_parallel_rendering_basic() { - // Test that parallel rendering works correctly - let sequences: Vec<Sequence> = (0..10) - .map(|i| { - Sequence::new(vec![Value::new(i, 0)]) - }) - .collect(); - - let output_dir = TempDir::new().unwrap(); - let config = RenderConfig::new(output_dir.path()) - .parallel(true); - - let svg_paths = render_sequences(&sequences, &config).unwrap(); - - assert_eq!(svg_paths.len(), 10); - for path in &svg_paths { - assert!(path.exists(), "SVG file should exist: {}", path.display()); - } -} - -#[test] -#[ignore] -fn test_parallel_vs_sequential_same_results() { - // Verify that parallel and sequential produce the same results - let sequences: Vec<Sequence> = (0..5) - .map(|i| { - Sequence::new(vec![Value::new(i, 0), Value::new(i, 1)]) - }) - .collect(); - - // Sequential rendering - let output_dir_seq = TempDir::new().unwrap(); - let config_seq = RenderConfig::new(output_dir_seq.path()) - .parallel(false); - - let svg_paths_seq = render_sequences(&sequences, &config_seq).unwrap(); - - // Parallel rendering - let output_dir_par = TempDir::new().unwrap(); - let config_par = RenderConfig::new(output_dir_par.path()) - .parallel(true); - - let svg_paths_par = render_sequences(&sequences, &config_par).unwrap(); - - // Both should produce same number of files - assert_eq!(svg_paths_seq.len(), svg_paths_par.len()); - - // Both should have files with same names - for (seq_path, par_path) in svg_paths_seq.iter().zip(svg_paths_par.iter()) { - assert_eq!( - seq_path.file_name(), - par_path.file_name(), - "Sequential and parallel should produce same filenames" - ); - assert!(seq_path.exists()); - assert!(par_path.exists()); - } -} - -#[test] -#[ignore] -fn test_parallel_with_progress_callback() { - // Test that progress callbacks work with parallel rendering - let sequences: Vec<Sequence> = (0..8) - .map(|i| { - Sequence::new(vec![Value::new(i, 0)]) - }) - .collect(); - - let progress_calls = Arc::new(Mutex::new(Vec::new())); - let progress_calls_clone = progress_calls.clone(); - - let callback: ProgressCallback = Arc::new(move |current, total| { - progress_calls_clone.lock().unwrap().push((current, total)); - }); - - let output_dir = TempDir::new().unwrap(); - let config = RenderConfig::new(output_dir.path()) - .parallel(true) - .progress_callback(callback); - - let svg_paths = render_sequences(&sequences, &config).unwrap(); - - assert_eq!(svg_paths.len(), 8); - - // Progress callback should have been called 8 times - let calls = progress_calls.lock().unwrap(); - assert_eq!(calls.len(), 8, "Progress callback should be called for each file"); - - // All calls should have total=8 - for (_current, total) in calls.iter() { - assert_eq!(*total, 8, "Total should always be 8"); - } -} - -#[test] -#[ignore] -fn test_parallel_default_is_false() { - let config = RenderConfig::default(); - assert!(!config.parallel, "Parallel should default to false"); - - let config2 = RenderConfig::new("output"); - assert!(!config2.parallel, "Parallel should default to false"); -} - -#[test] -#[ignore] -fn test_parallel_with_batch_chunking() { - // Test parallel rendering combined with batch chunking - let sequences: Vec<Sequence> = (0..15) - .map(|i| { - Sequence::new(vec![Value::new(i, 0)]) - }) - .collect(); - - let output_dir = TempDir::new().unwrap(); - let config = RenderConfig::new(output_dir.path()) - .parallel(true) - .max_batch_size(5); - - let svg_paths = render_sequences(&sequences, &config).unwrap(); - - // All 15 SVGs should be created - assert_eq!(svg_paths.len(), 15); - - // Verify files are in order (sequence-00.svg through sequence-14.svg) - for (i, path) in svg_paths.iter().enumerate() { - let expected_filename = format!("sequence-{:02}.svg", i); - assert_eq!( - path.file_name().unwrap().to_str().unwrap(), - expected_filename, - "Files should be in correct order" - ); - assert!(path.exists()); - } -} - -#[test] -#[ignore] -fn test_benchmark_parallel_vs_sequential() { - use std::time::Instant; - - // Create many sequences for meaningful benchmark - let sequences: Vec<Sequence> = (0..20) - .map(|i| { - Sequence::new(vec![Value::new(i, 0)]) - }) - .collect(); - - // Sequential rendering - let output_dir_seq = TempDir::new().unwrap(); - let config_seq = RenderConfig::new(output_dir_seq.path()) - .parallel(false); - - let start = Instant::now(); - let svg_paths_seq = render_sequences(&sequences, &config_seq).unwrap(); - let sequential_time = start.elapsed(); - - assert_eq!(svg_paths_seq.len(), 20); - - // Parallel rendering - let output_dir_par = TempDir::new().unwrap(); - let config_par = RenderConfig::new(output_dir_par.path()) - .parallel(true); - - let start = Instant::now(); - let svg_paths_par = render_sequences(&sequences, &config_par).unwrap(); - let parallel_time = start.elapsed(); - - assert_eq!(svg_paths_par.len(), 20); - - // Print timing results - println!("\n=== Parallel vs Sequential Benchmark (20 sequences) ==="); - println!("Sequential time: {:?}", sequential_time); - println!("Parallel time: {:?}", parallel_time); - - if parallel_time < sequential_time { - let speedup = sequential_time.as_secs_f64() / parallel_time.as_secs_f64(); - println!("Speedup: {:.2}x faster", speedup); - } else { - println!("Note: Parallel was slower (overhead or system constraints)"); - } - - // No strict assertion on speed - depends on system - // Just verify both completed successfully -} diff --git a/morphology-img/tests/render.rs b/morphology-img/tests/render.rs index b6538ab..3e86f97 100644 --- a/morphology-img/tests/render.rs +++ b/morphology-img/tests/render.rs @@ -1,12 +1,11 @@ -use morphology_img::render::{check_lilypond_available, render_ly_to_svg, render_ly_files_to_svg}; +use morphology_img::render::{check_lilypond_available, render_all_ly_files_batch}; use morphology_img::error::RenderError; use morphology_img::file_gen::{create_temp_dir, generate_ly_file, write_support_files, generate_ly_files}; use morphology::{Sequence, Value}; use std::path::Path; use tempfile::TempDir; -/// This test requires LilyPond to be installed on the system. -/// Run with: cargo test -- --ignored +/// Test that LilyPond is available (requires LilyPond installation) #[test] #[ignore] fn test_lilypond_available() { @@ -17,10 +16,7 @@ fn test_lilypond_available() { let version = result.unwrap(); println!("LilyPond version: {}", version); - // Verify the version string is not empty assert!(!version.is_empty(), "version string should not be empty"); - - // Verify it contains "LilyPond" or starts with "GNU" assert!( version.contains("LilyPond") || version.starts_with("GNU"), "version string should contain 'LilyPond' or start with 'GNU', got: {}", @@ -28,18 +24,14 @@ fn test_lilypond_available() { ); } -/// Test that verifies the error type when LilyPond is not found. -/// This test will pass if LilyPond is NOT installed, or will be skipped if it is. +/// Test error type when LilyPond is not found #[test] fn test_lilypond_not_found_error_type() { - // Try to check for LilyPond let result = check_lilypond_available(); - // If it fails, verify it's the right error type if let Err(e) = result { match e { RenderError::LilyPondNotFound(msg) => { - // Verify the error message is helpful assert!(!msg.is_empty(), "error message should not be empty"); assert!( msg.contains("LilyPond") || msg.contains("PATH"), @@ -49,450 +41,221 @@ fn test_lilypond_not_found_error_type() { _ => panic!("Expected RenderError::LilyPondNotFound, got: {:?}", e), } } else { - // If LilyPond is available, we can't test the error case, so skip println!("LilyPond is installed, skipping error test"); } } -/// Test that we handle the case where the command exists but fails -#[test] -fn test_command_failure_handling() { - use std::process::Command; - - // Use a command that exists but will fail with --version - // (most systems have 'false' which always returns non-zero) - let output = Command::new("false") - .output(); - - if output.is_ok() { - let out = output.unwrap(); - // If false command exists, verify we can detect failure status - assert!(!out.status.success(), "false command should have non-success status"); - } -} - -// Tests for render_ly_to_svg (single file SVG generation) - -/// Test rendering a single .ly file to SVG +/// Test rendering multiple .ly files to SVGs in a single batch #[test] #[ignore] -fn test_render_single_svg() { - // Create a simple sequence - let seq = Sequence::new(vec![Value::origin()]); +fn test_render_batch_basic() { + let sequences = vec![ + Sequence::new(vec![Value::origin()]), + Sequence::new(vec![Value::new(1, 0)]), + Sequence::new(vec![Value::new(-1, 0)]), + ]; - // Generate .ly file let temp_dir = create_temp_dir().unwrap(); write_support_files(temp_dir.path()).unwrap(); + let ly_files = generate_ly_files(&sequences, temp_dir.path()).unwrap(); - let ly_path = temp_dir.path().join("test.ly"); - generate_ly_file(&seq, &ly_path).unwrap(); - - // Render to SVG let output_dir = TempDir::new().unwrap(); - let svg_path = render_ly_to_svg( - &ly_path, + let svg_paths = render_all_ly_files_batch( + &ly_files, output_dir.path(), Path::new("lilypond"), ).unwrap(); - // Verify SVG exists - assert!(svg_path.exists(), "SVG file should exist"); - - // Verify SVG has content - let svg_content = std::fs::read_to_string(&svg_path).unwrap(); - assert!(svg_content.contains("<svg"), "file should contain SVG markup"); - assert!(!svg_content.is_empty(), "SVG file should not be empty"); + assert_eq!(svg_paths.len(), 3); + for svg_path in &svg_paths { + assert!(svg_path.exists()); + let content = std::fs::read_to_string(svg_path).unwrap(); + assert!(content.contains("<svg")); + } } -/// Test rendering with the example sequence +/// Test batch rendering preserves order #[test] #[ignore] -fn test_render_example_sequence() { - // Create the example sequence - let seq = Sequence::new(vec![ - Value::new(1, 0), - Value::new(-1, 1), - Value::new(-1, 0), - Value::new(0, 0), - ]); +fn test_render_batch_preserves_order() { + let sequences = vec![ + Sequence::new(vec![Value::new(5, 0)]), + Sequence::new(vec![Value::new(3, 0)]), + Sequence::new(vec![Value::new(1, 0)]), + ]; let temp_dir = create_temp_dir().unwrap(); write_support_files(temp_dir.path()).unwrap(); - - let ly_path = temp_dir.path().join("example.ly"); - generate_ly_file(&seq, &ly_path).unwrap(); + let ly_files = generate_ly_files(&sequences, temp_dir.path()).unwrap(); let output_dir = TempDir::new().unwrap(); - let svg_path = render_ly_to_svg( - &ly_path, + let svg_paths = render_all_ly_files_batch( + &ly_files, output_dir.path(), Path::new("lilypond"), ).unwrap(); - // Verify SVG was created - assert!(svg_path.exists()); - - // Verify it contains SVG content - let svg_content = std::fs::read_to_string(&svg_path).unwrap(); - assert!(svg_content.contains("<svg")); - assert!(svg_content.len() > 1000, "SVG should have substantial content"); -} - -/// Test that output directory is created if it doesn't exist -#[test] -#[ignore] -fn test_creates_output_directory() { - let seq = Sequence::new(vec![Value::origin()]); - - let temp_dir = create_temp_dir().unwrap(); - write_support_files(temp_dir.path()).unwrap(); - - let ly_path = temp_dir.path().join("test.ly"); - generate_ly_file(&seq, &ly_path).unwrap(); - - // Use a nested directory that doesn't exist yet - let output_base = TempDir::new().unwrap(); - let output_dir = output_base.path().join("nested").join("output"); - - assert!(!output_dir.exists(), "output directory should not exist yet"); - - let svg_path = render_ly_to_svg( - &ly_path, - &output_dir, - Path::new("lilypond"), - ).unwrap(); - - // Verify directory was created - assert!(output_dir.exists(), "output directory should be created"); - assert!(svg_path.exists(), "SVG should be in created directory"); + assert_eq!(svg_paths[0].file_name().unwrap().to_str().unwrap(), "sequence-0.svg"); + assert_eq!(svg_paths[1].file_name().unwrap().to_str().unwrap(), "sequence-1.svg"); + assert_eq!(svg_paths[2].file_name().unwrap().to_str().unwrap(), "sequence-2.svg"); } -/// Test rendering multiple different sequences +/// Test batch rendering with empty list #[test] -#[ignore] -fn test_render_multiple_different_sequences() { - let sequences = vec![ - Sequence::new(vec![Value::origin()]), - Sequence::new(vec![Value::new(1, 0)]), - Sequence::new(vec![Value::new(-1, 0)]), - ]; - - let temp_dir = create_temp_dir().unwrap(); - write_support_files(temp_dir.path()).unwrap(); - +fn test_render_batch_empty() { + let ly_files: Vec<std::path::PathBuf> = vec![]; let output_dir = TempDir::new().unwrap(); - for (i, seq) in sequences.iter().enumerate() { - let ly_path = temp_dir.path().join(format!("seq-{}.ly", i)); - generate_ly_file(seq, &ly_path).unwrap(); - - let svg_path = render_ly_to_svg( - &ly_path, - output_dir.path(), - Path::new("lilypond"), - ).unwrap(); - - assert!(svg_path.exists()); - assert_eq!(svg_path.file_name().unwrap().to_str().unwrap(), format!("seq-{}.svg", i)); - } - - // Verify all 3 SVGs were created - let entries: Vec<_> = std::fs::read_dir(output_dir.path()) - .unwrap() - .filter_map(|e| e.ok()) - .collect(); - assert_eq!(entries.len(), 3, "should have 3 SVG files"); -} - -/// Test that SVG content is valid and contains expected elements -#[test] -#[ignore] -fn test_svg_content_validity() { - let seq = Sequence::new(vec![Value::origin()]); - - let temp_dir = create_temp_dir().unwrap(); - write_support_files(temp_dir.path()).unwrap(); - - let ly_path = temp_dir.path().join("test.ly"); - generate_ly_file(&seq, &ly_path).unwrap(); - - let output_dir = TempDir::new().unwrap(); - let svg_path = render_ly_to_svg( - &ly_path, + let svg_paths = render_all_ly_files_batch( + &ly_files, output_dir.path(), Path::new("lilypond"), ).unwrap(); - let svg_content = std::fs::read_to_string(&svg_path).unwrap(); - - // Verify SVG structure - assert!(svg_content.contains("<svg"), "should contain <svg tag"); - assert!(svg_content.contains("</svg>"), "should contain closing </svg> tag"); - assert!(svg_content.contains("xmlns"), "should contain XML namespace"); - - // LilyPond SVGs typically contain these elements - assert!(svg_content.contains("<g"), "should contain <g> group elements"); + assert_eq!(svg_paths.len(), 0); } -/// Test rendering with relative path for lilypond binary +/// Test batch rendering creates output directory #[test] #[ignore] -fn test_render_with_relative_lilypond_path() { +fn test_render_batch_creates_output_dir() { let seq = Sequence::new(vec![Value::origin()]); - let temp_dir = create_temp_dir().unwrap(); write_support_files(temp_dir.path()).unwrap(); let ly_path = temp_dir.path().join("test.ly"); generate_ly_file(&seq, &ly_path).unwrap(); - let output_dir = TempDir::new().unwrap(); + let output_base = TempDir::new().unwrap(); + let output_dir = output_base.path().join("nested").join("output"); + assert!(!output_dir.exists()); - // Use just "lilypond" as the binary name (will be found in PATH) - let svg_path = render_ly_to_svg( - &ly_path, - output_dir.path(), + let svg_paths = render_all_ly_files_batch( + &[ly_path], + &output_dir, Path::new("lilypond"), ).unwrap(); - assert!(svg_path.exists()); + assert!(output_dir.exists()); + assert_eq!(svg_paths.len(), 1); } -/// Test that the function returns an error if LilyPond fails +/// Test with invalid .ly file #[test] #[ignore] -fn test_render_error_on_invalid_ly_file() { +fn test_render_batch_invalid_ly_file() { use std::fs; let temp_dir = create_temp_dir().unwrap(); - - // Create an invalid .ly file (missing required structure) let ly_path = temp_dir.path().join("invalid.ly"); fs::write(&ly_path, "this is not valid lilypond syntax!!!").unwrap(); let output_dir = TempDir::new().unwrap(); - - let result = render_ly_to_svg( - &ly_path, + let result = render_all_ly_files_batch( + &[ly_path], output_dir.path(), Path::new("lilypond"), ); - // Should return an error - assert!(result.is_err(), "should fail on invalid .ly file"); - + assert!(result.is_err()); match result { Err(RenderError::LilyPondExecution(msg)) => { - assert!(!msg.is_empty(), "error message should not be empty"); + assert!(!msg.is_empty()); } _ => panic!("expected LilyPondExecution error"), } } -// Tests for render_ly_files_to_svg (batch SVG generation) - -/// Test rendering multiple .ly files to SVGs in batch +/// Test batch rendering with many files #[test] #[ignore] -fn test_render_multiple_svgs_batch() { - // Create multiple sequences - let sequences = vec![ - Sequence::new(vec![Value::origin()]), - Sequence::new(vec![Value::new(1, 0)]), - Sequence::new(vec![Value::new(-1, 0)]), - ]; +fn test_render_batch_many_files() { + let sequences: Vec<Sequence> = (0..20) + .map(|i| Sequence::new(vec![Value::new(i, 0)])) + .collect(); let temp_dir = create_temp_dir().unwrap(); write_support_files(temp_dir.path()).unwrap(); - - // Generate .ly files let ly_files = generate_ly_files(&sequences, temp_dir.path()).unwrap(); - // Render all to SVGs let output_dir = TempDir::new().unwrap(); - let svg_paths = render_ly_files_to_svg( + let svg_paths = render_all_ly_files_batch( &ly_files, output_dir.path(), Path::new("lilypond"), - None, ).unwrap(); - // Verify all SVGs were created - assert_eq!(svg_paths.len(), 3, "should create 3 SVG files"); - + assert_eq!(svg_paths.len(), 20); for svg_path in &svg_paths { - assert!(svg_path.exists(), "each SVG should exist"); - - // Verify SVG has content + assert!(svg_path.exists()); let content = std::fs::read_to_string(svg_path).unwrap(); - assert!(content.contains("<svg"), "should contain SVG markup"); - } -} - -/// Test that batch rendering preserves order -#[test] -#[ignore] -fn test_batch_render_preserves_order() { - let sequences = vec![ - Sequence::new(vec![Value::new(5, 0)]), - Sequence::new(vec![Value::new(3, 0)]), - Sequence::new(vec![Value::new(1, 0)]), - ]; - - let temp_dir = create_temp_dir().unwrap(); - write_support_files(temp_dir.path()).unwrap(); - - let ly_files = generate_ly_files(&sequences, temp_dir.path()).unwrap(); - - let output_dir = TempDir::new().unwrap(); - let svg_paths = render_ly_files_to_svg( - &ly_files, - output_dir.path(), - Path::new("lilypond"), - None, - ).unwrap(); - - // Verify filenames are in order - assert_eq!(svg_paths[0].file_name().unwrap().to_str().unwrap(), "sequence-0.svg"); - assert_eq!(svg_paths[1].file_name().unwrap().to_str().unwrap(), "sequence-1.svg"); - assert_eq!(svg_paths[2].file_name().unwrap().to_str().unwrap(), "sequence-2.svg"); - - // Verify all files exist - for path in &svg_paths { - assert!(path.exists()); + assert!(content.contains("<svg")); } } -/// Test batch rendering with empty list +/// Test rendering with example sequence from development plan #[test] #[ignore] -fn test_batch_render_empty_list() { - let ly_files: Vec<std::path::PathBuf> = vec![]; - - let output_dir = TempDir::new().unwrap(); - let svg_paths = render_ly_files_to_svg( - &ly_files, - output_dir.path(), - Path::new("lilypond"), - None, - ).unwrap(); - - assert_eq!(svg_paths.len(), 0, "should return empty vector for empty input"); -} - -/// Test batch rendering with single file -#[test] -#[ignore] -fn test_batch_render_single_file() { - let seq = Sequence::new(vec![Value::origin()]); +fn test_render_example_sequence() { + let seq = Sequence::new(vec![ + Value::new(1, 0), + Value::new(-1, 1), + Value::new(-1, 0), + Value::new(0, 0), + ]); let temp_dir = create_temp_dir().unwrap(); write_support_files(temp_dir.path()).unwrap(); - let ly_path = temp_dir.path().join("single.ly"); + let ly_path = temp_dir.path().join("example.ly"); generate_ly_file(&seq, &ly_path).unwrap(); - let ly_files = vec![ly_path]; - let output_dir = TempDir::new().unwrap(); - let svg_paths = render_ly_files_to_svg( - &ly_files, + let svg_paths = render_all_ly_files_batch( + &[ly_path], output_dir.path(), Path::new("lilypond"), - None, ).unwrap(); assert_eq!(svg_paths.len(), 1); assert!(svg_paths[0].exists()); - assert_eq!(svg_paths[0].file_name().unwrap().to_str().unwrap(), "single.svg"); -} - -/// Test that batch rendering stops on first error -#[test] -#[ignore] -fn test_batch_render_stops_on_error() { - use std::fs; - - let temp_dir = create_temp_dir().unwrap(); - // Create one valid and one invalid .ly file - let seq = Sequence::new(vec![Value::origin()]); - write_support_files(temp_dir.path()).unwrap(); - - let valid_ly = temp_dir.path().join("valid.ly"); - generate_ly_file(&seq, &valid_ly).unwrap(); - - let invalid_ly = temp_dir.path().join("invalid.ly"); - fs::write(&invalid_ly, "invalid lilypond syntax!!!").unwrap(); - - let ly_files = vec![valid_ly, invalid_ly]; - - let output_dir = TempDir::new().unwrap(); - let result = render_ly_files_to_svg( - &ly_files, - output_dir.path(), - Path::new("lilypond"), - None, - ); - - // Should fail due to invalid file - assert!(result.is_err(), "should fail on invalid file"); - - match result { - Err(RenderError::LilyPondExecution(_)) => { - // Expected error type - } - _ => panic!("expected LilyPondExecution error"), - } + let svg_content = std::fs::read_to_string(&svg_paths[0]).unwrap(); + assert!(svg_content.contains("<svg")); + assert!(svg_content.len() > 1000, "SVG should have substantial content"); } -/// Test batch rendering with large number of files +/// Test that SVG content is valid #[test] #[ignore] -fn test_batch_render_many_files() { - // Create 10 sequences - let sequences: Vec<Sequence> = (0..10) - .map(|i| Sequence::new(vec![Value::new(i, 0)])) - .collect(); +fn test_svg_content_validity() { + let seq = Sequence::new(vec![Value::origin()]); let temp_dir = create_temp_dir().unwrap(); write_support_files(temp_dir.path()).unwrap(); - let ly_files = generate_ly_files(&sequences, temp_dir.path()).unwrap(); + let ly_path = temp_dir.path().join("test.ly"); + generate_ly_file(&seq, &ly_path).unwrap(); let output_dir = TempDir::new().unwrap(); - let svg_paths = render_ly_files_to_svg( - &ly_files, + let svg_paths = render_all_ly_files_batch( + &[ly_path], output_dir.path(), Path::new("lilypond"), - None, ).unwrap(); - // Verify all 10 SVGs were created - assert_eq!(svg_paths.len(), 10, "should create 10 SVG files"); + let svg_content = std::fs::read_to_string(&svg_paths[0]).unwrap(); - for (i, svg_path) in svg_paths.iter().enumerate() { - assert!(svg_path.exists()); - // With 10 files, we need 2-digit padding: 00, 01, 02, ..., 09 - assert_eq!( - svg_path.file_name().unwrap().to_str().unwrap(), - format!("sequence-{:02}.svg", i) - ); - } - - // Verify all files have content - for svg_path in &svg_paths { - let content = std::fs::read_to_string(svg_path).unwrap(); - assert!(content.contains("<svg")); - assert!(content.len() > 100, "SVG should have substantial content"); - } + assert!(svg_content.contains("<svg"), "should contain <svg tag"); + assert!(svg_content.contains("</svg>"), "should contain closing </svg> tag"); + assert!(svg_content.contains("xmlns"), "should contain XML namespace"); + assert!(svg_content.contains("<g"), "should contain <g> group elements"); } /// Integration test: Complete pipeline from sequences to SVGs #[test] #[ignore] fn test_complete_pipeline_batch_rendering() { - // Create test sequences let sequences = vec![ Sequence::new(vec![ Value::new(1, 0), @@ -509,44 +272,33 @@ fn test_complete_pipeline_batch_rendering() { ]), ]; - // Create temp directory and write support files let temp_dir = create_temp_dir().unwrap(); write_support_files(temp_dir.path()).unwrap(); - // Generate .ly files let ly_files = generate_ly_files(&sequences, temp_dir.path()).unwrap(); assert_eq!(ly_files.len(), 3); - // Render all to SVGs let output_dir = TempDir::new().unwrap(); - let svg_paths = render_ly_files_to_svg( + let svg_paths = render_all_ly_files_batch( &ly_files, output_dir.path(), Path::new("lilypond"), - None, ).unwrap(); - // Verify complete pipeline assert_eq!(svg_paths.len(), 3); - // Verify each SVG for (i, svg_path) in svg_paths.iter().enumerate() { - // File exists assert!(svg_path.exists(), "SVG {} should exist", i); - - // Correct filename assert_eq!( svg_path.file_name().unwrap().to_str().unwrap(), format!("sequence-{}.svg", i) ); - // Has valid SVG content let content = std::fs::read_to_string(svg_path).unwrap(); assert!(content.contains("<svg"), "SVG {} should have svg tag", i); assert!(content.contains("</svg>"), "SVG {} should have closing tag", i); } - // Verify all files are in output directory let entries: Vec<_> = std::fs::read_dir(output_dir.path()) .unwrap() .filter_map(|e| e.ok()) |