mirror of
https://github.com/rust-lang/rustlings
synced 2024-11-18 09:25:36 +00:00
make the example work
This commit is contained in:
parent
8ea1b17fd9
commit
d9946a91d4
@ -1,5 +1,5 @@
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn guess_this () -> i32 {
|
fn guess_this () -> i32 {
|
||||||
let one = 5;
|
let one = 5;
|
||||||
let two = 7;
|
let two = 7;
|
||||||
let three = 3;
|
let three = 3;
|
||||||
@ -11,7 +11,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn test_complicated () {
|
pub fn test_complicated () {
|
||||||
assert_eq!(1, guess_this());
|
verify!(1, guess_this(), "Complicated example");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
src/macros.rs
Normal file
31
src/macros.rs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#[macro_export]
|
||||||
|
macro_rules! verify {
|
||||||
|
($left:expr, $right:expr, $str:expr) => {
|
||||||
|
use ansi_term::Color::{Green, Red};
|
||||||
|
|
||||||
|
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_export]
|
||||||
|
macro_rules! verify_easy {
|
||||||
|
($str:expr, $left:expr, $right:expr) => {
|
||||||
|
use ansi_term::Color::{Green, Red};
|
||||||
|
|
||||||
|
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!");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
30
src/main.rs
30
src/main.rs
@ -2,34 +2,10 @@
|
|||||||
extern crate quicli;
|
extern crate quicli;
|
||||||
extern crate ansi_term;
|
extern crate ansi_term;
|
||||||
|
|
||||||
use ansi_term::Colour::{Green, Red, Yellow};
|
|
||||||
use quicli::prelude::*;
|
use quicli::prelude::*;
|
||||||
|
use ansi_term::Color::Yellow;
|
||||||
|
|
||||||
macro_rules! verify {
|
#[macro_use] mod macros;
|
||||||
($left:expr, $right:expr, $str: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;
|
mod about_variables;
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
@ -41,5 +17,5 @@ main!(|args: Cli| if let Some(e) = args.exercise {
|
|||||||
println!("selected {}", e);
|
println!("selected {}", e);
|
||||||
} else {
|
} else {
|
||||||
println!("Welcome to {}", Yellow.paint("rustlings"));
|
println!("Welcome to {}", Yellow.paint("rustlings"));
|
||||||
verify!(2, 1, "One equals one");
|
about_variables::exec();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user