summaryrefslogtreecommitdiff
path: root/morphology-img/tests/config.rs
blob: 9b47ed58a154b128826322e1ee564c007d204c28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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);
}