Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Fix broken color parsing #6

Merged
merged 1 commit into from
May 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
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
39 changes: 20 additions & 19 deletions color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,25 @@ pub mod parsing {

/** Match an exact color keyword. */
fn parse_by_name(color : &str) -> Option<Color> {
let col = match color.to_ascii().to_lower().to_str() {
~"black" => black(),
~"silver" => silver(),
~"gray" => gray(),
~"grey" => gray(),
~"white" => white(),
~"maroon" => maroon(),
~"red" => red(),
~"purple" => purple(),
~"fuchsia" => fuchsia(),
~"green" => green(),
~"lime" => lime(),
~"olive" => olive(),
~"yellow" => yellow(),
~"navy" => navy(),
~"blue" => blue(),
~"teal" => teal(),
~"aqua" => aqua(),
_ => return fail_unrecognized(color)
let col = match color.to_ascii().to_lower().to_str_ascii() {
~"black" => black(),
~"silver" => silver(),
~"gray" => gray(),
~"grey" => gray(),
~"white" => white(),
~"maroon" => maroon(),
~"red" => red(),
~"purple" => purple(),
~"fuchsia" => fuchsia(),
~"green" => green(),
~"lime" => lime(),
~"olive" => olive(),
~"yellow" => yellow(),
~"navy" => navy(),
~"blue" => blue(),
~"teal" => teal(),
~"aqua" => aqua(),
_ => return fail_unrecognized(color)
};

return Some(col);
Expand Down Expand Up @@ -202,6 +202,7 @@ mod test {
assert!(white().eq(&parse_color(~"white").unwrap()));
assert!(black().eq(&parse_color(~"Black").unwrap()));
assert!(gray().eq(&parse_color(~"Gray").unwrap()));
println("silver");
assert!(silver().eq(&parse_color(~"SiLvEr").unwrap()));
assert!(maroon().eq(&parse_color(~"maroon").unwrap()));
assert!(purple().eq(&parse_color(~"PURPLE").unwrap()));
Expand Down
6 changes: 4 additions & 2 deletions test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ impl VoidPtrLike for TestNode {
fn from_void_ptr(node: *libc::c_void) -> TestNode {
assert!(node.is_not_null());
TestNode(unsafe {
let box = cast::reinterpret_cast(&node);
let box = cast::transmute_copy(&node);
cast::bump_box_refcount(box);
box
})
}

fn to_void_ptr(&self) -> *libc::c_void {
unsafe { cast::reinterpret_cast(&(*self)) }
unsafe {
cast::transmute_copy(&(*self))
}
}
}

Expand Down