Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update to current rust: to_owned_vec was removed.
  • Loading branch information
Ms2ger committed Apr 5, 2014
commit 6ea862378455e58b37979b33a2490fcc4163fe0d
2 changes: 1 addition & 1 deletion from_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn decode_stylesheet_bytes(css: &[u8], protocol_encoding_label: Option<&str>
Some(label_length)
=> if css.slice_from(10 + label_length).starts_with("\";".as_bytes()) {
let label = css.slice(10, 10 + label_length);
let label = str::from_chars(label.iter().map(|&b| b as char).to_owned_vec());
let label = str::from_chars(label.iter().map(|&b| b as char).collect::<~[char]>());
match encoding_from_whatwg_label(label) {
None => (),
Some(fallback) => match fallback.name() {
Expand Down
29 changes: 15 additions & 14 deletions tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn run_json_tests<T: ToJson>(json_data: &str, parse: |input: ~str| -> T) {
#[test]
fn component_value_list() {
run_json_tests(include_str!("css-parsing-tests/component_value_list.json"), |input| {
tokenize(input).map(|(c, _)| c).to_owned_vec()
tokenize(input).map(|(c, _)| c).collect::<~[ComponentValue]>()
});
}

Expand All @@ -108,7 +108,7 @@ fn one_component_value() {
#[test]
fn declaration_list() {
run_json_tests(include_str!("css-parsing-tests/declaration_list.json"), |input| {
parse_declaration_list(tokenize(input)).to_owned_vec()
parse_declaration_list(tokenize(input)).collect::<~[Result<DeclarationListItem, SyntaxError>]>()
});
}

Expand All @@ -124,15 +124,15 @@ fn one_declaration() {
#[test]
fn rule_list() {
run_json_tests(include_str!("css-parsing-tests/rule_list.json"), |input| {
parse_rule_list(tokenize(input)).to_owned_vec()
parse_rule_list(tokenize(input)).collect::<~[Result<Rule, SyntaxError>]>()
});
}


#[test]
fn stylesheet() {
run_json_tests(include_str!("css-parsing-tests/stylesheet.json"), |input| {
parse_stylesheet_rules(tokenize(input)).to_owned_vec()
parse_stylesheet_rules(tokenize(input)).collect::<~[Result<Rule, SyntaxError>]>()
});
}

Expand All @@ -158,15 +158,15 @@ fn stylesheet_from_bytes() {
let css = get_string(map, &~"css_bytes").unwrap().chars().map(|c| {
assert!(c as u32 <= 0xFF);
c as u8
}).to_owned_vec();
}).collect::<~[u8]>();
let protocol_encoding_label = get_string(map, &~"protocol_encoding");
let environment_encoding = get_string(map, &~"environment_encoding")
.and_then(encoding_from_whatwg_label);

let (mut rules, used_encoding) = parse_stylesheet_rules_from_bytes(
css, protocol_encoding_label, environment_encoding);

(rules.to_owned_vec(), used_encoding.name().to_owned()).to_json()
(rules.collect::<~[Result<Rule, SyntaxError>]>(), used_encoding.name().to_owned()).to_json()
};
assert_json_eq(result, expected, json::Object(map).to_str());
});
Expand Down Expand Up @@ -242,17 +242,17 @@ fn bench_color_lookup_fail(b: &mut test::BenchHarness) {
#[test]
fn nth() {
run_json_tests(include_str!("css-parsing-tests/An+B.json"), |input| {
parse_nth(tokenize(input).map(|(c, _)| c).to_owned_vec())
parse_nth(tokenize(input).map(|(c, _)| c).collect::<~[ComponentValue]>())
});
}


#[test]
fn serializer() {
run_json_tests(include_str!("css-parsing-tests/component_value_list.json"), |input| {
let component_values = tokenize(input).map(|(c, _)| c).to_owned_vec();
let component_values = tokenize(input).map(|(c, _)| c).collect::<~[ComponentValue]>();
let serialized = component_values.iter().to_css();
tokenize(serialized).map(|(c, _)| c).to_owned_vec()
tokenize(serialized).map(|(c, _)| c).collect::<~[ComponentValue]>()
});
}

Expand Down Expand Up @@ -339,11 +339,11 @@ impl ToJson for DeclarationListItem {


fn list_to_json(list: &~[(ComponentValue, SourceLocation)]) -> ~[json::Json] {
list.map(|tuple| {
list.iter().map(|tuple| {
match *tuple {
(ref c, _) => c.to_json()
}
})
}).collect()
}


Expand Down Expand Up @@ -426,11 +426,12 @@ impl ToJson for ComponentValue {
CDC => JString(~"-->"),

Function(ref name, ref arguments)
=> JList(~[JString(~"function"), name.to_json()] + arguments.map(|a| a.to_json())),
=> JList(~[JString(~"function"), name.to_json()] +
arguments.iter().map(|a| a.to_json()).collect::<~[json::Json]>()),
ParenthesisBlock(ref content)
=> JList(~[JString(~"()")] + content.map(|c| c.to_json())),
=> JList(~[JString(~"()")] + content.iter().map(|c| c.to_json()).collect::<~[json::Json]>()),
SquareBracketBlock(ref content)
=> JList(~[JString(~"[]")] + content.map(|c| c.to_json())),
=> JList(~[JString(~"[]")] + content.iter().map(|c| c.to_json()).collect::<~[json::Json]>()),
CurlyBracketBlock(ref content)
=> JList(~[JString(~"{}")] + list_to_json(content)),

Expand Down