Skip to content

Commit 8bcc258

Browse files
committed
fmt: cargo
1 parent 2fce307 commit 8bcc258

File tree

5 files changed

+106
-40
lines changed

5 files changed

+106
-40
lines changed

float-pigment-css-macro/src/style_syntax.rs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -860,15 +860,37 @@ impl ToTokens for StyleSyntaxDefinition {
860860
a.cmp(b)
861861
});
862862
let supported_property_count = supported_properties.len();
863-
let supported_property_names = supported_properties.iter().map(|x| x.name.as_ref().unwrap());
863+
let supported_property_names = supported_properties
864+
.iter()
865+
.map(|x| x.name.as_ref().unwrap());
864866
let mut style_doc = String::new();
865867
writeln!(&mut style_doc, "The supported CSS property names.\n").unwrap();
866-
writeln!(&mut style_doc, "This list is sorted, so it is safe to do binary search on it.\n").unwrap();
867-
writeln!(&mut style_doc, "Note that this is just a simple list of basic parsing rules.\n").unwrap();
868+
writeln!(
869+
&mut style_doc,
870+
"This list is sorted, so it is safe to do binary search on it.\n"
871+
)
872+
.unwrap();
873+
writeln!(
874+
&mut style_doc,
875+
"Note that this is just a simple list of basic parsing rules.\n"
876+
)
877+
.unwrap();
868878
writeln!(&mut style_doc, "* Some properties in this list are shorthand properties that cannot be found in the [Property] enum.").unwrap();
869-
writeln!(&mut style_doc, "* Parsing rules of some properties are slightly different from the web standard.").unwrap();
870-
writeln!(&mut style_doc, "\nSee the table below for more information about all supported properties.\n").unwrap();
871-
writeln!(&mut style_doc, "| Property Name | Related Property Variant | Major Value Options |").unwrap();
879+
writeln!(
880+
&mut style_doc,
881+
"* Parsing rules of some properties are slightly different from the web standard."
882+
)
883+
.unwrap();
884+
writeln!(
885+
&mut style_doc,
886+
"\nSee the table below for more information about all supported properties.\n"
887+
)
888+
.unwrap();
889+
writeln!(
890+
&mut style_doc,
891+
"| Property Name | Related Property Variant | Major Value Options |"
892+
)
893+
.unwrap();
872894
writeln!(&mut style_doc, "| ---- | ---- | ---- |").unwrap();
873895
let table_list_a = supported_properties
874896
.iter()
@@ -879,7 +901,11 @@ impl ToTokens for StyleSyntaxDefinition {
879901
for x in table_list_a.chain(table_list_b) {
880902
let name = x.name.as_ref().unwrap();
881903
let non_standard = name.starts_with("-");
882-
let name_col = if non_standard { format!("*`{}`*", name) } else { format!("`{}`", name) };
904+
let name_col = if non_standard {
905+
format!("*`{}`*", name)
906+
} else {
907+
format!("`{}`", name)
908+
};
883909
let mut doc_col = String::new();
884910
let mut options_col = vec![];
885911
if let StyleSyntaxValueItem::Assign(variant, v) = &x.value {
@@ -895,7 +921,14 @@ impl ToTokens for StyleSyntaxDefinition {
895921
}
896922
}
897923
options_col.sort();
898-
writeln!(&mut style_doc, "| {} | {} | {} |", name_col, doc_col, options_col.join("<br>")).unwrap();
924+
writeln!(
925+
&mut style_doc,
926+
"| {} | {} | {} |",
927+
name_col,
928+
doc_col,
929+
options_col.join("<br>")
930+
)
931+
.unwrap();
899932
}
900933
tokens.append_all(quote! {
901934
#[doc = #style_doc]

float-pigment-css/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
//! 1. Merge the `MatchedRuleList` into `NodeProperties` with `MatchedRuleList::merge_node_properties`.
1515
//!
1616
//! The result `NodeProperties` contains all supported CSS properties.
17-
//!
17+
//!
1818
//! ### Supported CSS Features
19-
//!
19+
//!
2020
//! The supported selectors can be found in [StyleQuery] docs.
21-
//!
21+
//!
2222
//! The supported media features can be found in [MediaQueryStatus] docs.
23-
//!
23+
//!
2424
//! The supported style properties can be found in [SUPPORTED_CSS_PROPERTY_NAMES](crate::property::SUPPORTED_CSS_PROPERTY_NAMES) docs.
2525
//!
2626
//! ### The Binary Format

float-pigment-css/tests/selector.rs

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,42 @@ fn attribute_selector() {
306306
let node_properties = query(&ssg, "a", "", [""], []);
307307
assert_eq!(node_properties.height(), Length::Undefined);
308308
assert_eq!(node_properties.width(), Length::Undefined);
309-
let node_properties = query(&ssg, "a", "", [""], [("title".into(), "".into()), ("class".into(), "logo1 logo2".into())]);
309+
let node_properties = query(
310+
&ssg,
311+
"a",
312+
"",
313+
[""],
314+
[
315+
("title".into(), "".into()),
316+
("class".into(), "logo1 logo2".into()),
317+
],
318+
);
310319
assert_eq!(node_properties.height(), Length::Px(100.));
311320
assert_eq!(node_properties.width(), Length::Undefined);
312-
let node_properties = query(&ssg, "a", "", [""], [("title".into(), "".into()), ("class".into(), "logo1 logo logo2".into())]);
321+
let node_properties = query(
322+
&ssg,
323+
"a",
324+
"",
325+
[""],
326+
[
327+
("title".into(), "".into()),
328+
("class".into(), "logo1 logo logo2".into()),
329+
],
330+
);
313331
assert_eq!(node_properties.height(), Length::Px(100.));
314332
assert_eq!(node_properties.width(), Length::Px(300.));
315333
let node_properties = query(&ssg, "a", "", ["b"], [("title".into(), "".into())]);
316334
assert_eq!(node_properties.height(), Length::Px(100.));
317335
let node_properties = query(&ssg, "", "", [], [("title".into(), "".into())]);
318336
assert_eq!(node_properties.height(), Length::Undefined);
319337

320-
let node_properties = query(&ssg, "a", "", [], [("href".into(), "https://example.org".into())]);
338+
let node_properties = query(
339+
&ssg,
340+
"a",
341+
"",
342+
[],
343+
[("href".into(), "https://example.org".into())],
344+
);
321345
assert_eq!(node_properties.height(), Length::Undefined);
322346
assert_eq!(node_properties.width(), Length::Undefined);
323347
assert_eq!(node_properties.min_height(), Length::Px(100.));
@@ -329,9 +353,27 @@ fn attribute_selector() {
329353
assert_eq!(node_properties.height(), Length::Px(13.));
330354
let node_properties = query(&ssg, "button", "a", [], [("type".into(), "warn".into())]);
331355
assert_eq!(node_properties.height(), Length::Px(12.));
332-
let node_properties = query(&ssg, "button", "", [], [("type".into(), "primary".into()), ("size".into(), "mini".into())]);
356+
let node_properties = query(
357+
&ssg,
358+
"button",
359+
"",
360+
[],
361+
[
362+
("type".into(), "primary".into()),
363+
("size".into(), "mini".into()),
364+
],
365+
);
333366
assert_eq!(node_properties.height(), Length::Px(11.));
334-
let node_properties = query(&ssg, "button", "", [], [("type".into(), "warm".into()), ("size".into(), "mini".into())]);
367+
let node_properties = query(
368+
&ssg,
369+
"button",
370+
"",
371+
[],
372+
[
373+
("type".into(), "warm".into()),
374+
("size".into(), "mini".into()),
375+
],
376+
);
335377
assert_eq!(node_properties.height(), Length::Px(10.));
336378
}
337379

float-pigment-css/tests/style_sheet_group.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,7 @@ fn scopes_in_tag_name_and_id() {
347347
);
348348
assert_eq!(node_properties.width(), Length::Px(0.));
349349
assert_eq!(node_properties.height(), Length::Undefined);
350-
let query = StyleQuery::single(
351-
NonZeroUsize::new(1),
352-
None,
353-
None,
354-
"view",
355-
"i",
356-
&classes,
357-
);
350+
let query = StyleQuery::single(NonZeroUsize::new(1), None, None, "view", "i", &classes);
358351
let mut node_properties = NodeProperties::new(None);
359352
ssg.query_single(
360353
query,
@@ -363,14 +356,7 @@ fn scopes_in_tag_name_and_id() {
363356
);
364357
assert_eq!(node_properties.width(), Length::Px(1.));
365358
assert_eq!(node_properties.height(), Length::Undefined);
366-
let query = StyleQuery::single(
367-
NonZeroUsize::new(2),
368-
None,
369-
None,
370-
"view",
371-
"i",
372-
&classes,
373-
);
359+
let query = StyleQuery::single(NonZeroUsize::new(2), None, None, "view", "i", &classes);
374360
let mut node_properties = NodeProperties::new(None);
375361
ssg.query_single(
376362
&query,

float-pigment-css/tests/utils/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::num::NonZeroUsize;
22

3+
use float_pigment_css::query::{StyleNode, StyleNodeAttributeCaseSensitivity};
34
use float_pigment_css::{
45
length_num::LengthNum, property::*, MediaQueryStatus, StyleQuery, StyleSheet, StyleSheetGroup,
56
};
6-
use float_pigment_css::query::{StyleNode, StyleNodeAttributeCaseSensitivity};
77

88
pub struct StyleQueryTest<'a> {
99
pub style_scope: Option<NonZeroUsize>,
@@ -18,7 +18,7 @@ pub struct StyleQueryTest<'a> {
1818
impl<'a> StyleNode for StyleQueryTest<'a> {
1919
type Class = (String, Option<NonZeroUsize>);
2020
type ClassIter<'c>
21-
= core::slice::Iter<'c, Self::Class>
21+
= core::slice::Iter<'c, Self::Class>
2222
where
2323
'a: 'c;
2424

@@ -50,11 +50,16 @@ impl<'a> StyleNode for StyleQueryTest<'a> {
5050
self.attributes
5151
.iter()
5252
.find(|(n, _)| n == name)
53-
.map(|(_, v)| (v.as_str(), match name {
54-
"id" | "class" => StyleNodeAttributeCaseSensitivity::CaseSensitive,
55-
"type" | "size" => StyleNodeAttributeCaseSensitivity::CaseInsensitive,
56-
_ => StyleNodeAttributeCaseSensitivity::CaseSensitive,
57-
}))
53+
.map(|(_, v)| {
54+
(
55+
v.as_str(),
56+
match name {
57+
"id" | "class" => StyleNodeAttributeCaseSensitivity::CaseSensitive,
58+
"type" | "size" => StyleNodeAttributeCaseSensitivity::CaseInsensitive,
59+
_ => StyleNodeAttributeCaseSensitivity::CaseSensitive,
60+
},
61+
)
62+
})
5863
}
5964
}
6065

0 commit comments

Comments
 (0)