From 3f0c1dea49eac7b76b098e299b69c809f56bb099 Mon Sep 17 00:00:00 2001 From: One <43485962+c-git@users.noreply.github.com> Date: Fri, 2 Feb 2024 13:20:22 -0500 Subject: [PATCH 1/3] refactor: use raw strings instead of escaping quotes --- src/tool/core/helpers/problem_code.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/tool/core/helpers/problem_code.rs b/src/tool/core/helpers/problem_code.rs index ee4a3ef..c889d52 100644 --- a/src/tool/core/helpers/problem_code.rs +++ b/src/tool/core/helpers/problem_code.rs @@ -725,19 +725,19 @@ impl Solution { (FAT::I64, "2"), (FAT::F64, "2.00000"), (FAT::Bool, "true"), - (FAT::String_, "\"leetcode\""), + (FAT::String_, r#""leetcode""#), (FAT::VecI32, "[1,2,3,4]"), (FAT::VecF64, "[6.00000,0.50000,-1.00000,1.00000,-1.00000]"), (FAT::VecBool, "[true,false,false,false,false]"), - (FAT::VecString, "[\"@..aA\",\"..B#.\",\"....b\"]"), + (FAT::VecString, r#"["@..aA","..B#.","....b"]"#), (FAT::VecVecI32, "[[2,2,3],[7]]"), ( FAT::VecVecString, - "[[\"java\"],[\"nodejs\"],[\"nodejs\",\"reactjs\"]]", + r#"[["java"],["nodejs"],["nodejs","reactjs"]]"#, ), ( FAT::VecVecChar, - "[[\"X\",\".\",\".\",\"X\"],[\".\",\".\",\".\",\"X\"],[\".\",\".\",\".\",\"X\"]]", + r#"[["X",".",".","X"],[".",".",".","X"],[".",".",".","X"]]"#, ), (FAT::List, "[1,2,4]"), (FAT::Tree, "[1,null,2,3]"), @@ -772,19 +772,21 @@ impl Solution { FAT::I64 => "2", FAT::F64 => "2.00000", FAT::Bool => "true", - FAT::String_ => "\"leetcode\"", + FAT::String_ => r#""leetcode""#, FAT::VecI32 => "vec![1,2,3,4]", FAT::VecF64 => "vec![6.00000,0.50000,-1.00000,1.00000,-1.00000]", FAT::VecBool => "vec![true,false,false,false,false]", - FAT::VecString => "vec![\"@..aA\".into(),\"..B#.\".into(),\"....b\".into()]", + FAT::VecString => r#"vec!["@..aA".into(),"..B#.".into(),"....b".into()]"#, FAT::VecVecI32 => "vec![vec![2,2,3],vec![7]]", FAT::VecVecString => { - "vec![vec![\"java\".into()],vec![\"nodejs\".into()],vec![\"nodejs\".into(),\"reactjs\".into()]]" + r#"vec![vec!["java".into()],vec!["nodejs".into()],vec!["nodejs".into(),"reactjs".into()]]"# + } + FAT::VecVecChar => { + "vec![vec!['X','.','.','X'],vec!['.','.','.','X'],vec!['.','.','.','X']]" } - FAT::VecVecChar => { "vec![vec!['X','.','.','X'],vec!['.','.','.','X'],vec!['.','.','.','X']]" } FAT::List => "ListHead::from(vec![1,2,4]).into()", - FAT::Tree => "TreeRoot::from(\"[1,null,2,3]\").into()", - FAT::Other { raw: _ } => "todo!(\"1\")", + FAT::Tree => r#"TreeRoot::from("[1,null,2,3]").into()"#, + FAT::Other { raw: _ } => r#"todo!("1")"#, }; let actual = fat.apply(input); assert_eq!(actual, expected); From 2c905af19a6f89ed340558256e40a16f5a1bc76e Mon Sep 17 00:00:00 2001 From: One <43485962+c-git@users.noreply.github.com> Date: Fri, 2 Feb 2024 13:36:55 -0500 Subject: [PATCH 2/3] refactor: use raw string in where applicable Some cases it made it harder to read so those were skipped but all others were converted --- src/tool/core/helpers/code_snippet.rs | 2 +- src/tool/core/helpers/problem_code.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tool/core/helpers/code_snippet.rs b/src/tool/core/helpers/code_snippet.rs index af7c359..ee47902 100644 --- a/src/tool/core/helpers/code_snippet.rs +++ b/src/tool/core/helpers/code_snippet.rs @@ -51,7 +51,7 @@ pub(crate) fn get_code_snippet_for_problem(title_slug: &str) -> anyhow::Result

Err(e.to_string()), }, Self::Tree => match Self::does_pass_basic_vec_tests(line) { - Ok(()) => Ok(format!("TreeRoot::from(\"{line}\").into()")), + Ok(()) => Ok(format!(r#"TreeRoot::from("{line}").into()"#)), Err(e) => Err(e.to_string()), }, - Self::Other { raw: _ } => Ok(format!("todo!(\"{line}\")")), + Self::Other { raw: _ } => Ok(format!(r#"todo!("{line}")"#)), }; result.unwrap_or_else(|e| { warn!("Type Mismatch? Type detected as '{self:?}' but got argument value of {line:?}. Error: {e}"); @@ -586,7 +586,7 @@ impl Solution { #[test] fn get_test_case_ok() { // Arrange - let expected = "7, vec![2,3,1,2,4,3], todo!(\"Expected Result\")"; + let expected = r#"7, vec![2,3,1,2,4,3], todo!("Expected Result")"#; let fn_info = get_fn_info_min_sub_array_len(); let input = "7\n[2,3,1,2,4,3]"; From b9e2a52c25c4a41a5204392f71db3a640c1e1d97 Mon Sep 17 00:00:00 2001 From: One <43485962+c-git@users.noreply.github.com> Date: Fri, 2 Feb 2024 13:38:26 -0500 Subject: [PATCH 3/3] refactor: remove uncessary raw strings --- src/tool/core/helpers/daily_challenge.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tool/core/helpers/daily_challenge.rs b/src/tool/core/helpers/daily_challenge.rs index f6aee33..690d162 100644 --- a/src/tool/core/helpers/daily_challenge.rs +++ b/src/tool/core/helpers/daily_challenge.rs @@ -16,7 +16,7 @@ struct DailyChallengeResponse { pub(crate) fn get_daily_challenge_slug() -> anyhow::Result { let daily_challenge_response = ureq::get(Config::LEETCODE_GRAPH_QL) .send_json(ureq::json!({ - "query": r"query questionOfToday { + "query": "query questionOfToday { activeDailyCodingChallengeQuestion { question { titleSlug