mirror of
https://github.com/nushell/nushell.git
synced 2024-12-25 00:19:39 +01:00
Use int
type name consistently (#10579)
# Description When referring to the type use `int` consistently. Only when referring to the concept of integer numbers use `integer`. - Fix `random integer` to `random int` tests - Forgot in #10520 - Use int instead of integer in error messages - Use int type name in bits commands - Fix messages in `for` examples - Use int typename in `into` commands - Use int typename in rest of commands - Report errors in `nu-protocol` with int typename Work for #10332 # User-Facing Changes User errorrs should now use `int` so you can easily find the necessary commands or type annotations. # Tests + Formatting Only two tests found that needed updating
This commit is contained in:
parent
2cc4191ec9
commit
7c1487e18d
@ -91,7 +91,7 @@ impl Command for Commandline {
|
|||||||
from_type: "string".to_string(),
|
from_type: "string".to_string(),
|
||||||
span: cmd.span(),
|
span: cmd.span(),
|
||||||
help: Some(format!(
|
help: Some(format!(
|
||||||
r#"string "{cmd_str}" does not represent a valid integer"#
|
r#"string "{cmd_str}" does not represent a valid int"#
|
||||||
)),
|
)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -22,16 +22,12 @@ impl Command for BitsAnd {
|
|||||||
Type::List(Box::new(Type::Int)),
|
Type::List(Box::new(Type::Int)),
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
.required(
|
.required("target", SyntaxShape::Int, "target int to perform bit and")
|
||||||
"target",
|
|
||||||
SyntaxShape::Int,
|
|
||||||
"target integer to perform bit and",
|
|
||||||
)
|
|
||||||
.category(Category::Bits)
|
.category(Category::Bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
"Performs bitwise and for integers."
|
"Performs bitwise and for ints."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_terms(&self) -> Vec<&str> {
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
@ -85,7 +81,7 @@ fn operate(value: Value, target: i64, head: Span) -> Value {
|
|||||||
Value::Error { .. } => value,
|
Value::Error { .. } => value,
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "integer".into(),
|
exp_input_type: "int".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: head,
|
dst_span: head,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -219,7 +219,7 @@ pub fn action(input: &Value, _args: &Arguments, span: Span) -> Value {
|
|||||||
Value::Error { .. } => input.clone(),
|
Value::Error { .. } => input.clone(),
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "integer, filesize, string, date, duration, binary or bool".into(),
|
exp_input_type: "int, filesize, string, date, duration, binary, or bool".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: span,
|
dst_span: span,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -158,7 +158,7 @@ fn operate(value: Value, head: Span, signed: bool, number_size: NumberBytes) ->
|
|||||||
Value::Error { .. } => other,
|
Value::Error { .. } => other,
|
||||||
_ => Value::error(
|
_ => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "integer".into(),
|
exp_input_type: "int".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: head,
|
dst_span: head,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -22,16 +22,12 @@ impl Command for BitsOr {
|
|||||||
Type::List(Box::new(Type::Int)),
|
Type::List(Box::new(Type::Int)),
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
.required(
|
.required("target", SyntaxShape::Int, "target int to perform bit or")
|
||||||
"target",
|
|
||||||
SyntaxShape::Int,
|
|
||||||
"target integer to perform bit or",
|
|
||||||
)
|
|
||||||
.category(Category::Bits)
|
.category(Category::Bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
"Performs bitwise or for integers."
|
"Performs bitwise or for ints."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_terms(&self) -> Vec<&str> {
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
@ -85,7 +81,7 @@ fn operate(value: Value, target: i64, head: Span) -> Value {
|
|||||||
Value::Error { .. } => value,
|
Value::Error { .. } => value,
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "integer".into(),
|
exp_input_type: "int".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: head,
|
dst_span: head,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -41,7 +41,7 @@ impl Command for BitsRol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
"Bitwise rotate left for integers."
|
"Bitwise rotate left for ints."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_terms(&self) -> Vec<&str> {
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
@ -145,7 +145,7 @@ fn operate(value: Value, bits: usize, head: Span, signed: bool, number_size: Num
|
|||||||
Value::Error { .. } => value,
|
Value::Error { .. } => value,
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "integer".into(),
|
exp_input_type: "int".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: head,
|
dst_span: head,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -41,7 +41,7 @@ impl Command for BitsRor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
"Bitwise rotate right for integers."
|
"Bitwise rotate right for ints."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_terms(&self) -> Vec<&str> {
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
@ -149,7 +149,7 @@ fn operate(value: Value, bits: usize, head: Span, signed: bool, number_size: Num
|
|||||||
Value::Error { .. } => value,
|
Value::Error { .. } => value,
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "integer".into(),
|
exp_input_type: "int".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: head,
|
dst_span: head,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -41,7 +41,7 @@ impl Command for BitsShl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
"Bitwise shift left for integers."
|
"Bitwise shift left for ints."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_terms(&self) -> Vec<&str> {
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
@ -169,7 +169,7 @@ fn operate(value: Value, bits: usize, head: Span, signed: bool, number_size: Num
|
|||||||
Value::Error { .. } => value,
|
Value::Error { .. } => value,
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "integer".into(),
|
exp_input_type: "int".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: head,
|
dst_span: head,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -41,7 +41,7 @@ impl Command for BitsShr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
"Bitwise shift right for integers."
|
"Bitwise shift right for ints."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_terms(&self) -> Vec<&str> {
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
@ -159,7 +159,7 @@ fn operate(value: Value, bits: usize, head: Span, signed: bool, number_size: Num
|
|||||||
Value::Error { .. } => value,
|
Value::Error { .. } => value,
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "integer".into(),
|
exp_input_type: "int".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: head,
|
dst_span: head,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -22,16 +22,12 @@ impl Command for BitsXor {
|
|||||||
Type::List(Box::new(Type::Int)),
|
Type::List(Box::new(Type::Int)),
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
.required(
|
.required("target", SyntaxShape::Int, "target int to perform bit xor")
|
||||||
"target",
|
|
||||||
SyntaxShape::Int,
|
|
||||||
"target integer to perform bit xor",
|
|
||||||
)
|
|
||||||
.category(Category::Bits)
|
.category(Category::Bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
"Performs bitwise xor for integers."
|
"Performs bitwise xor for ints."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_terms(&self) -> Vec<&str> {
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
@ -84,7 +80,7 @@ fn operate(value: Value, target: i64, head: Span) -> Value {
|
|||||||
Value::Error { .. } => value,
|
Value::Error { .. } => value,
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "integer".into(),
|
exp_input_type: "int".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: head,
|
dst_span: head,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -88,7 +88,7 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
|||||||
Value::Error { .. } => input.clone(),
|
Value::Error { .. } => input.clone(),
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "float , integer or filesize".into(),
|
exp_input_type: "float, int, or filesize".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: span,
|
dst_span: span,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -199,7 +199,7 @@ impl Command for For {
|
|||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![
|
vec![
|
||||||
Example {
|
Example {
|
||||||
description: "Echo the square of each integer",
|
description: "Print the square of each integer",
|
||||||
example: "for x in [1 2 3] { print ($x * $x) }",
|
example: "for x in [1 2 3] { print ($x * $x) }",
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
@ -209,7 +209,7 @@ impl Command for For {
|
|||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Number each item and echo a message",
|
description: "Number each item and print a message",
|
||||||
example:
|
example:
|
||||||
"for $it in ['bob' 'fred'] --numbered { print $\"($it.index) is ($it.item)\" }",
|
"for $it in ['bob' 'fred'] --numbered { print $\"($it.index) is ($it.item)\" }",
|
||||||
result: None,
|
result: None,
|
||||||
|
@ -115,8 +115,7 @@ impl Command for SubCommand {
|
|||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description:
|
description: "convert an int to a nushell binary primitive with compact enabled",
|
||||||
"convert an integer to a nushell binary primitive with compact enabled",
|
|
||||||
example: "10 | into binary --compact",
|
example: "10 | into binary --compact",
|
||||||
result: Some(Value::binary(vec![10], Span::test_data())),
|
result: Some(Value::binary(vec![10], Span::test_data())),
|
||||||
},
|
},
|
||||||
@ -172,7 +171,7 @@ pub fn action(input: &Value, _args: &Arguments, span: Span) -> Value {
|
|||||||
Value::Error { .. } => input.clone(),
|
Value::Error { .. } => input.clone(),
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "integer, float, filesize, string, date, duration, binary or bool"
|
exp_input_type: "int, float, filesize, string, date, duration, binary, or bool"
|
||||||
.into(),
|
.into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: span,
|
dst_span: span,
|
||||||
|
@ -90,7 +90,7 @@ impl Command for SubCommand {
|
|||||||
result: Some(Value::bool(true, span)),
|
result: Some(Value::bool(true, span)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "convert integer to boolean",
|
description: "convert int to boolean",
|
||||||
example: "1 | into bool",
|
example: "1 | into bool",
|
||||||
result: Some(Value::bool(true, span)),
|
result: Some(Value::bool(true, span)),
|
||||||
},
|
},
|
||||||
@ -159,7 +159,7 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
|||||||
Value::Error { .. } => input.clone(),
|
Value::Error { .. } => input.clone(),
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "bool, integer, float or string".into(),
|
exp_input_type: "bool, int, float or string".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: span,
|
dst_span: span,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -256,7 +256,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
|||||||
other => {
|
other => {
|
||||||
return Value::error(
|
return Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "string and integer".into(),
|
exp_input_type: "string and int".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: head,
|
dst_span: head,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -138,7 +138,7 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, head: Span) -> Value {
|
|||||||
Value::Error { .. } => input.clone(),
|
Value::Error { .. } => input.clone(),
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "string, integer or bool".into(),
|
exp_input_type: "string, int, or bool".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: head,
|
dst_span: head,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -136,7 +136,7 @@ pub fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
|||||||
Value::Nothing { .. } => Value::filesize(0, value_span),
|
Value::Nothing { .. } => Value::filesize(0, value_span),
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "string and integer".into(),
|
exp_input_type: "string and int".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: span,
|
dst_span: span,
|
||||||
src_span: value_span,
|
src_span: value_span,
|
||||||
|
@ -121,7 +121,7 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, head: Span) -> Value {
|
|||||||
Value::Error { .. } => input.clone(),
|
Value::Error { .. } => input.clone(),
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "string, integer or bool".into(),
|
exp_input_type: "string, int or bool".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: head,
|
dst_span: head,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -158,32 +158,32 @@ impl Command for SubCommand {
|
|||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![
|
vec![
|
||||||
Example {
|
Example {
|
||||||
description: "Convert string to integer in table",
|
description: "Convert string to int in table",
|
||||||
example: "[[num]; ['-5'] [4] [1.5]] | into int num",
|
example: "[[num]; ['-5'] [4] [1.5]] | into int num",
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert string to integer",
|
description: "Convert string to int",
|
||||||
example: "'2' | into int",
|
example: "'2' | into int",
|
||||||
result: Some(Value::test_int(2)),
|
result: Some(Value::test_int(2)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert float to integer",
|
description: "Convert float to int",
|
||||||
example: "5.9 | into int",
|
example: "5.9 | into int",
|
||||||
result: Some(Value::test_int(5)),
|
result: Some(Value::test_int(5)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert decimal string to integer",
|
description: "Convert decimal string to int",
|
||||||
example: "'5.9' | into int",
|
example: "'5.9' | into int",
|
||||||
result: Some(Value::test_int(5)),
|
result: Some(Value::test_int(5)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert file size to integer",
|
description: "Convert file size to int",
|
||||||
example: "4KB | into int",
|
example: "4KB | into int",
|
||||||
result: Some(Value::test_int(4000)),
|
result: Some(Value::test_int(4000)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert bool to integer",
|
description: "Convert bool to int",
|
||||||
example: "[false, true] | into int",
|
example: "[false, true] | into int",
|
||||||
result: Some(Value::list(
|
result: Some(Value::list(
|
||||||
vec![Value::test_int(0), Value::test_int(1)],
|
vec![Value::test_int(0), Value::test_int(1)],
|
||||||
@ -191,32 +191,32 @@ impl Command for SubCommand {
|
|||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert date to integer (Unix nanosecond timestamp)",
|
description: "Convert date to int (Unix nanosecond timestamp)",
|
||||||
example: "1983-04-13T12:09:14.123456789-05:00 | into int",
|
example: "1983-04-13T12:09:14.123456789-05:00 | into int",
|
||||||
result: Some(Value::test_int(419101754123456789)),
|
result: Some(Value::test_int(419101754123456789)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert to integer from binary",
|
description: "Convert to int from binary data (radix: 2)",
|
||||||
example: "'1101' | into int -r 2",
|
example: "'1101' | into int -r 2",
|
||||||
result: Some(Value::test_int(13)),
|
result: Some(Value::test_int(13)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert to integer from hex",
|
description: "Convert to int from hex",
|
||||||
example: "'FF' | into int -r 16",
|
example: "'FF' | into int -r 16",
|
||||||
result: Some(Value::test_int(255)),
|
result: Some(Value::test_int(255)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert octal string to integer",
|
description: "Convert octal string to int",
|
||||||
example: "'0o10132' | into int",
|
example: "'0o10132' | into int",
|
||||||
result: Some(Value::test_int(4186)),
|
result: Some(Value::test_int(4186)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert 0 padded string to integer",
|
description: "Convert 0 padded string to int",
|
||||||
example: "'0010132' | into int",
|
example: "'0010132' | into int",
|
||||||
result: Some(Value::test_int(10132)),
|
result: Some(Value::test_int(10132)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert 0 padded string to integer with radix",
|
description: "Convert 0 padded string to int with radix 8",
|
||||||
example: "'0010132' | into int -r 8",
|
example: "'0010132' | into int -r 8",
|
||||||
result: Some(Value::test_int(4186)),
|
result: Some(Value::test_int(4186)),
|
||||||
},
|
},
|
||||||
@ -248,7 +248,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
return Value::error(
|
return Value::error(
|
||||||
ShellError::CantConvert {
|
ShellError::CantConvert {
|
||||||
to_type: "float".to_string(),
|
to_type: "float".to_string(),
|
||||||
from_type: "integer".to_string(),
|
from_type: "int".to_string(),
|
||||||
span,
|
span,
|
||||||
help: None,
|
help: None,
|
||||||
},
|
},
|
||||||
@ -327,7 +327,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
Value::Error { .. } => input.clone(),
|
Value::Error { .. } => input.clone(),
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "integer, float, filesize, date, string, binary, duration or bool"
|
exp_input_type: "int, float, filesize, date, string, binary, duration, or bool"
|
||||||
.into(),
|
.into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: span,
|
dst_span: span,
|
||||||
@ -376,7 +376,7 @@ fn convert_int(input: &Value, head: Span, radix: u32) -> Value {
|
|||||||
other => {
|
other => {
|
||||||
return Value::error(
|
return Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
exp_input_type: "string and integer".into(),
|
exp_input_type: "string and int".into(),
|
||||||
wrong_type: other.get_type().to_string(),
|
wrong_type: other.get_type().to_string(),
|
||||||
dst_span: head,
|
dst_span: head,
|
||||||
src_span: other.span(),
|
src_span: other.span(),
|
||||||
|
@ -84,7 +84,7 @@ impl Command for SubCommand {
|
|||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![
|
vec![
|
||||||
Example {
|
Example {
|
||||||
description: "convert integer to string and append three decimal places",
|
description: "convert int to string and append three decimal places",
|
||||||
example: "5 | into string -d 3",
|
example: "5 | into string -d 3",
|
||||||
result: Some(Value::test_string("5.000")),
|
result: Some(Value::test_string("5.000")),
|
||||||
},
|
},
|
||||||
|
@ -41,7 +41,7 @@ only unwrap the outer list, and leave the variable's contents untouched."#
|
|||||||
vec![
|
vec![
|
||||||
Example {
|
Example {
|
||||||
example: "[0 1 2 3] | append 4",
|
example: "[0 1 2 3] | append 4",
|
||||||
description: "Append one integer to a list",
|
description: "Append one int to a list",
|
||||||
result: Some(Value::test_list(vec![
|
result: Some(Value::test_list(vec![
|
||||||
Value::test_int(0),
|
Value::test_int(0),
|
||||||
Value::test_int(1),
|
Value::test_int(1),
|
||||||
@ -70,7 +70,7 @@ only unwrap the outer list, and leave the variable's contents untouched."#
|
|||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
example: "[0 1] | append [2 3 4]",
|
example: "[0 1] | append [2 3 4]",
|
||||||
description: "Append three integer items",
|
description: "Append three int items",
|
||||||
result: Some(Value::test_list(vec![
|
result: Some(Value::test_list(vec![
|
||||||
Value::test_int(0),
|
Value::test_int(0),
|
||||||
Value::test_int(1),
|
Value::test_int(1),
|
||||||
@ -81,7 +81,7 @@ only unwrap the outer list, and leave the variable's contents untouched."#
|
|||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
example: "[0 1] | append [2 nu 4 shell]",
|
example: "[0 1] | append [2 nu 4 shell]",
|
||||||
description: "Append integers and strings",
|
description: "Append ints and strings",
|
||||||
result: Some(Value::test_list(vec![
|
result: Some(Value::test_list(vec![
|
||||||
Value::test_int(0),
|
Value::test_int(0),
|
||||||
Value::test_int(1),
|
Value::test_int(1),
|
||||||
@ -93,7 +93,7 @@ only unwrap the outer list, and leave the variable's contents untouched."#
|
|||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
example: "[0 1] | append 2..4",
|
example: "[0 1] | append 2..4",
|
||||||
description: "Append a range of integers to a list",
|
description: "Append a range of ints to a list",
|
||||||
result: Some(Value::test_list(vec![
|
result: Some(Value::test_list(vec![
|
||||||
Value::test_int(0),
|
Value::test_int(0),
|
||||||
Value::test_int(1),
|
Value::test_int(1),
|
||||||
|
@ -122,7 +122,7 @@ impl Command for DropNth {
|
|||||||
if from.is_negative() || to.is_negative() {
|
if from.is_negative() || to.is_negative() {
|
||||||
let span: Spanned<Range> = call.req(engine_state, stack, 0)?;
|
let span: Spanned<Range> = call.req(engine_state, stack, 0)?;
|
||||||
return Err(ShellError::TypeMismatch {
|
return Err(ShellError::TypeMismatch {
|
||||||
err_message: "drop nth accepts only positive integers".to_string(),
|
err_message: "drop nth accepts only positive ints".to_string(),
|
||||||
span: span.span,
|
span: span.span,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ only unwrap the outer list, and leave the variable's contents untouched."#
|
|||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
example: "[1 2 3 4] | prepend 0",
|
example: "[1 2 3 4] | prepend 0",
|
||||||
description: "Prepend one integer item",
|
description: "Prepend one int item",
|
||||||
result: Some(Value::test_list(vec![
|
result: Some(Value::test_list(vec![
|
||||||
Value::test_int(0),
|
Value::test_int(0),
|
||||||
Value::test_int(1),
|
Value::test_int(1),
|
||||||
@ -73,7 +73,7 @@ only unwrap the outer list, and leave the variable's contents untouched."#
|
|||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
example: "[2 3 4] | prepend [0 1]",
|
example: "[2 3 4] | prepend [0 1]",
|
||||||
description: "Prepend two integer items",
|
description: "Prepend two int items",
|
||||||
result: Some(Value::test_list(vec![
|
result: Some(Value::test_list(vec![
|
||||||
Value::test_int(0),
|
Value::test_int(0),
|
||||||
Value::test_int(1),
|
Value::test_int(1),
|
||||||
@ -84,7 +84,7 @@ only unwrap the outer list, and leave the variable's contents untouched."#
|
|||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
example: "[2 nu 4 shell] | prepend [0 1 rocks]",
|
example: "[2 nu 4 shell] | prepend [0 1 rocks]",
|
||||||
description: "Prepend integers and strings",
|
description: "Prepend ints and strings",
|
||||||
result: Some(Value::test_list(vec![
|
result: Some(Value::test_list(vec![
|
||||||
Value::test_int(0),
|
Value::test_int(0),
|
||||||
Value::test_int(1),
|
Value::test_int(1),
|
||||||
|
@ -80,15 +80,13 @@ impl Command for Skip {
|
|||||||
match v {
|
match v {
|
||||||
Value::Int { val, .. } => {
|
Value::Int { val, .. } => {
|
||||||
val.try_into().map_err(|err| ShellError::TypeMismatch {
|
val.try_into().map_err(|err| ShellError::TypeMismatch {
|
||||||
err_message: format!(
|
err_message: format!("Could not convert {val} to unsigned int: {err}"),
|
||||||
"Could not convert {val} to unsigned integer: {err}"
|
|
||||||
),
|
|
||||||
span,
|
span,
|
||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(ShellError::TypeMismatch {
|
return Err(ShellError::TypeMismatch {
|
||||||
err_message: "expected integer".into(),
|
err_message: "expected int".into(),
|
||||||
span,
|
span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ impl Command for ToNuon {
|
|||||||
result: Some(Value::test_string("[1, 2, 3]"))
|
result: Some(Value::test_string("[1, 2, 3]"))
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Outputs a NUON array of integers, with pretty indentation",
|
description: "Outputs a NUON array of ints, with pretty indentation",
|
||||||
example: "[1 2 3] | to nuon --indent 2",
|
example: "[1 2 3] | to nuon --indent 2",
|
||||||
result: Some(Value::test_string("[\n 1,\n 2,\n 3\n]")),
|
result: Some(Value::test_string("[\n 1,\n 2,\n 3\n]")),
|
||||||
},
|
},
|
||||||
|
@ -283,8 +283,8 @@ pub fn run_seq_dates(
|
|||||||
Some(date) => date,
|
Some(date) => date,
|
||||||
None => {
|
None => {
|
||||||
return Err(ShellError::GenericError(
|
return Err(ShellError::GenericError(
|
||||||
"integer value too large".to_string(),
|
"int value too large".to_string(),
|
||||||
"integer value too large".to_string(),
|
"int value too large".to_string(),
|
||||||
Some(call_span),
|
Some(call_span),
|
||||||
None,
|
None,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
|
@ -108,7 +108,7 @@ pub fn calculate(
|
|||||||
PipelineData::Value(val, ..) => mf(&[val], span, name),
|
PipelineData::Value(val, ..) => mf(&[val], span, name),
|
||||||
PipelineData::Empty { .. } => Err(ShellError::PipelineEmpty { dst_span: name }),
|
PipelineData::Empty { .. } => Err(ShellError::PipelineEmpty { dst_span: name }),
|
||||||
val => Err(ShellError::UnsupportedInput(
|
val => Err(ShellError::UnsupportedInput(
|
||||||
"Only integers, floats, lists, records or ranges are supported".into(),
|
"Only ints, floats, lists, records, or ranges are supported".into(),
|
||||||
"value originates from here".into(),
|
"value originates from here".into(),
|
||||||
name,
|
name,
|
||||||
// This requires both the ListStream and Empty match arms to be above it.
|
// This requires both the ListStream and Empty match arms to be above it.
|
||||||
|
@ -66,8 +66,7 @@ fn sum_of_squares(values: &[Value], span: Span) -> Result<Value, ShellError> {
|
|||||||
Value::Int { .. } | Value::Float { .. } => Ok(value),
|
Value::Int { .. } | Value::Float { .. } => Ok(value),
|
||||||
Value::Error { error, .. } => Err(*error.clone()),
|
Value::Error { error, .. } => Err(*error.clone()),
|
||||||
_ => Err(ShellError::UnsupportedInput(
|
_ => Err(ShellError::UnsupportedInput(
|
||||||
"Attempted to compute the sum of squares of a non-integer, non-float value"
|
"Attempted to compute the sum of squares of a non-int, non-float value".to_string(),
|
||||||
.to_string(),
|
|
||||||
"value originates from here".into(),
|
"value originates from here".into(),
|
||||||
span,
|
span,
|
||||||
value.span(),
|
value.span(),
|
||||||
|
@ -288,7 +288,7 @@ pub fn request_set_timeout(
|
|||||||
let val = timeout.as_i64()?;
|
let val = timeout.as_i64()?;
|
||||||
if val.is_negative() || val < 1 {
|
if val.is_negative() || val < 1 {
|
||||||
return Err(ShellError::TypeMismatch {
|
return Err(ShellError::TypeMismatch {
|
||||||
err_message: "Timeout value must be an integer and larger than 0".to_string(),
|
err_message: "Timeout value must be an int and larger than 0".to_string(),
|
||||||
span: timeout.span(),
|
span: timeout.span(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ impl UrlComponents {
|
|||||||
}),
|
}),
|
||||||
Err(_) => Err(ShellError::IncompatibleParametersSingle {
|
Err(_) => Err(ShellError::IncompatibleParametersSingle {
|
||||||
msg: String::from(
|
msg: String::from(
|
||||||
"Port parameter should represent an unsigned integer",
|
"Port parameter should represent an unsigned int",
|
||||||
),
|
),
|
||||||
span: value_span,
|
span: value_span,
|
||||||
}),
|
}),
|
||||||
@ -172,7 +172,7 @@ impl UrlComponents {
|
|||||||
Value::Error { error, .. } => Err(*error),
|
Value::Error { error, .. } => Err(*error),
|
||||||
other => Err(ShellError::IncompatibleParametersSingle {
|
other => Err(ShellError::IncompatibleParametersSingle {
|
||||||
msg: String::from(
|
msg: String::from(
|
||||||
"Port parameter should be an unsigned integer or a string representing it",
|
"Port parameter should be an unsigned int or a string representing it",
|
||||||
),
|
),
|
||||||
span: other.span(),
|
span: other.span(),
|
||||||
}),
|
}),
|
||||||
|
@ -2,21 +2,21 @@ use nu_test_support::nu;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generates_an_integer() {
|
fn generates_an_integer() {
|
||||||
let actual = nu!("random integer 42..43");
|
let actual = nu!("random int 42..43");
|
||||||
|
|
||||||
assert!(actual.out.contains("42") || actual.out.contains("43"));
|
assert!(actual.out.contains("42") || actual.out.contains("43"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generates_55() {
|
fn generates_55() {
|
||||||
let actual = nu!("random integer 55..55");
|
let actual = nu!("random int 55..55");
|
||||||
|
|
||||||
assert!(actual.out.contains("55"));
|
assert!(actual.out.contains("55"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generates_0() {
|
fn generates_0() {
|
||||||
let actual = nu!("random integer ..<1");
|
let actual = nu!("random int ..<1");
|
||||||
|
|
||||||
assert!(actual.out.contains('0'));
|
assert!(actual.out.contains('0'));
|
||||||
}
|
}
|
@ -2,6 +2,6 @@ mod bool;
|
|||||||
mod chars;
|
mod chars;
|
||||||
mod dice;
|
mod dice;
|
||||||
mod float;
|
mod float;
|
||||||
mod integer;
|
mod int;
|
||||||
#[cfg(feature = "uuid_crate")]
|
#[cfg(feature = "uuid_crate")]
|
||||||
mod uuid;
|
mod uuid;
|
||||||
|
@ -245,7 +245,7 @@ fn url_join_with_invalid_port() {
|
|||||||
|
|
||||||
assert!(actual
|
assert!(actual
|
||||||
.err
|
.err
|
||||||
.contains("Port parameter should represent an unsigned integer"));
|
.contains("Port parameter should represent an unsigned int"));
|
||||||
|
|
||||||
let actual = nu!(pipeline(
|
let actual = nu!(pipeline(
|
||||||
r#"
|
r#"
|
||||||
@ -259,7 +259,7 @@ fn url_join_with_invalid_port() {
|
|||||||
|
|
||||||
assert!(actual
|
assert!(actual
|
||||||
.err
|
.err
|
||||||
.contains("Port parameter should be an unsigned integer or a string representing it"));
|
.contains("Port parameter should be an unsigned int or a string representing it"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -26,7 +26,7 @@ impl FromValue for Spanned<i64> {
|
|||||||
Value::Duration { val, .. } => Ok(Spanned { item: *val, span }),
|
Value::Duration { val, .. } => Ok(Spanned { item: *val, span }),
|
||||||
|
|
||||||
v => Err(ShellError::CantConvert {
|
v => Err(ShellError::CantConvert {
|
||||||
to_type: "integer".into(),
|
to_type: "int".into(),
|
||||||
from_type: v.get_type().to_string(),
|
from_type: v.get_type().to_string(),
|
||||||
span: v.span(),
|
span: v.span(),
|
||||||
help: None,
|
help: None,
|
||||||
@ -43,7 +43,7 @@ impl FromValue for i64 {
|
|||||||
Value::Duration { val, .. } => Ok(*val),
|
Value::Duration { val, .. } => Ok(*val),
|
||||||
|
|
||||||
v => Err(ShellError::CantConvert {
|
v => Err(ShellError::CantConvert {
|
||||||
to_type: "integer".into(),
|
to_type: "int".into(),
|
||||||
from_type: v.get_type().to_string(),
|
from_type: v.get_type().to_string(),
|
||||||
span: v.span(),
|
span: v.span(),
|
||||||
help: None,
|
help: None,
|
||||||
@ -123,7 +123,7 @@ impl FromValue for Spanned<usize> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
v => Err(ShellError::CantConvert {
|
v => Err(ShellError::CantConvert {
|
||||||
to_type: "non-negative integer".into(),
|
to_type: "non-negative int".into(),
|
||||||
from_type: v.get_type().to_string(),
|
from_type: v.get_type().to_string(),
|
||||||
span: v.span(),
|
span: v.span(),
|
||||||
help: None,
|
help: None,
|
||||||
@ -159,7 +159,7 @@ impl FromValue for usize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
v => Err(ShellError::CantConvert {
|
v => Err(ShellError::CantConvert {
|
||||||
to_type: "non-negative integer".into(),
|
to_type: "non-negative int".into(),
|
||||||
from_type: v.get_type().to_string(),
|
from_type: v.get_type().to_string(),
|
||||||
span: v.span(),
|
span: v.span(),
|
||||||
help: None,
|
help: None,
|
||||||
|
@ -255,7 +255,7 @@ impl Value {
|
|||||||
match self {
|
match self {
|
||||||
Value::Int { val, .. } => Ok(*val),
|
Value::Int { val, .. } => Ok(*val),
|
||||||
x => Err(ShellError::CantConvert {
|
x => Err(ShellError::CantConvert {
|
||||||
to_type: "integer".into(),
|
to_type: "int".into(),
|
||||||
from_type: x.get_type().to_string(),
|
from_type: x.get_type().to_string(),
|
||||||
span: self.span(),
|
span: self.span(),
|
||||||
help: None,
|
help: None,
|
||||||
|
@ -124,6 +124,6 @@ fn commandline_test_cursor_invalid() -> TestResult {
|
|||||||
fail_test(
|
fail_test(
|
||||||
"commandline --replace '123456'\n\
|
"commandline --replace '123456'\n\
|
||||||
commandline --cursor 'abc'",
|
commandline --cursor 'abc'",
|
||||||
r#"string "abc" does not represent a valid integer"#,
|
r#"string "abc" does not represent a valid int"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user