// http://rosettacode.org/wiki/Strip_comments_from_a_string

fn strip_comments(str: &str) -> &str {
    let markers = ['#', ';'];
    str.find(markers.as_slice()).map_or(str, |i| str.slice_to(i)).trim()
}

#[test]
fn test_strip_comments() {
    let inputs = ["apples, pears # and bananas",
                  "apples, pears ; and bananas",
                  "  apples, pears "];
    let output = "apples, pears";

    for &input in inputs.iter() {
        assert_eq!(strip_comments(input), output)
    }
}

#[cfg(not(test))]
fn main() {
    let inputs = ["apples, pears # and bananas",
                  "apples, pears ; and bananas",
                  "  apples, pears "];

    for &input in inputs.iter() {
        println!("Input: {}\nStripped: {}", input, strip_comments(input))
    }
}

// http://rosettacode.org/wiki/Strip_comments_from_a_string

fn strip_comments(str: &str) -> &str {
    let markers = ['#', ';'];
    str.find(markers.as_slice()).map_or(str, |i| str.slice_to(i)).trim_right()
}

#[test]
fn test_strip_comments() {
    let inputs = ["apples, pears # and bananas",
                  "apples, pears ; and bananas",
                  "apples, pears "];
    let output = "apples, pears";

    for &input in inputs.iter() {
        assert_eq!(strip_comments(input), output)
    }
}

#[cfg(not(test))]
fn main() {
    let inputs = ["apples, pears # and bananas",
                  "apples, pears ; and bananas",
                  "apples, pears "];

    for &input in inputs.iter() {
        println!("Input: {}\nStripped: {}", input, strip_comments(input))
    }
}

--- 
+++ 
@@ -2,14 +2,14 @@
 
 fn strip_comments(str: &str) -> &str {
     let markers = ['#', ';'];
-    str.find(markers.as_slice()).map_or(str, |i| str.slice_to(i)).trim_right()
+    str.find(markers.as_slice()).map_or(str, |i| str.slice_to(i)).trim()
 }
 
 #[test]
 fn test_strip_comments() {
     let inputs = ["apples, pears # and bananas",
                   "apples, pears ; and bananas",
-                  "apples, pears "];
+                  "  apples, pears "];
     let output = "apples, pears";
 
     for &input in inputs.iter() {
@@ -21,7 +21,7 @@
 fn main() {
     let inputs = ["apples, pears # and bananas",
                   "apples, pears ; and bananas",
-                  "apples, pears "];
+                  "  apples, pears "];
 
     for &input in inputs.iter() {
         println!("Input: {}\nStripped: {}", input, strip_comments(input))
Trim the string from both sides, not just the right side.
