MCPcopy Index your code
hub / github.com/clearloop/leetcode-cli / pre_run_code

Method pre_run_code

src/cache/mod.rs:241–323  ·  view source on GitHub ↗

run_code data

(
        &self,
        run: Run,
        rfid: i32,
        test_case: Option<String>,
    )

Source from the content-addressed store, hash-verified

239
240 /// run_code data
241 async fn pre_run_code(
242 &self,
243 run: Run,
244 rfid: i32,
245 test_case: Option<String>,
246 ) -> Result<(HashMap<&'static str, String>, [String; 2]), Error> {
247 trace!("pre-run code...");
248 use crate::helper::code_path;
249 use std::fs::File;
250 use std::io::Read;
251
252 let mut p = self.get_problem(rfid)?;
253 if p.desc.is_empty() {
254 trace!("Problem description does not exist, pull desc and exec again...");
255 self.get_question(rfid).await?;
256 p = self.get_problem(rfid)?;
257 }
258
259 let d: Question = serde_json::from_str(&p.desc)?;
260 let conf = &self.0.conf;
261 let mut json: HashMap<&'static str, String> = HashMap::new();
262 let mut code: String = "".to_string();
263
264 let maybe_file_testcases: Option<String> = test_cases_path(&p)
265 .map(|file_name| {
266 let mut tests = "".to_string();
267 File::open(file_name)
268 .and_then(|mut file_descriptor| file_descriptor.read_to_string(&mut tests))
269 .map(|_| Some(tests))
270 .unwrap_or(None)
271 })
272 .unwrap_or(None);
273
274 let maybe_all_testcases: Option<String> = if d.all_cases.is_empty() {
275 None
276 } else {
277 Some(d.all_cases.to_string())
278 };
279
280 // Takes test cases using following priority
281 // 1. cli parameter
282 // 2. if test cases file exist, use the file test cases(user can edit it)
283 // 3. test cases from problem desc all test cases
284 // 4. sample test case from the task
285 let test_case = test_case
286 .or(maybe_file_testcases)
287 .or(maybe_all_testcases)
288 .unwrap_or(d.case);
289
290 File::open(code_path(&p, None)?)?.read_to_string(&mut code)?;
291
292 let code = if conf.code.edit_code_marker {
293 let begin = code.find(&conf.code.start_marker);
294 let end = code.find(&conf.code.end_marker);
295 if let (Some(l), Some(r)) = (begin, end) {
296 code.get((l + conf.code.start_marker.len())..r)
297 .map(|s| s.to_string())
298 .unwrap_or_else(|| code)

Callers 1

exec_problemMethod · 0.80

Calls 7

test_cases_pathFunction · 0.85
code_pathFunction · 0.85
get_problemMethod · 0.80
get_questionMethod · 0.80
testMethod · 0.80
submitMethod · 0.80
problemMethod · 0.80

Tested by

no test coverage detected