mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 16:33:37 +01:00
Improve expr parse (#3584)
* Require '-' to be a number for math * Add test * improve parse logic, add test
This commit is contained in:
parent
440e12abc4
commit
e8a2250ef8
@ -1577,7 +1577,7 @@ fn parse_internal_command(
|
|||||||
let arg = {
|
let arg = {
|
||||||
let (new_idx, expr, err) = parse_positional_argument(
|
let (new_idx, expr, err) = parse_positional_argument(
|
||||||
idx,
|
idx,
|
||||||
&lite_cmd,
|
lite_cmd,
|
||||||
&signature.positional[current_positional].0,
|
&signature.positional[current_positional].0,
|
||||||
signature.positional.len() - current_positional - 1,
|
signature.positional.len() - current_positional - 1,
|
||||||
scope,
|
scope,
|
||||||
@ -1802,7 +1802,14 @@ fn parse_call(
|
|||||||
} else if lite_cmd.parts[0].item.starts_with('$')
|
} else if lite_cmd.parts[0].item.starts_with('$')
|
||||||
|| lite_cmd.parts[0].item.starts_with('\"')
|
|| lite_cmd.parts[0].item.starts_with('\"')
|
||||||
|| lite_cmd.parts[0].item.starts_with('\'')
|
|| lite_cmd.parts[0].item.starts_with('\'')
|
||||||
|| lite_cmd.parts[0].item.starts_with('-')
|
|| (lite_cmd.parts[0].item.starts_with('-')
|
||||||
|
&& parse_arg(SyntaxShape::Number, scope, &lite_cmd.parts[0])
|
||||||
|
.1
|
||||||
|
.is_none())
|
||||||
|
|| (lite_cmd.parts[0].item.starts_with('-')
|
||||||
|
&& parse_arg(SyntaxShape::Range, scope, &lite_cmd.parts[0])
|
||||||
|
.1
|
||||||
|
.is_none())
|
||||||
|| lite_cmd.parts[0].item.starts_with('0')
|
|| lite_cmd.parts[0].item.starts_with('0')
|
||||||
|| lite_cmd.parts[0].item.starts_with('1')
|
|| lite_cmd.parts[0].item.starts_with('1')
|
||||||
|| lite_cmd.parts[0].item.starts_with('2')
|
|| lite_cmd.parts[0].item.starts_with('2')
|
||||||
|
@ -618,6 +618,29 @@ fn index_out_of_bounds() {
|
|||||||
assert!(actual.err.contains("unknown row"));
|
assert!(actual.err.contains("unknown row"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dash_def() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: ".",
|
||||||
|
r#"
|
||||||
|
def - [x, y] { $x - $y }; - 4 1
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "3");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn negative_decimal_start() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: ".",
|
||||||
|
r#"
|
||||||
|
-1.3 + 4
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "2.7");
|
||||||
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn index_row() {
|
fn index_row() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
|
Loading…
Reference in New Issue
Block a user