Skip to content

Commit 34b45dc

Browse files
committed
style: apply cargo fmt to new code
1 parent dd2a141 commit 34b45dc

4 files changed

Lines changed: 19 additions & 35 deletions

File tree

src/helm_functions/math.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,11 @@ mod tests {
385385
#[test]
386386
fn test_math_add_returns_number_not_string() {
387387
let result = math_add(&[Value::Number(3.into()), Value::Number(5.into())]).unwrap();
388-
assert!(matches!(result, Value::Number(_)), "expected Number, got {:?}", result);
388+
assert!(
389+
matches!(result, Value::Number(_)),
390+
"expected Number, got {:?}",
391+
result
392+
);
389393
}
390394

391395
#[test]
@@ -494,7 +498,9 @@ mod tests {
494498
let result = addf(&[Value::Number(1.5.into()), Value::Number(3.7.into())]).unwrap();
495499
match result {
496500
Value::Number(n) => {
497-
let f = n.as_f64().expect("addf with fractional result must expose f64");
501+
let f = n
502+
.as_f64()
503+
.expect("addf with fractional result must expose f64");
498504
assert!((f - 5.2).abs() < 1e-9, "got {}", f);
499505
}
500506
_ => panic!("expected Number, got {:?}", result),

src/helm_functions/string.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ pub fn trunc(args: &[Value]) -> Result<Value, FuncError> {
220220
// Parse as i64 so that negative indices (Sprig/Helm semantics: trunc the
221221
// *last* N bytes when N is negative) are supported; the previous code
222222
// parsed as usize which made the `negative` branch dead.
223-
let trunc_index: i64 = trunc_index.parse().map_err(|_| {
224-
FuncError::Generic("Invalid number. Number must be an integer".to_string())
225-
})?;
223+
let trunc_index: i64 = trunc_index
224+
.parse()
225+
.map_err(|_| FuncError::Generic("Invalid number. Number must be an integer".to_string()))?;
226226
let value = &args.get(1).ok_or(FuncError::ExactlyXArgs(
227227
"This function requires exactly 2 arguments.".to_string(),
228228
2,

src/mows_functions/crypto.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,9 @@ pub fn random_string(args: &[Value]) -> Result<Value, FuncError> {
6262
2,
6363
))?;
6464

65-
let length: u16 = length
66-
.to_string()
67-
.replace(' ', "")
68-
.parse()
69-
.map_err(|_| {
70-
FuncError::Generic(
71-
"randomString: length must be an integer in 0..=65535".to_string(),
72-
)
73-
})?;
65+
let length: u16 = length.to_string().replace(' ', "").parse().map_err(|_| {
66+
FuncError::Generic("randomString: length must be an integer in 0..=65535".to_string())
67+
})?;
7468

7569
let mut charset: Vec<u8> = b"".to_vec();
7670
if method.contains('A') {
@@ -89,8 +83,7 @@ pub fn random_string(args: &[Value]) -> Result<Value, FuncError> {
8983
// charset explicitly instead of crashing.
9084
if charset.is_empty() {
9185
return Err(FuncError::Generic(
92-
"randomString: method must contain at least one of 'A', 'a', '0', '%'"
93-
.to_string(),
86+
"randomString: method must contain at least one of 'A', 'a', '0', '%'".to_string(),
9487
));
9588
}
9689
let mut rng = rand::rng();

tests/panic_audit.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,7 @@ fn coalesce_with_integers_does_not_panic() {
150150
fn ternary_with_integer_condition_does_not_panic() {
151151
let mut ctx: HashMap<String, Value> = HashMap::new();
152152
ctx.insert("cond".to_string(), Value::from(1i64));
153-
let out = render(
154-
r#"{{ ternary "yes" "no" .cond }}"#,
155-
Value::from(ctx),
156-
)
157-
.unwrap();
153+
let out = render(r#"{{ ternary "yes" "no" .cond }}"#, Value::from(ctx)).unwrap();
158154
// Helm ternary returns the first arg when condition is truthy.
159155
assert_eq!(out, "yes");
160156
}
@@ -213,11 +209,7 @@ fn add_integer_from_json_produces_integer() {
213209

214210
#[test]
215211
fn add_integer_from_yaml_produces_integer() {
216-
let out = render(
217-
r#"{{ $d := fromYaml "n: 5" }}{{ add $d.n 3 }}"#,
218-
Value::Nil,
219-
)
220-
.unwrap();
212+
let out = render(r#"{{ $d := fromYaml "n: 5" }}{{ add $d.n 3 }}"#, Value::Nil).unwrap();
221213
assert_eq!(out, "8");
222214
}
223215

@@ -251,11 +243,7 @@ fn math_pipeline_with_default_does_not_panic_on_integer_context() {
251243
// This is the exact shape that previously crashed `value_is_truthy`.
252244
let mut ctx: HashMap<String, Value> = HashMap::new();
253245
ctx.insert("count".to_string(), Value::from(3i64));
254-
let out = render(
255-
r#"{{ .count | default 1 | add 10 }}"#,
256-
Value::from(ctx),
257-
)
258-
.unwrap();
246+
let out = render(r#"{{ .count | default 1 | add 10 }}"#, Value::from(ctx)).unwrap();
259247
assert_eq!(out, "13");
260248
}
261249

@@ -290,10 +278,7 @@ mod mows {
290278
fn random_string_empty_method_returns_error_not_panic() {
291279
// Previously panicked in `rng.random_range(0..0)` because the
292280
// charset stayed empty.
293-
let result = random_string(&[
294-
Value::String("".to_string()),
295-
Value::Number(10.into()),
296-
]);
281+
let result = random_string(&[Value::String("".to_string()), Value::Number(10.into())]);
297282
assert!(result.is_err(), "expected error, got {:?}", result);
298283
}
299284
}

0 commit comments

Comments
 (0)