mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-22 05:52:23 -05:00
use macros
This commit is contained in:
parent
595a91df55
commit
97efff760d
2 changed files with 46 additions and 21 deletions
|
@ -1,20 +1,20 @@
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
mod about_variables {
|
pub fn guess_this () -> i32 {
|
||||||
pub fn guess_this () -> i32 {
|
let one = 5;
|
||||||
let one = 5;
|
let two = 7;
|
||||||
let two = 7;
|
let three = 3;
|
||||||
let three = 3;
|
let result = (one + two) / three;
|
||||||
let result = (one + two) / three;
|
return result;
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::about_variables::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
pub fn test_complicated () {
|
||||||
fn test_complicated () {
|
assert_eq!(1, guess_this());
|
||||||
assert_eq!(___, guess_this());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn exec () {
|
||||||
|
tests::test_complicated();
|
||||||
|
}
|
||||||
|
|
41
src/main.rs
41
src/main.rs
|
@ -2,7 +2,34 @@
|
||||||
extern crate ansi_term;
|
extern crate ansi_term;
|
||||||
|
|
||||||
use quicli::prelude::*;
|
use quicli::prelude::*;
|
||||||
use ansi_term::Colour::{Red, Yellow};
|
use ansi_term::Colour::{Red, Yellow, Green};
|
||||||
|
|
||||||
|
macro_rules! verify {
|
||||||
|
( $str:expr, $left:expr, $right:expr ) => {
|
||||||
|
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!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! verify_easy {
|
||||||
|
( $str:expr, $left:expr, $right:expr ) => {
|
||||||
|
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!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod about_variables;
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
@ -10,12 +37,10 @@ struct Cli {
|
||||||
}
|
}
|
||||||
|
|
||||||
main!(|args: Cli| {
|
main!(|args: Cli| {
|
||||||
match args.exercise {
|
if let Some(e) = args.exercise {
|
||||||
Some(e) => {
|
println!("selected {}", e);
|
||||||
println!("selected {}", e);
|
} else {
|
||||||
}
|
println!("Welcome to {}", Yellow.paint("rustlings"));
|
||||||
None => {
|
verify!("One equals one", 1, 2);
|
||||||
println!("Welcome to {}", Yellow.paint("Rustlings"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue