Skip to content

Commit

Permalink
Next adaptation for rust-nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
tailhook committed Feb 3, 2015
1 parent 91ac46b commit 0d6cc11
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ impl<'a, T: Copy> IFlagAction for StoreConstAction<'a, T> {
impl<'a, T: FromStr> IArgAction for StoreAction<'a, T> {
fn parse_arg(&self, arg: &str) -> ParseResult {
match FromStr::from_str(arg) {
Some(x) => {
Ok(x) => {
**self.cell.borrow_mut() = x;
return Parsed;
}
None => {
Err(_) => {
return Error(format!("Bad value {}", arg));
}
}
Expand All @@ -82,11 +82,11 @@ impl<'a, T: FromStr> IArgAction for StoreAction<'a, T> {
impl<'a, T: FromStr> IArgAction for StoreOptionAction<'a, T> {
fn parse_arg(&self, arg: &str) -> ParseResult {
match FromStr::from_str(arg) {
Some(x) => {
Ok(x) => {
**self.cell.borrow_mut() = Some(x);
return Parsed;
}
None => {
Err(_) => {
return Error(format!("Bad value {}", arg));
}
}
Expand All @@ -98,10 +98,10 @@ impl<'a, T: FromStr + Clone> IArgsAction for ListAction<'a, T> {
let mut result = box Vec::new();
for arg in args.iter() {
match FromStr::from_str(*arg) {
Some(x) => {
Ok(x) => {
result.push(x);
}
None => {
Err(_) => {
return Error(format!("Bad value {}", arg));
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ impl<'a> Iterator for WordsIter<'a> {
}
}
}
for (idx, ch) in self.iter {
loop {
let (idx, ch) = match self.iter.next() {
None => break,
Some((idx, ch)) => ((idx, ch)),
};
match ch {
' ' | '\t' | '\r' | '\n' => {
return Some(self.data.slice(word_start, idx));
Expand Down
11 changes: 6 additions & 5 deletions src/test_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ use test_parser::{check_ok,check_err};
use self::Greeting::{Hello, Hi, NoGreeting};


#[derive(PartialEq, Eq, Show)]
#[derive(PartialEq, Eq, Debug)]
enum Greeting {
Hello,
Hi,
NoGreeting,
}

impl FromStr for Greeting {
fn from_str(src: &str) -> Option<Greeting> {
type Err = ();
fn from_str(src: &str) -> Result<Greeting, ()> {
return match src {
"hello" => Some(Hello),
"hi" => Some(Hi),
_ => None,
"hello" => Ok(Hello),
"hi" => Ok(Hi),
_ => Err(()),
};
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/test_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ fn test_empty() {

#[test]
fn test_options() {
let mut ap = ArgumentParser::new();
let mut val = 0;
let mut val2 = 0;
let mut ap = ArgumentParser::new();
ap.set_description("Test program. The description of the program is ought
to be very long, because we want to test how word wrapping works for
it. So some more text would be ok for the test");
Expand Down Expand Up @@ -53,8 +53,8 @@ for the test\n"

#[test]
fn test_argument() {
let mut ap = ArgumentParser::new();
let mut val = 0;
let mut ap = ArgumentParser::new();
ap.set_description("Test program");
ap.refer(&mut val)
.add_argument("value", box Store::<isize>,
Expand All @@ -76,9 +76,9 @@ fn test_argument() {

#[test]
fn test_arguments() {
let mut ap = ArgumentParser::new();
let mut v1 = 0;
let mut v2 = Vec::new();
let mut ap = ArgumentParser::new();
ap.set_description("Test program");
ap.refer(&mut v1)
.add_argument("v1", box Store::<isize>,
Expand All @@ -104,9 +104,9 @@ fn test_arguments() {

#[test]
fn test_req_arguments() {
let mut ap = ArgumentParser::new();
let mut v1 = 0;
let mut v2 = Vec::new();
let mut ap = ArgumentParser::new();
ap.set_description("Test program");
ap.refer(&mut v1)
.add_argument("v1", box Store::<isize>,
Expand Down Expand Up @@ -134,8 +134,8 @@ fn test_req_arguments() {

#[test]
fn test_metavar() {
let mut ap = ArgumentParser::new();
let mut val2 = 0;
let mut ap = ArgumentParser::new();
ap.set_description("Test program.");
ap.refer(&mut val2)
.add_option(&["-L", "--long-option"], box Store::<isize>,
Expand Down
16 changes: 9 additions & 7 deletions src/test_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ fn test_empty() {

#[test]
fn test_options() {
let mut ap = ArgumentParser::new();
let mut val = 0;
ap.refer(&mut val)
.add_option(&["--value"], box Store::<isize>,
"Set integer value");
let mut buf = MemWriter::new();
assert_eq!(ap.print_usage("./argparse_test", &mut buf), Ok(()));
{
let mut ap = ArgumentParser::new();
ap.refer(&mut val)
.add_option(&["--value"], box Store::<isize>,
"Set integer value");
assert_eq!(ap.print_usage("./argparse_test", &mut buf), Ok(()));
}
assert_eq!("Usage:\n ./argparse_test [OPTIONS]\n",
from_utf8(buf.into_inner().as_slice()).unwrap());
}

#[test]
fn test_argument() {
let mut ap = ArgumentParser::new();
let mut val = 0;
let mut ap = ArgumentParser::new();
ap.refer(&mut val)
.add_argument("value", box Store::<isize>,
"Integer value");
Expand All @@ -41,9 +43,9 @@ fn test_argument() {

#[test]
fn test_arguments() {
let mut ap = ArgumentParser::new();
let mut v1 = 0;
let mut v2 = Vec::new();
let mut ap = ArgumentParser::new();
ap.refer(&mut v1)
.add_argument("v1", box Store::<isize>,
"Integer value 1");
Expand Down
2 changes: 1 addition & 1 deletion vagga.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ containers:
- !Ubuntu trusty
- !Install [make, gcc]
- !TarInstall
url: http://static.rust-lang.org/dist/rust-1.0.0-alpha-x86_64-unknown-linux-gnu.tar.gz
url: http://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.gz
script: ./install.sh --prefix=/usr
volumes:
/tmp: !Tmpfs { size: 100Mi }
Expand Down

0 comments on commit 0d6cc11

Please sign in to comment.