Simplify split_args
code, add a unit test for it and run it into CI
This commit is contained in:
parent
db9b932314
commit
95dfe5ec90
9
.github/workflows/ci.yml
vendored
9
.github/workflows/ci.yml
vendored
@ -131,3 +131,12 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: python tools/check_intrinsics_duplicates.py
|
||||
|
||||
build_system:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Test build system
|
||||
run: |
|
||||
cd build_system
|
||||
cargo test
|
||||
|
@ -306,7 +306,6 @@ pub fn split_args(args: &str) -> Result<Vec<String>, String> {
|
||||
let args = args.trim();
|
||||
let mut iter = args.char_indices().peekable();
|
||||
|
||||
while iter.peek().is_some() {
|
||||
while let Some((pos, c)) = iter.next() {
|
||||
if c == ' ' {
|
||||
out.push(args[start..pos].to_string());
|
||||
@ -347,7 +346,6 @@ pub fn split_args(args: &str) -> Result<Vec<String>, String> {
|
||||
iter.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
let s = args[start..].trim();
|
||||
if !s.is_empty() {
|
||||
out.push(s.to_string());
|
||||
@ -364,3 +362,26 @@ pub fn remove_file<P: AsRef<Path>>(file_path: &P) -> Result<(), String> {
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_split_args() {
|
||||
// Missing `"` at the end.
|
||||
assert!(split_args("\"tada").is_err());
|
||||
// Missing `'` at the end.
|
||||
assert!(split_args("\'tada").is_err());
|
||||
|
||||
assert_eq!(
|
||||
split_args("a \"b\" c"),
|
||||
Ok(vec!["a".to_string(), "\"b\"".to_string(), "c".to_string()])
|
||||
);
|
||||
// Trailing whitespace characters.
|
||||
assert_eq!(
|
||||
split_args(" a \"b\" c "),
|
||||
Ok(vec!["a".to_string(), "\"b\"".to_string(), "c".to_string()])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user