From de8b4cd42590a49a96125636c6435defb14cc45c Mon Sep 17 00:00:00 2001 From: Raees Rajwani Date: Fri, 28 Feb 2020 20:16:39 +0530 Subject: [PATCH 1/3] Adds gitignore for .DS_Store junk file, fixes description of test command --- .gitignore | 1 + src/cmds/test.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d0a65ef..a9d1380 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target /Cargo.lock **/*.rs.bk +.DS_Store \ No newline at end of file diff --git a/src/cmds/test.rs b/src/cmds/test.rs index 7aa7f54..bc06936 100644 --- a/src/cmds/test.rs +++ b/src/cmds/test.rs @@ -25,7 +25,7 @@ impl Command for TestCommand { fn usage<'a, 'edit>() -> App<'a, 'edit> { use clap::{Arg, SubCommand}; SubCommand::with_name("test") - .about("Edit question by id") + .about("Test question by id") .visible_alias("t") .arg( Arg::with_name("id") From cbe52a88fee2c0e8a7c60027897d0c2ae17a440d Mon Sep 17 00:00:00 2001 From: Raees Rajwani Date: Sat, 29 Feb 2020 17:31:34 +0530 Subject: [PATCH 2/3] Adds support for custom testcases with leetcode test command, updates gitignore to ignore macOS .DS_Store and IDE .idea files --- .gitignore | 3 ++- src/cache/mod.rs | 15 ++++++++++----- src/cmds/exec.rs | 2 +- src/cmds/test.rs | 14 +++++++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index a9d1380..e654d81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target /Cargo.lock **/*.rs.bk -.DS_Store \ No newline at end of file +.DS_Store +.idea \ No newline at end of file diff --git a/src/cache/mod.rs b/src/cache/mod.rs index 77ad7d6..fa71011 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -186,6 +186,7 @@ impl Cache { &self, run: Run, rfid: i32, + testcase: Option ) -> Result<(HashMap<&'static str, String>, [String; 2]), Error> { trace!("pre run code..."); use crate::helper::code_path; @@ -207,7 +208,11 @@ impl Cache { // pass manually data json.insert("name", p.name.to_string()); - json.insert("data_input", d.case); + match testcase { + Some(case) => json.insert("data_input", case), + _ => json.insert("data_input", d.case) + + }; let url = match run { Run::Test => conf.sys.urls.get("test")?.replace("$slug", &p.slug), @@ -251,10 +256,10 @@ impl Cache { Ok(res) } - /// Exec problem fliter —— Test or Submit - pub fn exec_problem(&self, rfid: i32, run: Run) -> Result { - trace!("Exec problem fliter —— Test or Submit"); - let pre = self.pre_run_code(run.clone(), rfid)?; + /// Exec problem filter —— Test or Submit + pub fn exec_problem(&self, rfid: i32, run: Run, testcase: Option) -> Result { + trace!("Exec problem filter —— Test or Submit"); + let pre = self.pre_run_code(run.clone(), rfid, testcase)?; let json = pre.0; let run_res: RunCode = self diff --git a/src/cmds/exec.rs b/src/cmds/exec.rs index 3c8cd3a..da7d66c 100644 --- a/src/cmds/exec.rs +++ b/src/cmds/exec.rs @@ -41,7 +41,7 @@ impl Command for ExecCommand { let id: i32 = m.value_of("id")?.parse()?; let cache = Cache::new()?; - let res = cache.exec_problem(id, Run::Submit)?; + let res = cache.exec_problem(id, Run::Submit, None)?; println!("{}", res); Ok(()) diff --git a/src/cmds/test.rs b/src/cmds/test.rs index bc06936..2eb8cd0 100644 --- a/src/cmds/test.rs +++ b/src/cmds/test.rs @@ -33,14 +33,26 @@ impl Command for TestCommand { .required(true) .help("question id"), ) + .arg( + Arg::with_name("testcase") + .takes_value(true) + .required(false) + .help("custom testcase"), + ) } /// `test` handler fn handler(m: &ArgMatches) -> Result<(), crate::Error> { use crate::cache::{Cache, Run}; let id: i32 = m.value_of("id")?.parse()?; + let testcase = m.value_of("testcase"); + let case_str: Option; + match testcase { + Some(case) => case_str = Option::from(case.replace("\\n", "\n").to_string()), + _ => case_str = None, + } let cache = Cache::new()?; - let res = cache.exec_problem(id, Run::Test)?; + let res = cache.exec_problem(id, Run::Test, case_str)?; println!("{}", res); Ok(()) From 965de8dd4329b1ffd3515d90278892cad2a2ad3d Mon Sep 17 00:00:00 2001 From: Raees Rajwani Date: Sat, 29 Feb 2020 17:33:31 +0530 Subject: [PATCH 3/3] =?UTF-8?q?Resolves=20ambiguity=20in=20test=20case=20d?= =?UTF-8?q?isplayed,=20replaces=20,=20with=20=E2=86=A9=20character?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cache/models.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cache/models.rs b/src/cache/models.rs index aafdf59..aff59f6 100644 --- a/src/cache/models.rs +++ b/src/cache/models.rs @@ -261,7 +261,7 @@ impl std::fmt::Display for VerifyResult { " Runtime: ".dimmed(), &self.status.status_runtime.dimmed(), "\n Your input: ", - &self.data_input.replace("\n", ", "), + &self.data_input.replace("\n", "↩"), "\n Output: ", ca, "\n Expected: ", @@ -331,7 +331,7 @@ impl std::fmt::Display for VerifyResult { " Runtime: ".dimmed(), &self.status.status_runtime.dimmed(), "\n Your input: ", - &self.data_input.replace("\n", ", "), + &self.data_input.replace("\n", "↩"), "\n Output: ", ca, "\n Expected: ", @@ -387,7 +387,7 @@ impl std::fmt::Display for VerifyResult { &self.status.status_msg.red().bold(), &self.error.full_compile_error ), - _ => write!(f, "{}", "\nUnKnow Error...\n".red().bold()), + _ => write!(f, "{}", "\nUnknown Error...\n".red().bold()), } } }