diff options
| author | jacksonfu14 <jackson@fashionunited.com> | 2025-11-17 06:56:09 +0100 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2025-11-17 06:56:09 +0100 |
| commit | a20f9a327c4d9e5ac8f42db4e2e9fb29770c3d37 (patch) | |
| tree | 568c2650e8bf015b896f86297176a485b9bb5c08 /morphology-img/tests/config.rs | |
| parent | 3077c7af770b055804d5cf48994a4e4cf6d31146 (diff) | |
feature: generate and process ly files
Diffstat (limited to 'morphology-img/tests/config.rs')
| -rw-r--r-- | morphology-img/tests/config.rs | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/morphology-img/tests/config.rs b/morphology-img/tests/config.rs new file mode 100644 index 0000000..9b47ed5 --- /dev/null +++ b/morphology-img/tests/config.rs @@ -0,0 +1,185 @@ +use morphology_img::RenderConfig; +use std::path::PathBuf; + +#[test] +fn test_default_config() { + let config = RenderConfig::default(); + + assert_eq!(config.output_dir, PathBuf::from("output")); + assert!(!config.keep_temp_files); + assert_eq!(config.lilypond_binary, PathBuf::from("lilypond")); +} + +#[test] +fn test_new_config() { + let config = RenderConfig::new("my-output"); + + assert_eq!(config.output_dir, PathBuf::from("my-output")); + assert!(!config.keep_temp_files); + assert_eq!(config.lilypond_binary, PathBuf::from("lilypond")); +} + +#[test] +fn test_new_config_with_pathbuf() { + let path = PathBuf::from("/absolute/path/to/output"); + let config = RenderConfig::new(path.clone()); + + assert_eq!(config.output_dir, path); +} + +#[test] +fn test_builder_keep_temp_files() { + let config = RenderConfig::new("output") + .keep_temp_files(true); + + assert!(config.keep_temp_files); + assert_eq!(config.output_dir, PathBuf::from("output")); +} + +#[test] +fn test_builder_keep_temp_files_false() { + let config = RenderConfig::new("output") + .keep_temp_files(false); + + assert!(!config.keep_temp_files); +} + +#[test] +fn test_builder_lilypond_binary_str() { + let config = RenderConfig::new("output") + .lilypond_binary("/usr/local/bin/lilypond"); + + assert_eq!(config.lilypond_binary, PathBuf::from("/usr/local/bin/lilypond")); + assert_eq!(config.output_dir, PathBuf::from("output")); +} + +#[test] +fn test_builder_lilypond_binary_pathbuf() { + let lilypond_path = PathBuf::from("/custom/path/lilypond"); + let config = RenderConfig::new("output") + .lilypond_binary(lilypond_path.clone()); + + assert_eq!(config.lilypond_binary, lilypond_path); +} + +#[test] +fn test_builder_method_chaining() { + let config = RenderConfig::new("my-output") + .keep_temp_files(true) + .lilypond_binary("/usr/bin/lilypond"); + + assert_eq!(config.output_dir, PathBuf::from("my-output")); + assert!(config.keep_temp_files); + assert_eq!(config.lilypond_binary, PathBuf::from("/usr/bin/lilypond")); +} + +#[test] +fn test_builder_order_independence() { + // Test that builder methods work in any order + let config1 = RenderConfig::new("output") + .keep_temp_files(true) + .lilypond_binary("/usr/bin/lilypond"); + + let config2 = RenderConfig::new("output") + .lilypond_binary("/usr/bin/lilypond") + .keep_temp_files(true); + + assert_eq!(config1.output_dir, config2.output_dir); + assert_eq!(config1.keep_temp_files, config2.keep_temp_files); + assert_eq!(config1.lilypond_binary, config2.lilypond_binary); +} + +#[test] +fn test_config_is_clonable() { + let config1 = RenderConfig::new("output") + .keep_temp_files(true) + .lilypond_binary("/usr/bin/lilypond"); + + let config2 = config1.clone(); + + assert_eq!(config1.output_dir, config2.output_dir); + assert_eq!(config1.keep_temp_files, config2.keep_temp_files); + assert_eq!(config1.lilypond_binary, config2.lilypond_binary); +} + +#[test] +fn test_config_is_debuggable() { + let config = RenderConfig::new("output"); + let debug_str = format!("{:?}", config); + + // Should contain the struct name and fields + assert!(debug_str.contains("RenderConfig")); +} + +#[test] +fn test_multiple_configs_independent() { + let config1 = RenderConfig::new("output1") + .keep_temp_files(true); + + let config2 = RenderConfig::new("output2") + .keep_temp_files(false); + + // Verify they're independent + assert_eq!(config1.output_dir, PathBuf::from("output1")); + assert_eq!(config2.output_dir, PathBuf::from("output2")); + assert!(config1.keep_temp_files); + assert!(!config2.keep_temp_files); +} + +#[test] +fn test_config_with_relative_path() { + let config = RenderConfig::new("./relative/path"); + + assert_eq!(config.output_dir, PathBuf::from("./relative/path")); +} + +#[test] +fn test_config_with_absolute_path() { + let config = RenderConfig::new("/absolute/path"); + + assert_eq!(config.output_dir, PathBuf::from("/absolute/path")); +} + +#[test] +fn test_builder_overwrites_previous_values() { + let config = RenderConfig::new("output") + .keep_temp_files(true) + .keep_temp_files(false); // Override previous value + + assert!(!config.keep_temp_files); +} + +#[test] +fn test_config_fields_are_public() { + let config = RenderConfig::new("output"); + + // Should be able to access fields directly + let _output_dir = &config.output_dir; + let _keep_temp = config.keep_temp_files; + let _binary = &config.lilypond_binary; +} + +#[test] +fn test_default_values_are_sensible() { + let config = RenderConfig::default(); + + // Default output directory should be "output" + assert_eq!(config.output_dir, PathBuf::from("output")); + + // Should not keep temp files by default (for cleanliness) + assert!(!config.keep_temp_files); + + // Should use system lilypond by default + assert_eq!(config.lilypond_binary, PathBuf::from("lilypond")); +} + +#[test] +fn test_new_is_equivalent_to_default_with_custom_output() { + let config_new = RenderConfig::new("custom-output"); + let mut config_default = RenderConfig::default(); + config_default.output_dir = PathBuf::from("custom-output"); + + assert_eq!(config_new.output_dir, config_default.output_dir); + assert_eq!(config_new.keep_temp_files, config_default.keep_temp_files); + assert_eq!(config_new.lilypond_binary, config_default.lilypond_binary); +} |