style: Add some parsing and serialization tests for @layer

This uncovers some serialization bugs, and some missing null-checks
given the statement layer doesn't have a rule list.

Differential Revision: https://phabricator.services.mozilla.com/D125176
This commit is contained in:
Emilio Cobos Álvarez 2023-05-27 07:20:11 +02:00 committed by Oriol Brufau
parent 35bf5f0b09
commit 5fe148d5f1

View file

@ -234,7 +234,7 @@ impl ToCssWithGuard for LayerRule {
guard: &SharedRwLockReadGuard, guard: &SharedRwLockReadGuard,
dest: &mut crate::str::CssStringWriter, dest: &mut crate::str::CssStringWriter,
) -> fmt::Result { ) -> fmt::Result {
dest.write_str("@layer ")?; dest.write_str("@layer")?;
match self.kind { match self.kind {
LayerRuleKind::Block { LayerRuleKind::Block {
ref name, ref name,
@ -242,8 +242,8 @@ impl ToCssWithGuard for LayerRule {
ref is_anonymous, ref is_anonymous,
} => { } => {
if !*is_anonymous { if !*is_anonymous {
name.to_css(&mut CssWriter::new(dest))?;
dest.write_char(' ')?; dest.write_char(' ')?;
name.to_css(&mut CssWriter::new(dest))?;
} }
rules.read_with(guard).to_css_block(guard, dest) rules.read_with(guard).to_css_block(guard, dest)
}, },
@ -251,7 +251,9 @@ impl ToCssWithGuard for LayerRule {
let mut writer = CssWriter::new(dest); let mut writer = CssWriter::new(dest);
let mut first = true; let mut first = true;
for name in &**names { for name in &**names {
if !first { if first {
writer.write_char(' ')?;
} else {
writer.write_str(", ")?; writer.write_str(", ")?;
} }
first = false; first = false;