rustlings/src/main.rs

46 lines
1.2 KiB
Rust
Raw Normal View History

2018-05-14 12:13:13 -05:00
#[macro_use]
extern crate quicli;
2018-05-06 11:59:50 -05:00
extern crate ansi_term;
2018-05-14 12:13:13 -05:00
use ansi_term::Colour::{Green, Red, Yellow};
2018-05-06 11:59:50 -05:00
use quicli::prelude::*;
2018-05-14 11:41:58 -05:00
macro_rules! verify {
2018-05-14 12:13:13 -05:00
($left:expr, $right:expr, $str:expr) => {
2018-05-14 11:41:58 -05:00
if ($left == $right) {
println!("{} {}", Green.bold().paint("PASS"), $str);
} else {
println!("{} {}", Red.bold().paint("FAIL"), $str);
println!("\tYou submitted {}, but that's not correct!", $left);
println!("\tPlease correct your code to make this test pass!");
}
2018-05-14 12:13:13 -05:00
};
2018-05-14 11:41:58 -05:00
}
macro_rules! verify_easy {
2018-05-14 12:13:13 -05:00
($str:expr, $left:expr, $right:expr) => {
2018-05-14 11:41:58 -05:00
if ($left == $right) {
println!("{} {}", Green.bold().paint("PASS"), $str);
} else {
println!("{} {}", Red.bold().paint("FAIL"), $str);
println!("\tExpected: {}", $right);
println!("\tGot: {}", $left);
println!("\tPlease correct your code to make this test pass!");
}
2018-05-14 12:13:13 -05:00
};
2018-05-14 11:41:58 -05:00
}
mod about_variables;
2018-05-06 11:59:50 -05:00
#[derive(Debug, StructOpt)]
struct Cli {
exercise: Option<String>,
}
2018-05-14 12:13:13 -05:00
main!(|args: Cli| if let Some(e) = args.exercise {
println!("selected {}", e);
} else {
println!("Welcome to {}", Yellow.paint("rustlings"));
verify!(2, 1, "One equals one");
2018-05-06 11:59:50 -05:00
});