Skip to content

Commit 2b46b3f

Browse files
committed
test: add more tests for tests/integration_tests/version/main/combinations.rs
1 parent 6552c06 commit 2b46b3f

File tree

2 files changed

+277
-0
lines changed

2 files changed

+277
-0
lines changed
Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
use rstest::rstest;
2+
use zerv::test_utils::{
3+
ZervFixture,
4+
ZervSchemaFixture,
5+
};
6+
use zerv::version::PreReleaseLabel;
7+
8+
use crate::util::TestCommand;
9+
10+
mod schema_format {
11+
use super::*;
12+
13+
#[rstest]
14+
#[case::standard_semver("zerv-standard", "semver", "1.2.3")]
15+
#[case::standard_pep440("zerv-standard", "pep440", "1.2.3")]
16+
#[case::calver_semver("zerv-calver", "semver", "21.0.0")]
17+
#[case::calver_pep440("zerv-calver", "pep440", "21")]
18+
fn test_preset_schema_with_output_format(
19+
#[case] schema: &str,
20+
#[case] format: &str,
21+
#[case] expected: &str,
22+
) {
23+
let zerv_ron = if schema == "zerv-calver" {
24+
ZervFixture::new()
25+
.with_version(2025, 10, 21)
26+
.with_calver_tier_1()
27+
.build()
28+
.to_string()
29+
} else {
30+
ZervFixture::new()
31+
.with_version(1, 2, 3)
32+
.with_standard_tier_1()
33+
.build()
34+
.to_string()
35+
};
36+
37+
let result = TestCommand::run_with_stdin(
38+
&format!("version --source stdin --schema {schema} --output-format {format}"),
39+
zerv_ron,
40+
);
41+
42+
assert_eq!(result.trim(), expected);
43+
}
44+
45+
#[rstest]
46+
#[case::epoch_pep440("3!1.2", "pep440")]
47+
#[case::epoch_semver("1.2.0-epoch.3", "semver")]
48+
fn test_custom_schema_with_epoch_and_format(#[case] expected: &str, #[case] format: &str) {
49+
let schema_ron = ZervSchemaFixture::empty()
50+
.with_major_minor()
51+
.with_epoch_in_extra_core()
52+
.build()
53+
.to_string();
54+
55+
let zerv_ron = ZervFixture::new()
56+
.with_version(1, 2, 0)
57+
.with_epoch(3)
58+
.build()
59+
.to_string();
60+
61+
let result = TestCommand::run_with_stdin(
62+
&format!("version --source stdin --schema-ron '{schema_ron}' --output-format {format}"),
63+
zerv_ron,
64+
);
65+
66+
assert_eq!(result.trim(), expected);
67+
}
68+
}
69+
70+
mod schema_template {
71+
use super::*;
72+
73+
#[rstest]
74+
#[case::standard("zerv-standard", "v{{major}}.{{minor}}.{{patch}}", "v1.2.3")]
75+
#[case::calver("zerv-calver", "{{major}}-{{minor}}-{{patch}}", "2025-10-21")]
76+
fn test_preset_schema_with_template(
77+
#[case] schema: &str,
78+
#[case] template: &str,
79+
#[case] expected: &str,
80+
) {
81+
let zerv_ron = if schema == "zerv-calver" {
82+
ZervFixture::new()
83+
.with_version(2025, 10, 21)
84+
.with_calver_tier_1()
85+
.build()
86+
.to_string()
87+
} else {
88+
ZervFixture::new()
89+
.with_version(1, 2, 3)
90+
.with_standard_tier_1()
91+
.build()
92+
.to_string()
93+
};
94+
95+
let result = TestCommand::run_with_stdin(
96+
&format!(r#"version --source stdin --schema {schema} --output-template "{template}""#),
97+
zerv_ron,
98+
);
99+
100+
assert_eq!(result.trim(), expected);
101+
}
102+
103+
#[test]
104+
fn test_custom_schema_with_template_and_helpers() {
105+
let schema_ron = ZervSchemaFixture::empty()
106+
.with_major_minor_patch()
107+
.with_epoch_in_extra_core()
108+
.build()
109+
.to_string();
110+
111+
let zerv_ron = ZervFixture::new()
112+
.with_version(1, 2, 3)
113+
.with_epoch(2)
114+
.with_vcs_data(
115+
None,
116+
None,
117+
Some("feature/test".to_string()),
118+
None,
119+
None,
120+
None,
121+
None,
122+
)
123+
.build()
124+
.to_string();
125+
126+
let result = TestCommand::run_with_stdin(
127+
&format!(
128+
r#"version --source stdin --schema-ron '{schema_ron}' --output-template "{{{{epoch}}}}:{{{{semver}}}}-{{{{sanitize bumped_branch}}}}""#
129+
),
130+
zerv_ron,
131+
);
132+
133+
assert_eq!(result.trim(), "2:1.2.3-epoch.2-feature.test");
134+
}
135+
}
136+
137+
mod format_prefix {
138+
use super::*;
139+
140+
#[rstest]
141+
#[case::semver("semver", "v", "v1.2.3")]
142+
#[case::pep440("pep440", "v", "v1.2.3")]
143+
#[case::semver_release("semver", "release-", "release-1.2.3")]
144+
fn test_output_format_with_prefix(
145+
#[case] format: &str,
146+
#[case] prefix: &str,
147+
#[case] expected: &str,
148+
) {
149+
let zerv_ron = ZervFixture::new().with_version(1, 2, 3).build().to_string();
150+
151+
let result = TestCommand::run_with_stdin(
152+
&format!(
153+
r#"version --source stdin --output-format {format} --output-prefix "{prefix}""#
154+
),
155+
zerv_ron,
156+
);
157+
158+
assert_eq!(result.trim(), expected);
159+
}
160+
161+
#[test]
162+
fn test_epoch_with_prefix_pep440() {
163+
let zerv_ron = ZervFixture::new()
164+
.with_version(1, 2, 3)
165+
.with_epoch(5)
166+
.build()
167+
.to_string();
168+
169+
let result = TestCommand::run_with_stdin(
170+
"version --source stdin --output-format pep440 --output-prefix v",
171+
zerv_ron,
172+
);
173+
174+
assert_eq!(result.trim(), "v5!1.2.3");
175+
}
176+
}
177+
178+
mod template_helpers {
179+
use super::*;
180+
181+
#[test]
182+
fn test_multiple_format_helpers_in_template() {
183+
let zerv_ron = ZervFixture::new()
184+
.with_version(3, 2, 1)
185+
.with_pre_release(PreReleaseLabel::Rc, Some(2))
186+
.build()
187+
.to_string();
188+
189+
let result = TestCommand::run_with_stdin(
190+
r#"version --source stdin --output-template "SemVer={{semver}},PEP440={{pep440}},Raw={{major}}.{{minor}}.{{patch}}""#,
191+
zerv_ron,
192+
);
193+
194+
assert_eq!(result.trim(), "SemVer=3.2.1-rc.2,PEP440=3.2.1rc2,Raw=3.2.1");
195+
}
196+
197+
#[test]
198+
fn test_template_with_sanitize_helper() {
199+
let zerv_ron = ZervFixture::new()
200+
.with_version(1, 0, 0)
201+
.with_vcs_data(
202+
None,
203+
None,
204+
Some("feature/test-branch".to_string()),
205+
None,
206+
None,
207+
None,
208+
None,
209+
)
210+
.build()
211+
.to_string();
212+
213+
let result = TestCommand::run_with_stdin(
214+
r#"version --source stdin --output-template "{{semver}}-{{sanitize bumped_branch}}""#,
215+
zerv_ron,
216+
);
217+
218+
assert_eq!(result.trim(), "1.0.0-feature.test.branch");
219+
}
220+
}
221+
222+
mod multi_option {
223+
use super::*;
224+
225+
#[test]
226+
fn test_custom_schema_template_complex_workflow() {
227+
let schema_ron = ZervSchemaFixture::empty()
228+
.with_major_minor_patch()
229+
.build()
230+
.to_string();
231+
232+
let zerv_ron = ZervFixture::new().with_version(2, 5, 1).build().to_string();
233+
234+
let result = TestCommand::run_with_stdin(
235+
&format!(
236+
r#"version --source stdin --schema-ron '{schema_ron}' --output-template "release-{{{{major}}}}.{{{{minor}}}}.{{{{patch}}}}""#
237+
),
238+
zerv_ron,
239+
);
240+
241+
assert_eq!(result.trim(), "release-2.5.1");
242+
}
243+
244+
#[test]
245+
fn test_schema_format_prefix_together() {
246+
let zerv_ron = ZervFixture::new()
247+
.with_version(1, 0, 0)
248+
.with_standard_tier_1()
249+
.build()
250+
.to_string();
251+
252+
let result = TestCommand::run_with_stdin(
253+
"version --source stdin --schema zerv-standard --output-format semver --output-prefix v",
254+
zerv_ron,
255+
);
256+
257+
assert_eq!(result.trim(), "v1.0.0");
258+
}
259+
260+
#[rstest]
261+
#[case::post_only("2.0.0.post3")]
262+
fn test_extended_version_with_template(#[case] expected: &str) {
263+
let zerv_ron = ZervFixture::new()
264+
.with_version(2, 0, 0)
265+
.with_post(3)
266+
.build()
267+
.to_string();
268+
269+
let result = TestCommand::run_with_stdin(
270+
r#"version --source stdin --output-template "{{pep440}}""#,
271+
zerv_ron,
272+
);
273+
274+
assert_eq!(result.trim(), expected);
275+
}
276+
}

tests/integration_tests/version/main/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod combinations;
12
pub mod directory;
23
pub mod formats;
34
pub mod schemas;

0 commit comments

Comments
 (0)