Allow negative values for letter-spacing and word-spacing. Inline Length parse functions.

Signed-off-by: Sam <sam@sam.uk.net>

Use existing parse functions for any length parsing of letter-spacing and word-spacing.

Signed-off-by: Sam <sam@sam.uk.net>

Add letter-spacing test

Signed-off-by: Sam <sam@sam.uk.net>

Add tests for letter-spacing and word-spacing negative parsing.

Signed-off-by: Sam <sam@sam.uk.net>

Remove extra line.

Signed-off-by: Sam <sam@sam.uk.net>

Remove _ of _context.

Signed-off-by: Sam <sam@sam.uk.net>

Refactor tests to use new NoCalcLength

Signed-off-by: Sam <sam@sam.uk.net>

Remove unused import.

Signed-off-by: Sam <sam@sam.uk.net>

Remove un-needed use.
This commit is contained in:
Sam 2017-01-26 11:04:19 +00:00 committed by Sam
parent fb4f421c8b
commit 3682434828
5 changed files with 28 additions and 11 deletions

View file

@ -335,11 +335,11 @@ ${helpers.single_keyword("text-align-last",
}
}
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
Ok(SpecifiedValue::Normal)
} else {
specified::Length::parse_non_negative(input).map(SpecifiedValue::Specified)
specified::Length::parse(context, input).map(SpecifiedValue::Specified)
}
}
</%helpers:longhand>
@ -416,11 +416,11 @@ ${helpers.single_keyword("text-align-last",
}
}
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
Ok(SpecifiedValue::Normal)
} else {
specified::LengthOrPercentage::parse_non_negative(input)
specified::LengthOrPercentage::parse(context, input)
.map(SpecifiedValue::Specified)
}
}

View file

@ -463,6 +463,7 @@ impl Length {
}
/// Parse a non-negative length
#[inline]
pub fn parse_non_negative(input: &mut Parser) -> Result<Length, ()> {
Length::parse_internal(input, AllowedNumericType::NonNegative)
}

View file

@ -7,6 +7,29 @@ use media_queries::CSSErrorReporterTest;
use style::parser::ParserContext;
use style::stylesheets::Origin;
#[test]
fn negative_letter_spacing_should_parse_properly() {
use style::properties::longhands::letter_spacing;
use style::properties::longhands::letter_spacing::SpecifiedValue;
use style::values::specified::length::{Length, NoCalcLength, FontRelativeLength};
let negative_value = parse_longhand!(letter_spacing, "-0.5em");
let expected = SpecifiedValue::Specified(Length::NoCalc(NoCalcLength::FontRelative(FontRelativeLength::Em(-0.5))));
assert_eq!(negative_value, expected);
}
#[test]
fn negative_word_spacing_should_parse_properly() {
use style::properties::longhands::word_spacing;
use style::properties::longhands::word_spacing::SpecifiedValue;
use style::values::specified::length::{NoCalcLength, LengthOrPercentage, FontRelativeLength};
let negative_value = parse_longhand!(word_spacing, "-0.5em");
let expected = SpecifiedValue::Specified(LengthOrPercentage::Length(NoCalcLength::FontRelative(
FontRelativeLength::Em(-0.5))));
assert_eq!(negative_value, expected);
}
#[test]
fn text_emphasis_style_longhand_should_parse_properly() {
use style::properties::longhands::text_emphasis_style;
@ -79,7 +102,6 @@ fn test_text_emphasis_position() {
assert_eq!(left_under, SpecifiedValue(HorizontalWritingModeValue::Under, VerticalWritingModeValue::Left));
}
#[test]
fn webkit_text_stroke_shorthand_should_parse_properly() {
use media_queries::CSSErrorReporterTest;

View file

@ -1,3 +0,0 @@
[text-word-spacing-001.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[c542-letter-sp-001.htm]
type: reftest
expected: FAIL