Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove uncessary raw strings #79

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tool/core/helpers/code_snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) fn get_code_snippet_for_problem(title_slug: &str) -> anyhow::Result<P
// Add todo!() placeholders in function bodies
let re = Regex::new(r"\{\s*\}")?;
result = re
.replace_all(&result, "{ todo!(\"Fill in body\") }")
.replace_all(&result, r#"{ todo!("Fill in body") }"#)
.to_string();

result.try_into()
Expand Down
2 changes: 1 addition & 1 deletion src/tool/core/helpers/daily_challenge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct DailyChallengeResponse {
pub(crate) fn get_daily_challenge_slug() -> anyhow::Result<String> {
let daily_challenge_response = ureq::get(Config::LEETCODE_GRAPH_QL)
.send_json(ureq::json!({
"query": r"query questionOfToday {
"query": "query questionOfToday {
activeDailyCodingChallengeQuestion {
question {
titleSlug
Expand Down
28 changes: 15 additions & 13 deletions src/tool/core/helpers/problem_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ impl FunctionArgType {
Err(e) => 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}");
Expand Down Expand Up @@ -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]";

Expand Down Expand Up @@ -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]"),
Expand Down Expand Up @@ -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);
Expand Down