mirror of
https://github.com/nushell/nushell.git
synced 2025-04-03 14:10:41 +02:00
Fix fmt and small cleaning in nu-parser (#3033)
* parse_unit: reduce indentation in loop * fix fmt: crates/nu-parser/src/lex/tests.rs
This commit is contained in:
parent
e3a273cf73
commit
7f7e8465da
@ -218,7 +218,10 @@ mod lite_parse {
|
|||||||
#[test]
|
#[test]
|
||||||
fn incomplete_result() {
|
fn incomplete_result() {
|
||||||
let (result, err) = lex("my_command \"foo' --test", 10);
|
let (result, err) = lex("my_command \"foo' --test", 10);
|
||||||
assert!(matches!(err.unwrap().reason(), nu_errors::ParseErrorReason::Eof { .. }));
|
assert!(matches!(
|
||||||
|
err.unwrap().reason(),
|
||||||
|
nu_errors::ParseErrorReason::Eof { .. }
|
||||||
|
));
|
||||||
let (result, _) = block(result);
|
let (result, _) = block(result);
|
||||||
|
|
||||||
assert_eq!(result.block.len(), 1);
|
assert_eq!(result.block.len(), 1);
|
||||||
|
@ -346,7 +346,9 @@ fn parse_unit(lite_arg: &Spanned<String>) -> (SpannedExpression, Option<ParseErr
|
|||||||
|
|
||||||
for unit_group in unit_groups.iter() {
|
for unit_group in unit_groups.iter() {
|
||||||
for unit in unit_group.1.iter() {
|
for unit in unit_group.1.iter() {
|
||||||
if lite_arg.item.ends_with(unit) {
|
if !lite_arg.item.ends_with(unit) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let mut lhs = lite_arg.item.clone();
|
let mut lhs = lite_arg.item.clone();
|
||||||
|
|
||||||
for _ in 0..unit.len() {
|
for _ in 0..unit.len() {
|
||||||
@ -355,10 +357,8 @@ fn parse_unit(lite_arg: &Spanned<String>) -> (SpannedExpression, Option<ParseErr
|
|||||||
|
|
||||||
// these units are allowed to be signed
|
// these units are allowed to be signed
|
||||||
if let Ok(x) = lhs.parse::<i64>() {
|
if let Ok(x) = lhs.parse::<i64>() {
|
||||||
let lhs_span =
|
let lhs_span = Span::new(lite_arg.span.start(), lite_arg.span.start() + lhs.len());
|
||||||
Span::new(lite_arg.span.start(), lite_arg.span.start() + lhs.len());
|
let unit_span = Span::new(lite_arg.span.start() + lhs.len(), lite_arg.span.end());
|
||||||
let unit_span =
|
|
||||||
Span::new(lite_arg.span.start() + lhs.len(), lite_arg.span.end());
|
|
||||||
return (
|
return (
|
||||||
SpannedExpression::new(
|
SpannedExpression::new(
|
||||||
Expression::unit(x.spanned(lhs_span), unit_group.0.spanned(unit_span)),
|
Expression::unit(x.spanned(lhs_span), unit_group.0.spanned(unit_span)),
|
||||||
@ -369,7 +369,6 @@ fn parse_unit(lite_arg: &Spanned<String>) -> (SpannedExpression, Option<ParseErr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
(
|
(
|
||||||
garbage(lite_arg.span),
|
garbage(lite_arg.span),
|
||||||
|
Loading…
Reference in New Issue
Block a user