Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b3086a5

Browse files
Merge pull request clearloop#7 from Raees678/master
Allow for custom testcases with the `leetcode test` command, and some minor edits
2 parents cf2deee + 965de8d commit b3086a5

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/target
22
/Cargo.lock
33
**/*.rs.bk
4+
.DS_Store
5+
.idea

‎src/cache/mod.rs‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ impl Cache {
186186
&self,
187187
run: Run,
188188
rfid: i32,
189+
testcase: Option<String>
189190
) -> Result<(HashMap<&'static str, String>, [String; 2]), Error> {
190191
trace!("pre run code...");
191192
use crate::helper::code_path;
@@ -207,7 +208,11 @@ impl Cache {
207208

208209
// pass manually data
209210
json.insert("name", p.name.to_string());
210-
json.insert("data_input", d.case);
211+
match testcase {
212+
Some(case) => json.insert("data_input", case),
213+
_ => json.insert("data_input", d.case)
214+
215+
};
211216

212217
let url = match run {
213218
Run::Test => conf.sys.urls.get("test")?.replace("$slug", &p.slug),
@@ -251,10 +256,10 @@ impl Cache {
251256
Ok(res)
252257
}
253258

254-
/// Exec problem fliter —— Test or Submit
255-
pub fn exec_problem(&self, rfid: i32, run: Run) -> Result<VerifyResult, Error> {
256-
trace!("Exec problem fliter —— Test or Submit");
257-
let pre = self.pre_run_code(run.clone(), rfid)?;
259+
/// Exec problem filter —— Test or Submit
260+
pub fn exec_problem(&self, rfid: i32, run: Run,testcase:Option<String>) -> Result<VerifyResult, Error> {
261+
trace!("Exec problem filter —— Test or Submit");
262+
let pre = self.pre_run_code(run.clone(), rfid, testcase)?;
258263
let json = pre.0;
259264

260265
let run_res: RunCode = self

‎src/cache/models.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl std::fmt::Display for VerifyResult {
261261
" Runtime: ".dimmed(),
262262
&self.status.status_runtime.dimmed(),
263263
"\n Your input: ",
264-
&self.data_input.replace("\n", ", "),
264+
&self.data_input.replace("\n", ""),
265265
"\n Output: ",
266266
ca,
267267
"\n Expected: ",
@@ -331,7 +331,7 @@ impl std::fmt::Display for VerifyResult {
331331
" Runtime: ".dimmed(),
332332
&self.status.status_runtime.dimmed(),
333333
"\n Your input: ",
334-
&self.data_input.replace("\n", ", "),
334+
&self.data_input.replace("\n", ""),
335335
"\n Output: ",
336336
ca,
337337
"\n Expected: ",
@@ -387,7 +387,7 @@ impl std::fmt::Display for VerifyResult {
387387
&self.status.status_msg.red().bold(),
388388
&self.error.full_compile_error
389389
),
390-
_ => write!(f, "{}", "\nUnKnow Error...\n".red().bold()),
390+
_ => write!(f, "{}", "\nUnknown Error...\n".red().bold()),
391391
}
392392
}
393393
}

‎src/cmds/exec.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Command for ExecCommand {
4141

4242
let id: i32 = m.value_of("id")?.parse()?;
4343
let cache = Cache::new()?;
44-
let res = cache.exec_problem(id, Run::Submit)?;
44+
let res = cache.exec_problem(id, Run::Submit,None)?;
4545

4646
println!("{}", res);
4747
Ok(())

‎src/cmds/test.rs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,34 @@ impl Command for TestCommand {
2525
fn usage<'a, 'edit>() -> App<'a, 'edit> {
2626
use clap::{Arg, SubCommand};
2727
SubCommand::with_name("test")
28-
.about("Edit question by id")
28+
.about("Test question by id")
2929
.visible_alias("t")
3030
.arg(
3131
Arg::with_name("id")
3232
.takes_value(true)
3333
.required(true)
3434
.help("question id"),
3535
)
36+
.arg(
37+
Arg::with_name("testcase")
38+
.takes_value(true)
39+
.required(false)
40+
.help("custom testcase"),
41+
)
3642
}
3743

3844
/// `test` handler
3945
fn handler(m: &ArgMatches) -> Result<(), crate::Error> {
4046
use crate::cache::{Cache, Run};
4147
let id: i32 = m.value_of("id")?.parse()?;
48+
let testcase = m.value_of("testcase");
49+
let case_str: Option<String>;
50+
match testcase {
51+
Some(case) => case_str = Option::from(case.replace("\\n", "\n").to_string()),
52+
_ => case_str = None,
53+
}
4254
let cache = Cache::new()?;
43-
let res = cache.exec_problem(id, Run::Test)?;
55+
let res = cache.exec_problem(id, Run::Test, case_str)?;
4456

4557
println!("{}", res);
4658
Ok(())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /