Skip to content

Commit fd90596

Browse files
authored
refactor: clean code to solve sonarcloud issue (#108)
1 parent d380d32 commit fd90596

File tree

21 files changed

+345
-414
lines changed

21 files changed

+345
-414
lines changed

src/cli/utils/format_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ mod tests {
402402
.with_post(1)
403403
.with_dev(1)
404404
.with_build(Component::Str("local".to_string()))
405-
.with_build(Component::Int(1))
405+
.with_build(Component::UInt(1))
406406
.build()
407407
.clone();
408408
let ron_string = complex_zerv.to_string();

src/cli/version/args/tests/overrides_tests.rs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -125,66 +125,6 @@ fn test_validate_overrides_no_conflicts() {
125125
assert!(Validation::validate_overrides(&config).is_ok());
126126
}
127127

128-
#[test]
129-
fn test_validate_overrides_dirty_conflicts() {
130-
// Test conflicting dirty flags
131-
let config = OverridesConfig::try_parse_from(["version", "--dirty", "--no-dirty"]).unwrap();
132-
let result = Validation::validate_overrides(&config);
133-
assert!(result.is_err());
134-
135-
let error = result.unwrap_err();
136-
assert!(matches!(
137-
error,
138-
crate::error::ZervError::ConflictingOptions(_)
139-
));
140-
assert!(error.to_string().contains("--dirty"));
141-
assert!(error.to_string().contains("--no-dirty"));
142-
assert!(error.to_string().contains("conflicting options"));
143-
}
144-
145-
#[test]
146-
fn test_validate_overrides_clean_conflicts() {
147-
// Test --clean with --distance
148-
let config =
149-
OverridesConfig::try_parse_from(["version", "--clean", "--distance", "5"]).unwrap();
150-
let result = Validation::validate_overrides(&config);
151-
assert!(result.is_err());
152-
153-
let error = result.unwrap_err();
154-
assert!(matches!(
155-
error,
156-
crate::error::ZervError::ConflictingOptions(_)
157-
));
158-
assert!(error.to_string().contains("--clean"));
159-
assert!(error.to_string().contains("--distance"));
160-
161-
// Test --clean with --dirty
162-
let config = OverridesConfig::try_parse_from(["version", "--clean", "--dirty"]).unwrap();
163-
let result = Validation::validate_overrides(&config);
164-
assert!(result.is_err());
165-
166-
let error = result.unwrap_err();
167-
assert!(matches!(
168-
error,
169-
crate::error::ZervError::ConflictingOptions(_)
170-
));
171-
assert!(error.to_string().contains("--clean"));
172-
assert!(error.to_string().contains("--dirty"));
173-
174-
// Test --clean with --no-dirty
175-
let config = OverridesConfig::try_parse_from(["version", "--clean", "--no-dirty"]).unwrap();
176-
let result = Validation::validate_overrides(&config);
177-
assert!(result.is_err());
178-
179-
let error = result.unwrap_err();
180-
assert!(matches!(
181-
error,
182-
crate::error::ZervError::ConflictingOptions(_)
183-
));
184-
assert!(error.to_string().contains("--clean"));
185-
assert!(error.to_string().contains("--no-dirty"));
186-
}
187-
188128
#[test]
189129
fn test_validate_overrides_clean_with_non_conflicting_options() {
190130
// Test --clean with options that should NOT conflict

src/test_utils/zerv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
pub mod common_fixtures;
21
pub mod schema;
32
pub mod vars;
43
#[allow(clippy::module_inception)]
54
pub mod zerv;
65
pub mod zerv_calver;
6+
pub mod zerv_common;
77
pub mod zerv_pep440;
88
pub mod zerv_semver;
99

src/test_utils/zerv/zerv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl ZervFixture {
133133
// Clear existing core and rebuild with integers
134134
let mut core = Vec::new();
135135
for value in values {
136-
core.push(Component::Int(value));
136+
core.push(Component::UInt(value));
137137
}
138138
self.zerv.schema.set_core(core).unwrap();
139139
self
@@ -177,7 +177,7 @@ impl ZervFixture {
177177

178178
/// Create with empty schema - chainable
179179
pub fn with_empty_schema(mut self) -> Self {
180-
self.zerv.schema.set_core(vec![Component::Int(1)]).unwrap(); // Need at least one component
180+
self.zerv.schema.set_core(vec![Component::UInt(1)]).unwrap(); // Need at least one component
181181
self.zerv.schema.set_extra_core(vec![]).unwrap();
182182
self.zerv.schema.set_build(vec![]).unwrap();
183183
self

src/test_utils/zerv/zerv_calver.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use crate::version::zerv::{
88
};
99

1010
/// CalVer helper functions (demonstrating VarTimestamp usage)
11-
pub fn calver_yy_mm_patch() -> Zerv {
11+
fn calver_year_month_patch(year_pattern: &str, patch_value: u64) -> Zerv {
1212
Zerv {
1313
schema: ZervSchema::new_with_precedence(
1414
vec![
15-
Component::Var(Var::Timestamp("YY".to_string())),
15+
Component::Var(Var::Timestamp(year_pattern.to_string())),
1616
Component::Var(Var::Timestamp("MM".to_string())),
1717
Component::Var(Var::Patch),
1818
],
@@ -22,32 +22,19 @@ pub fn calver_yy_mm_patch() -> Zerv {
2222
)
2323
.unwrap(),
2424
vars: ZervVars {
25-
patch: Some(5),
25+
patch: Some(patch_value),
2626
last_timestamp: Some(1710547200), // 2024-03-15
2727
..Default::default()
2828
},
2929
}
3030
}
3131

32+
pub fn calver_yy_mm_patch() -> Zerv {
33+
calver_year_month_patch("YY", 5)
34+
}
35+
3236
pub fn calver_yyyy_mm_patch() -> Zerv {
33-
Zerv {
34-
schema: ZervSchema::new_with_precedence(
35-
vec![
36-
Component::Var(Var::Timestamp("YYYY".to_string())),
37-
Component::Var(Var::Timestamp("MM".to_string())),
38-
Component::Var(Var::Patch),
39-
],
40-
vec![],
41-
vec![],
42-
PrecedenceOrder::default(),
43-
)
44-
.unwrap(),
45-
vars: ZervVars {
46-
patch: Some(1),
47-
last_timestamp: Some(1710547200),
48-
..Default::default()
49-
},
50-
}
37+
calver_year_month_patch("YYYY", 1)
5138
}
5239

5340
pub fn calver_with_timestamp_build() -> Zerv {

src/test_utils/zerv/common_fixtures.rs renamed to src/test_utils/zerv/zerv_common.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use crate::version::zerv::{
66
};
77

88
/// Common base fixture builders shared between PEP440 and SemVer
9-
pub struct CommonFixtures;
9+
pub struct ZervCommon;
1010

11-
impl CommonFixtures {
11+
impl ZervCommon {
1212
// Base versions
1313
pub fn v1_2_3() -> ZervFixture {
1414
ZervFixture::new().with_version(1, 2, 3)
@@ -118,25 +118,25 @@ impl CommonFixtures {
118118
pub fn v1_0_0_build() -> ZervFixture {
119119
Self::v1_0_0()
120120
.with_build(Component::Str("build".to_string()))
121-
.with_build(Component::Int(123))
121+
.with_build(Component::UInt(123))
122122
}
123123

124124
pub fn v1_0_0_a1_build() -> ZervFixture {
125125
Self::v1_0_0_a1()
126126
.with_build(Component::Str("build".to_string()))
127-
.with_build(Component::Int(123))
127+
.with_build(Component::UInt(123))
128128
}
129129

130130
pub fn v1_0_0_e1_build() -> ZervFixture {
131131
Self::v1_0_0_e1()
132132
.with_build(Component::Str("build".to_string()))
133-
.with_build(Component::Int(123))
133+
.with_build(Component::UInt(123))
134134
}
135135

136136
pub fn v1_0_0_post1_build() -> ZervFixture {
137137
Self::v1_0_0_post1()
138138
.with_build(Component::Str("build".to_string()))
139-
.with_build(Component::Int(456))
139+
.with_build(Component::UInt(456))
140140
}
141141

142142
pub fn v1_0_0_e2_a1_build() -> ZervFixture {
@@ -149,7 +149,7 @@ impl CommonFixtures {
149149
Self::v1_0_0()
150150
.with_build(Component::Str("foo".to_string()))
151151
.with_build(Component::Str("bar".to_string()))
152-
.with_build(Component::Int(123))
152+
.with_build(Component::UInt(123))
153153
}
154154

155155
// VarField build metadata
@@ -177,7 +177,7 @@ impl CommonFixtures {
177177
Self::v1_2_3()
178178
.with_build(Component::Str("ubuntu".to_string()))
179179
.with_build(Component::Str("20".to_string()))
180-
.with_build(Component::Int(4))
180+
.with_build(Component::UInt(4))
181181
}
182182

183183
// Custom field variants
@@ -223,17 +223,17 @@ impl CommonFixtures {
223223
.with_pre_release(PreReleaseLabel::Alpha, Some(1))
224224
.with_post(2)
225225
.with_core(Component::Var(Var::Custom("core_custom".to_string())))
226-
.with_core(Component::Int(99))
226+
.with_core(Component::UInt(99))
227227
.with_extra_core(Component::Var(Var::Custom("extra_custom".to_string())))
228228
.with_extra_core(Component::Str("literal".to_string()))
229-
.with_extra_core(Component::Int(42))
229+
.with_extra_core(Component::UInt(42))
230230
.with_build(Component::Var(Var::BumpedBranch))
231231
.with_build(Component::Var(Var::Distance))
232232
.with_build(Component::Var(Var::BumpedCommitHashShort))
233233
.with_build(Component::Var(Var::Dirty))
234234
.with_build(Component::Var(Var::Custom("build_custom".to_string())))
235235
.with_build(Component::Str("build".to_string()))
236-
.with_build(Component::Int(123))
236+
.with_build(Component::UInt(123))
237237
.with_branch("feature/complex-test".to_string())
238238
.with_distance(7)
239239
.with_commit_hash("abcdef1234567890".to_string())

0 commit comments

Comments
 (0)