mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Refactoring; negative tests
This commit is contained in:
parent
34400374c1
commit
d94496c896
2 changed files with 40 additions and 18 deletions
|
@ -380,7 +380,7 @@ ${helpers.single_keyword("font-variant-position",
|
|||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum T {
|
||||
Normal,
|
||||
Computed(Vec<FeatureTagValue>)
|
||||
Tag(Vec<FeatureTagValue>)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -394,7 +394,7 @@ ${helpers.single_keyword("font-variant-position",
|
|||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
T::Normal => dest.write_str("normal"),
|
||||
T::Computed(ref ftvs) => {
|
||||
T::Tag(ref ftvs) => {
|
||||
let mut iter = ftvs.iter();
|
||||
// handle head element
|
||||
try!(iter.next().unwrap().to_css(dest));
|
||||
|
@ -417,32 +417,34 @@ ${helpers.single_keyword("font-variant-position",
|
|||
}
|
||||
|
||||
impl FeatureTagValue {
|
||||
/// https://www.w3.org/TR/css-fonts-3/#propdef-font-feature-settings
|
||||
/// <string> [ on | off | <integer> ]
|
||||
pub fn parse(input: &mut Parser) -> Result<FeatureTagValue, ()> {
|
||||
let tag = try!(input.expect_string()).into_owned();
|
||||
let tag = try!(input.expect_string());
|
||||
|
||||
// allowed strings of length 4 containing chars: <U+20, U+7E>
|
||||
if tag.len() != 4 ||
|
||||
tag.chars().any(|c| c < ' ' || c > '~') {
|
||||
return Err(())
|
||||
}
|
||||
tag.chars().any(|c| c < ' ' || c > '~')
|
||||
{
|
||||
return Err(())
|
||||
}
|
||||
|
||||
if let Ok(value) = input.try(|input| input.expect_integer()) {
|
||||
// handle integer, throw if it is negative
|
||||
if value >= 0 {
|
||||
Ok(FeatureTagValue{ tag: tag, value: value })
|
||||
Ok(FeatureTagValue { tag: tag.into_owned(), value: value })
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
} else if let Ok(_) = input.try(|input| input.expect_ident_matching("on")) {
|
||||
// on is an alias for '1'
|
||||
Ok(FeatureTagValue{ tag: tag, value: 1 })
|
||||
Ok(FeatureTagValue { tag: tag.into_owned(), value: 1 })
|
||||
} else if let Ok(_) = input.try(|input| input.expect_ident_matching("off")) {
|
||||
// off is an alias for '0'
|
||||
Ok(FeatureTagValue{ tag: tag, value: 0 })
|
||||
Ok(FeatureTagValue { tag: tag.into_owned(), value: 0 })
|
||||
} else {
|
||||
// empty value is an alias for '1'
|
||||
Ok(FeatureTagValue{ tag:tag, value: 1 })
|
||||
Ok(FeatureTagValue { tag:tag.into_owned(), value: 1 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -459,7 +461,7 @@ ${helpers.single_keyword("font-variant-position",
|
|||
Ok(computed_value::T::Normal)
|
||||
} else {
|
||||
input.parse_comma_separated(computed_value::FeatureTagValue::parse)
|
||||
.map(computed_value::T::Computed)
|
||||
.map(computed_value::T::Tag)
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue