Skip to content

Commit 5f5ae0d

Browse files
committed
Fix test case
1 parent 3325d1e commit 5f5ae0d

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

libs/sheet/src/theme.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -352,24 +352,24 @@ impl<'de> Deserialize<'de> for TokenValues {
352352
Value::String(s) => Ok(Self(vec![Some(s.clone())])),
353353
Value::Number(n) => Ok(Self(vec![Some(n.to_string())])),
354354
Value::Array(arr) => {
355-
let mut result = Vec::with_capacity(arr.len());
356-
for item in arr {
357-
result.push(match item {
358-
Value::Null => None,
359-
Value::String(s) => Some(s.clone()),
360-
Value::Number(n) => Some(n.to_string()),
361-
_ => {
362-
return Err(serde::de::Error::custom(format!(
363-
"Invalid token value: {item:?}"
364-
)));
355+
let result = arr
356+
.iter()
357+
.map(|item| match item {
358+
Value::Null => Ok(None),
359+
Value::String(s) => Ok(Some(s.clone())),
360+
Value::Number(n) => Ok(Some(n.to_string())),
361+
other => {
362+
let msg = format!("Invalid token value: {other:?}");
363+
Err(serde::de::Error::custom(msg))
365364
}
366-
});
367-
}
365+
})
366+
.collect::<Result<Vec<_>, _>>()?;
368367
Ok(Self(result))
369368
}
370-
_ => Err(serde::de::Error::custom(format!(
371-
"Expected string, number, or array, got: {value:?}"
372-
))),
369+
_ => {
370+
let msg = format!("Expected string, number, or array, got: {value:?}");
371+
Err(serde::de::Error::custom(msg))
372+
}
373373
}
374374
}
375375
}
@@ -699,10 +699,14 @@ impl Theme {
699699

700700
// Sort variants: default first, then alphabetical
701701
let mut sorted_variants: Vec<_> = themes.iter().collect();
702-
sorted_variants.sort_by(|a, b| match (a.0 == &default_key, b.0 == &default_key) {
703-
(true, _) => Ordering::Less,
704-
(_, true) => Ordering::Greater,
705-
_ => a.0.cmp(b.0),
702+
sorted_variants.sort_by(|a, b| {
703+
if a.0 == &default_key {
704+
Ordering::Less
705+
} else if b.0 == &default_key {
706+
Ordering::Greater
707+
} else {
708+
a.0.cmp(b.0)
709+
}
706710
});
707711

708712
for (variant_name, token_theme) in &sorted_variants {

0 commit comments

Comments
 (0)