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

Fix argument endpoint detection on replies #146

Merged
merged 2 commits into from
Apr 21, 2022
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
23 changes: 23 additions & 0 deletions src/tests/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ async fn standard_parse_url() {
assert_eq!(parser_result.code, "int main() {}");
}

#[tokio::test]
async fn standard_parse_url_args() {
let dummy_user = User::default();
let input = indoc::indoc!(
";compile c++ < https://pastebin.com/raw/ERqDRZva\ntest1 test2"
);

let reply = None;
let result = get_components(input, &dummy_user, None, &reply).await;
if let Err(_) = &result {
assert!(false, "Parser failed.");
}

let parser_result = result.unwrap();
println!("{:?}", &parser_result);
assert_eq!(parser_result.target, "c++");
assert_eq!(parser_result.args, ["test1", "test2"]);
assert_eq!(parser_result.options.len(), 0);
assert_eq!(parser_result.stdin, "");
assert_eq!(parser_result.url, "https://pastebin.com/raw/ERqDRZva");
assert_eq!(parser_result.code, "int main() {}");
}

#[tokio::test]
async fn standard_parse_stdin() {
let dummy_user = User::default();
Expand Down
5 changes: 1 addition & 4 deletions src/utls/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub async fn get_components(input: &str, author : &User, compilation_manager : O
let mut result = ParserResult::default();

// Find the index for where we should stop parsing user input
let mut end_point: usize = 0;
let mut end_point: usize = input.len();
if let Some(parse_stop) = input.find("\n") {
end_point = parse_stop;
}
Expand All @@ -53,10 +53,7 @@ pub async fn get_components(input: &str, author : &User, compilation_manager : O
else if index < end_point {
end_point = index;
}
} else {
end_point = input.len();
}

let mut args: Vec<&str> = input[..end_point].split_whitespace().collect();
// ditch command str (;compile, ;asm)
args.remove(0);
Expand Down