summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorolivia <olivia@fastmail.com>2018-05-16 15:23:14 +0200
committerolivia <olivia@fastmail.com>2018-05-16 15:23:14 +0200
commitd9946a91d429b2de2d0e21a2f346821f29c6ec5a (patch)
treeaf25ff7f76a52254ccb9adb49bde7dc150602c20
parent8ea1b17fd9505da92a7233d8bfd6d5f1c3d9a93e (diff)
make the example work
-rw-r--r--src/about_variables.rs4
-rw-r--r--src/macros.rs31
-rw-r--r--src/main.rs30
3 files changed, 36 insertions, 29 deletions
diff --git a/src/about_variables.rs b/src/about_variables.rs
index 4827dcf..9e64904 100644
--- a/src/about_variables.rs
+++ b/src/about_variables.rs
@@ -1,5 +1,5 @@
#[allow(dead_code)]
-pub fn guess_this () -> i32 {
+fn guess_this () -> i32 {
let one = 5;
let two = 7;
let three = 3;
@@ -11,7 +11,7 @@ mod tests {
use super::*;
pub fn test_complicated () {
- assert_eq!(1, guess_this());
+ verify!(1, guess_this(), "Complicated example");
}
}
diff --git a/src/macros.rs b/src/macros.rs
new file mode 100644
index 0000000..5c80b84
--- /dev/null
+++ b/src/macros.rs
@@ -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!");
+ }
+ };
+}
+
diff --git a/src/main.rs b/src/main.rs
index 3adc6bd..525baa4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,34 +2,10 @@
extern crate quicli;
extern crate ansi_term;
-use ansi_term::Colour::{Green, Red, Yellow};
use quicli::prelude::*;
+use ansi_term::Color::Yellow;
-macro_rules! verify {
- ($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!");
- }
- };
-}
-
+#[macro_use] mod macros;
mod about_variables;
#[derive(Debug, StructOpt)]
@@ -41,5 +17,5 @@ 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");
+ about_variables::exec();
});