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 cbe52a8

Browse files
committed
Adds support for custom testcases with leetcode test command, updates gitignore to ignore macOS .DS_Store and IDE .idea files
1 parent de8b4cd commit cbe52a8

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

β€Ž.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target
22
/Cargo.lock
33
**/*.rs.bk
4-
.DS_Store
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/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: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,26 @@ impl Command for TestCommand {
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 γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /