Auto merge of #161 - c-rustacean:rustfmt-and-ws-fixes, r=komaeda

Rustfmt and ws fixes
This commit is contained in:
bors 2019-05-22 12:29:20 +00:00
commit fffbb60ed9
8 changed files with 54 additions and 18 deletions

View file

@ -32,10 +32,7 @@ mod tests {
#[test] #[test]
fn item_quantity_is_a_valid_number() { fn item_quantity_is_a_valid_number() {
assert_eq!( assert_eq!(total_cost("34"), Ok(171));
total_cost("34"),
Ok(171)
);
} }
#[test] #[test]

View file

@ -65,7 +65,7 @@ fn test_ioerror() {
assert_eq!("uh-oh!", read_and_validate(&mut b).unwrap_err().to_string()); assert_eq!("uh-oh!", read_and_validate(&mut b).unwrap_err().to_string());
} }
#[derive(PartialEq,Debug)] #[derive(PartialEq, Debug)]
struct PositiveNonzeroInteger(u64); struct PositiveNonzeroInteger(u64);
impl PositiveNonzeroInteger { impl PositiveNonzeroInteger {
@ -83,11 +83,14 @@ impl PositiveNonzeroInteger {
#[test] #[test]
fn test_positive_nonzero_integer_creation() { fn test_positive_nonzero_integer_creation() {
assert!(PositiveNonzeroInteger::new(10).is_ok()); assert!(PositiveNonzeroInteger::new(10).is_ok());
assert_eq!(Err(CreationError::Negative), PositiveNonzeroInteger::new(-10)); assert_eq!(
Err(CreationError::Negative),
PositiveNonzeroInteger::new(-10)
);
assert_eq!(Err(CreationError::Zero), PositiveNonzeroInteger::new(0)); assert_eq!(Err(CreationError::Zero), PositiveNonzeroInteger::new(0));
} }
#[derive(PartialEq,Debug)] #[derive(PartialEq, Debug)]
enum CreationError { enum CreationError {
Negative, Negative,
Zero, Zero,
@ -108,6 +111,36 @@ impl error::Error for CreationError {
} }
} }
// First hint: To figure out what type should go where the ??? is, take a look // First hint: To figure out what type should go where the ??? is, take a look
// at the test helper function `test_with_str`, since it returns whatever // at the test helper function `test_with_str`, since it returns whatever
// `read_and_validate` returns and`test_with_str` has its signature fully // `read_and_validate` returns and`test_with_str` has its signature fully

View file

@ -11,7 +11,10 @@ fn main() {
println!("The last item in the list is {:?}", last); println!("The last item in the list is {:?}", last);
let second_to_last = list.pop().unwrap(); let second_to_last = list.pop().unwrap();
println!("The second-to-last item in the list is {:?}", second_to_last); println!(
"The second-to-last item in the list is {:?}",
second_to_last
);
} }

View file

@ -1,10 +1,10 @@
// result1.rs // result1.rs
// Make this test pass! Scroll down for hints :) // Make this test pass! Scroll down for hints :)
#[derive(PartialEq,Debug)] #[derive(PartialEq, Debug)]
struct PositiveNonzeroInteger(u64); struct PositiveNonzeroInteger(u64);
#[derive(PartialEq,Debug)] #[derive(PartialEq, Debug)]
enum CreationError { enum CreationError {
Negative, Negative,
Zero, Zero,
@ -19,7 +19,10 @@ impl PositiveNonzeroInteger {
#[test] #[test]
fn test_creation() { fn test_creation() {
assert!(PositiveNonzeroInteger::new(10).is_ok()); assert!(PositiveNonzeroInteger::new(10).is_ok());
assert_eq!(Err(CreationError::Negative), PositiveNonzeroInteger::new(-10)); assert_eq!(
Err(CreationError::Negative),
PositiveNonzeroInteger::new(-10)
);
assert_eq!(Err(CreationError::Zero), PositiveNonzeroInteger::new(0)); assert_eq!(Err(CreationError::Zero), PositiveNonzeroInteger::new(0));
} }

View file

@ -1,7 +1,7 @@
use serde::Deserialize; use serde::Deserialize;
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
use std::fs::{remove_file}; use std::fs::remove_file;
use std::path::{PathBuf}; use std::path::PathBuf;
use std::process::{self, Command, Output}; use std::process::{self, Command, Output};
const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"]; const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"];
@ -63,8 +63,8 @@ impl Display for Exercise {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use std::path::Path;
use std::fs::File; use std::fs::File;
use std::path::Path;
#[test] #[test]
fn test_clean() { fn test_clean() {

View file

@ -1,4 +1,4 @@
use crate::exercise::{Mode, Exercise}; use crate::exercise::{Exercise, Mode};
use crate::verify::test; use crate::verify::test;
use console::{style, Emoji}; use console::{style, Emoji};
use indicatif::ProgressBar; use indicatif::ProgressBar;

View file

@ -2,7 +2,7 @@ use crate::exercise::{Exercise, Mode};
use console::{style, Emoji}; use console::{style, Emoji};
use indicatif::ProgressBar; use indicatif::ProgressBar;
pub fn verify<'a>(start_at: impl IntoIterator<Item=&'a Exercise>) -> Result<(), ()> { pub fn verify<'a>(start_at: impl IntoIterator<Item = &'a Exercise>) -> Result<(), ()> {
for exercise in start_at { for exercise in start_at {
match exercise.mode { match exercise.mode {
Mode::Test => test(&exercise)?, Mode::Test => test(&exercise)?,