Skip to content

Commit

Permalink
fmt: cargo
Browse files Browse the repository at this point in the history
  • Loading branch information
LastLeaf committed Jan 24, 2025
1 parent 2fce307 commit 8bcc258
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 40 deletions.
49 changes: 41 additions & 8 deletions float-pigment-css-macro/src/style_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,15 +860,37 @@ impl ToTokens for StyleSyntaxDefinition {
a.cmp(b)
});
let supported_property_count = supported_properties.len();
let supported_property_names = supported_properties.iter().map(|x| x.name.as_ref().unwrap());
let supported_property_names = supported_properties
.iter()
.map(|x| x.name.as_ref().unwrap());
let mut style_doc = String::new();
writeln!(&mut style_doc, "The supported CSS property names.\n").unwrap();
writeln!(&mut style_doc, "This list is sorted, so it is safe to do binary search on it.\n").unwrap();
writeln!(&mut style_doc, "Note that this is just a simple list of basic parsing rules.\n").unwrap();
writeln!(
&mut style_doc,
"This list is sorted, so it is safe to do binary search on it.\n"
)
.unwrap();
writeln!(
&mut style_doc,
"Note that this is just a simple list of basic parsing rules.\n"
)
.unwrap();
writeln!(&mut style_doc, "* Some properties in this list are shorthand properties that cannot be found in the [Property] enum.").unwrap();
writeln!(&mut style_doc, "* Parsing rules of some properties are slightly different from the web standard.").unwrap();
writeln!(&mut style_doc, "\nSee the table below for more information about all supported properties.\n").unwrap();
writeln!(&mut style_doc, "| Property Name | Related Property Variant | Major Value Options |").unwrap();
writeln!(
&mut style_doc,
"* Parsing rules of some properties are slightly different from the web standard."
)
.unwrap();
writeln!(
&mut style_doc,
"\nSee the table below for more information about all supported properties.\n"
)
.unwrap();
writeln!(
&mut style_doc,
"| Property Name | Related Property Variant | Major Value Options |"
)
.unwrap();
writeln!(&mut style_doc, "| ---- | ---- | ---- |").unwrap();
let table_list_a = supported_properties
.iter()
Expand All @@ -879,7 +901,11 @@ impl ToTokens for StyleSyntaxDefinition {
for x in table_list_a.chain(table_list_b) {
let name = x.name.as_ref().unwrap();
let non_standard = name.starts_with("-");
let name_col = if non_standard { format!("*`{}`*", name) } else { format!("`{}`", name) };
let name_col = if non_standard {
format!("*`{}`*", name)
} else {
format!("`{}`", name)
};
let mut doc_col = String::new();
let mut options_col = vec![];
if let StyleSyntaxValueItem::Assign(variant, v) = &x.value {
Expand All @@ -895,7 +921,14 @@ impl ToTokens for StyleSyntaxDefinition {
}
}
options_col.sort();
writeln!(&mut style_doc, "| {} | {} | {} |", name_col, doc_col, options_col.join("<br>")).unwrap();
writeln!(
&mut style_doc,
"| {} | {} | {} |",
name_col,
doc_col,
options_col.join("<br>")
)
.unwrap();
}
tokens.append_all(quote! {
#[doc = #style_doc]
Expand Down
8 changes: 4 additions & 4 deletions float-pigment-css/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
//! 1. Merge the `MatchedRuleList` into `NodeProperties` with `MatchedRuleList::merge_node_properties`.
//!
//! The result `NodeProperties` contains all supported CSS properties.
//!
//!
//! ### Supported CSS Features
//!
//!
//! The supported selectors can be found in [StyleQuery] docs.
//!
//!
//! The supported media features can be found in [MediaQueryStatus] docs.
//!
//!
//! The supported style properties can be found in [SUPPORTED_CSS_PROPERTY_NAMES](crate::property::SUPPORTED_CSS_PROPERTY_NAMES) docs.
//!
//! ### The Binary Format
Expand Down
52 changes: 47 additions & 5 deletions float-pigment-css/tests/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,42 @@ fn attribute_selector() {
let node_properties = query(&ssg, "a", "", [""], []);
assert_eq!(node_properties.height(), Length::Undefined);
assert_eq!(node_properties.width(), Length::Undefined);
let node_properties = query(&ssg, "a", "", [""], [("title".into(), "".into()), ("class".into(), "logo1 logo2".into())]);
let node_properties = query(
&ssg,
"a",
"",
[""],
[
("title".into(), "".into()),
("class".into(), "logo1 logo2".into()),
],
);
assert_eq!(node_properties.height(), Length::Px(100.));
assert_eq!(node_properties.width(), Length::Undefined);
let node_properties = query(&ssg, "a", "", [""], [("title".into(), "".into()), ("class".into(), "logo1 logo logo2".into())]);
let node_properties = query(
&ssg,
"a",
"",
[""],
[
("title".into(), "".into()),
("class".into(), "logo1 logo logo2".into()),
],
);
assert_eq!(node_properties.height(), Length::Px(100.));
assert_eq!(node_properties.width(), Length::Px(300.));
let node_properties = query(&ssg, "a", "", ["b"], [("title".into(), "".into())]);
assert_eq!(node_properties.height(), Length::Px(100.));
let node_properties = query(&ssg, "", "", [], [("title".into(), "".into())]);
assert_eq!(node_properties.height(), Length::Undefined);

let node_properties = query(&ssg, "a", "", [], [("href".into(), "https://example.org".into())]);
let node_properties = query(
&ssg,
"a",
"",
[],
[("href".into(), "https://example.org".into())],
);
assert_eq!(node_properties.height(), Length::Undefined);
assert_eq!(node_properties.width(), Length::Undefined);
assert_eq!(node_properties.min_height(), Length::Px(100.));
Expand All @@ -329,9 +353,27 @@ fn attribute_selector() {
assert_eq!(node_properties.height(), Length::Px(13.));
let node_properties = query(&ssg, "button", "a", [], [("type".into(), "warn".into())]);
assert_eq!(node_properties.height(), Length::Px(12.));
let node_properties = query(&ssg, "button", "", [], [("type".into(), "primary".into()), ("size".into(), "mini".into())]);
let node_properties = query(
&ssg,
"button",
"",
[],
[
("type".into(), "primary".into()),
("size".into(), "mini".into()),
],
);
assert_eq!(node_properties.height(), Length::Px(11.));
let node_properties = query(&ssg, "button", "", [], [("type".into(), "warm".into()), ("size".into(), "mini".into())]);
let node_properties = query(
&ssg,
"button",
"",
[],
[
("type".into(), "warm".into()),
("size".into(), "mini".into()),
],
);
assert_eq!(node_properties.height(), Length::Px(10.));
}

Expand Down
18 changes: 2 additions & 16 deletions float-pigment-css/tests/style_sheet_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,7 @@ fn scopes_in_tag_name_and_id() {
);
assert_eq!(node_properties.width(), Length::Px(0.));
assert_eq!(node_properties.height(), Length::Undefined);
let query = StyleQuery::single(
NonZeroUsize::new(1),
None,
None,
"view",
"i",
&classes,
);
let query = StyleQuery::single(NonZeroUsize::new(1), None, None, "view", "i", &classes);
let mut node_properties = NodeProperties::new(None);
ssg.query_single(
query,
Expand All @@ -363,14 +356,7 @@ fn scopes_in_tag_name_and_id() {
);
assert_eq!(node_properties.width(), Length::Px(1.));
assert_eq!(node_properties.height(), Length::Undefined);
let query = StyleQuery::single(
NonZeroUsize::new(2),
None,
None,
"view",
"i",
&classes,
);
let query = StyleQuery::single(NonZeroUsize::new(2), None, None, "view", "i", &classes);
let mut node_properties = NodeProperties::new(None);
ssg.query_single(
&query,
Expand Down
19 changes: 12 additions & 7 deletions float-pigment-css/tests/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::num::NonZeroUsize;

use float_pigment_css::query::{StyleNode, StyleNodeAttributeCaseSensitivity};
use float_pigment_css::{
length_num::LengthNum, property::*, MediaQueryStatus, StyleQuery, StyleSheet, StyleSheetGroup,
};
use float_pigment_css::query::{StyleNode, StyleNodeAttributeCaseSensitivity};

pub struct StyleQueryTest<'a> {
pub style_scope: Option<NonZeroUsize>,
Expand All @@ -18,7 +18,7 @@ pub struct StyleQueryTest<'a> {
impl<'a> StyleNode for StyleQueryTest<'a> {
type Class = (String, Option<NonZeroUsize>);
type ClassIter<'c>
= core::slice::Iter<'c, Self::Class>
= core::slice::Iter<'c, Self::Class>
where
'a: 'c;

Expand Down Expand Up @@ -50,11 +50,16 @@ impl<'a> StyleNode for StyleQueryTest<'a> {
self.attributes
.iter()
.find(|(n, _)| n == name)
.map(|(_, v)| (v.as_str(), match name {
"id" | "class" => StyleNodeAttributeCaseSensitivity::CaseSensitive,
"type" | "size" => StyleNodeAttributeCaseSensitivity::CaseInsensitive,
_ => StyleNodeAttributeCaseSensitivity::CaseSensitive,
}))
.map(|(_, v)| {
(
v.as_str(),
match name {
"id" | "class" => StyleNodeAttributeCaseSensitivity::CaseSensitive,
"type" | "size" => StyleNodeAttributeCaseSensitivity::CaseInsensitive,
_ => StyleNodeAttributeCaseSensitivity::CaseSensitive,
},
)
})
}
}

Expand Down

0 comments on commit 8bcc258

Please sign in to comment.