summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorolivia <olivia@fastmail.com>2018-05-14 18:41:58 +0200
committerolivia <olivia@fastmail.com>2018-05-14 18:41:58 +0200
commit97efff760dcc032b634d3f69ebedac4ec1b301e7 (patch)
treef6e997de091e8514c40cc673e24c9b5100d5c415 /src
parent595a91df555fc71f3075ea78649b267665151d1d (diff)
use macros
Diffstat (limited to 'src')
-rw-r--r--src/about_variables.rs26
-rw-r--r--src/main.rs41
2 files changed, 46 insertions, 21 deletions
diff --git a/src/about_variables.rs b/src/about_variables.rs
index 4459509..4827dcf 100644
--- a/src/about_variables.rs
+++ b/src/about_variables.rs
@@ -1,20 +1,20 @@
#[allow(dead_code)]
-mod about_variables {
- pub fn guess_this () -> i32 {
- let one = 5;
- let two = 7;
- let three = 3;
- let result = (one + two) / three;
- return result;
- }
+pub fn guess_this () -> i32 {
+ let one = 5;
+ let two = 7;
+ let three = 3;
+ let result = (one + two) / three;
+ return result;
}
-#[cfg(test)]
mod tests {
- use super::about_variables::*;
+ use super::*;
- #[test]
- fn test_complicated () {
- assert_eq!(___, guess_this());
+ pub fn test_complicated () {
+ assert_eq!(1, guess_this());
}
}
+
+pub fn exec () {
+ tests::test_complicated();
+}
diff --git a/src/main.rs b/src/main.rs
index abbd3b8..c3ca53c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,7 +2,34 @@
extern crate ansi_term;
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)]
struct Cli {
@@ -10,12 +37,10 @@ struct Cli {
}
main!(|args: Cli| {
- match args.exercise {
- Some(e) => {
- println!("selected {}", e);
- }
- None => {
- println!("Welcome to {}", Yellow.paint("Rustlings"));
- }
+ if let Some(e) = args.exercise {
+ println!("selected {}", e);
+ } else {
+ println!("Welcome to {}", Yellow.paint("rustlings"));
+ verify!("One equals one", 1, 2);
}
});