rustlings/src/main.rs

46 lines
1.2 KiB
Rust
Raw Normal View History

2018-05-14 13:13:13 -04:00
#[macro_use]
extern crate quicli;
2018-05-06 12:59:50 -04:00
extern crate ansi_term;
2018-05-14 13:13:13 -04:00
use ansi_term::Colour::{Green, Red, Yellow};
2018-05-06 12:59:50 -04:00
use quicli::prelude::*;
2018-05-14 12:41:58 -04:00
macro_rules! verify {
2018-05-14 13:13:13 -04:00
($left:expr, $right:expr, $str:expr) => {
2018-05-14 12:41:58 -04: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 13:13:13 -04:00
};
2018-05-14 12:41:58 -04:00
}
macro_rules! verify_easy {
2018-05-14 13:13:13 -04:00
($str:expr, $left:expr, $right:expr) => {
2018-05-14 12:41:58 -04: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 13:13:13 -04:00
};
2018-05-14 12:41:58 -04:00
}
mod about_variables;
2018-05-06 12:59:50 -04:00
#[derive(Debug, StructOpt)]
struct Cli {
exercise: Option<String>,
}
2018-05-14 13:13:13 -04: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 12:59:50 -04:00
});