diff --git a/servo/components/style/properties/longhand/counters.mako.rs b/servo/components/style/properties/longhand/counters.mako.rs index f6b8173c610c..c4bbba8785a5 100644 --- a/servo/components/style/properties/longhand/counters.mako.rs +++ b/servo/components/style/properties/longhand/counters.mako.rs @@ -269,6 +269,10 @@ impl ToCss for SpecifiedValue { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + if self.0.is_empty() { + return dest.write_str("none"); + } + let mut first = true; for pair in &self.0 { if !first { @@ -278,6 +282,7 @@ try!(serialize_identifier(&pair.0, dest)); try!(write!(dest, " {}", pair.1)); } + Ok(()) } } diff --git a/servo/tests/unit/style/properties/serialization.rs b/servo/tests/unit/style/properties/serialization.rs index c95ae49cf7ed..73fdf184584e 100644 --- a/servo/tests/unit/style/properties/serialization.rs +++ b/servo/tests/unit/style/properties/serialization.rs @@ -1170,4 +1170,30 @@ mod shorthand_serialization { assert_eq!(shadow.to_css_string(), shadow_css); } } + + mod counter_increment { + pub use super::*; + pub use style::properties::longhands::counter_increment::SpecifiedValue as CounterIncrement; + + #[test] + fn counter_increment_with_properties_should_serialize_correctly() { + let mut properties = Vec::new(); + + properties.push(("counter1".to_owned(), 1)); + properties.push(("counter2".to_owned(), -4)); + + let counter_increment = CounterIncrement(properties); + let counter_increment_css = "counter1 1 counter2 -4"; + + assert_eq!(counter_increment.to_css_string(), counter_increment_css); + } + + #[test] + fn counter_increment_without_properties_should_serialize_correctly() { + let counter_increment = CounterIncrement(Vec::new()); + let counter_increment_css = "none"; + + assert_eq!(counter_increment.to_css_string(), counter_increment_css); + } + } }