mirror of
https://github.com/nushell/nushell.git
synced 2025-01-06 22:40:01 +01:00
Requested changes
This commit is contained in:
parent
ced3866916
commit
946da5ea5f
@ -162,17 +162,15 @@ pub fn check_example_evaluates_to_expected_output(
|
||||
if let Some(expected) = example.result.as_ref() {
|
||||
let expected = DebuggableValue(expected);
|
||||
let result = DebuggableValue(&result);
|
||||
if result != expected {
|
||||
assert_eq!(
|
||||
result,
|
||||
expected,
|
||||
"\x1b[31mError:\x1b[0m The result of example \x1b[34m'{}'\x1b[0m for the command \x1b[34m'{}'\x1b[0m differs from the expected value.\n\nExpected: {:?}\nActual: {:?}\n",
|
||||
example.description,
|
||||
cmd_name,
|
||||
expected,
|
||||
result,
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
result,
|
||||
expected,
|
||||
"Error: The result of example '{}' for the command '{}' differs from the expected value.\n\nExpected: {:?}\nActual: {:?}\n",
|
||||
example.description,
|
||||
cmd_name,
|
||||
expected,
|
||||
result,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,15 +85,14 @@ impl Command for BytesAt {
|
||||
};
|
||||
|
||||
if let PipelineData::ByteStream(stream, metadata) = input {
|
||||
match stream.slice(
|
||||
let stream = stream.slice(
|
||||
call.head,
|
||||
call.arguments_span(),
|
||||
args.indexes.0,
|
||||
args.indexes.1,
|
||||
) {
|
||||
Ok(stream) => Ok(PipelineData::ByteStream(stream, metadata)),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
)?;
|
||||
|
||||
Ok(PipelineData::ByteStream(stream, metadata))
|
||||
} else {
|
||||
operate(map_value, args, input, call.head, engine_state.signals())
|
||||
}
|
||||
@ -150,7 +149,7 @@ fn map_value(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
let range = &args.indexes;
|
||||
match input {
|
||||
Value::Binary { val, .. } => {
|
||||
let (start, end) = resolve_relative_range(range, val.len());
|
||||
let (start, end) = resolve_relative_range(range, &val.len());
|
||||
let iter = val.iter().copied();
|
||||
|
||||
let bytes: Vec<u8> = if start > end {
|
||||
@ -176,17 +175,14 @@ fn map_value(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_relative_range(range: &Subbytes, len: usize) -> (usize, usize) {
|
||||
fn resolve_relative_range(range: &Subbytes, len: &usize) -> (usize, usize) {
|
||||
let start = match range.0 {
|
||||
start if start < 0 => match len as isize + start {
|
||||
start if start < 0 => 0,
|
||||
start => start as usize,
|
||||
},
|
||||
start if start < 0 => len.checked_sub(start.abs() as usize).unwrap_or(0),
|
||||
start => start as usize,
|
||||
};
|
||||
|
||||
let end = match range.1 {
|
||||
end if end < 0 => (len as isize + end) as usize,
|
||||
end if end < 0 => len.checked_sub(end.abs() as usize).unwrap_or(0),
|
||||
end => end as usize,
|
||||
};
|
||||
|
||||
|
@ -94,10 +94,10 @@ impl Command for Skip {
|
||||
PipelineData::ByteStream(stream, metadata) => {
|
||||
if stream.type_().is_binary_coercible() {
|
||||
let span = stream.span();
|
||||
match stream.skip(span, n as u64) {
|
||||
Ok(stream) => Ok(PipelineData::ByteStream(stream, metadata)),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
Ok(PipelineData::ByteStream(
|
||||
stream.skip(span, n as u64)?,
|
||||
metadata,
|
||||
))
|
||||
} else {
|
||||
Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "list, binary or range".into(),
|
||||
|
@ -89,10 +89,10 @@ impl Command for Take {
|
||||
PipelineData::ByteStream(stream, metadata) => {
|
||||
if stream.type_().is_binary_coercible() {
|
||||
let span = stream.span();
|
||||
match stream.take(span, rows_desired as u64) {
|
||||
Ok(stream) => Ok(PipelineData::ByteStream(stream, metadata)),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
Ok(PipelineData::ByteStream(
|
||||
stream.take(span, rows_desired as u64)?,
|
||||
metadata,
|
||||
))
|
||||
} else {
|
||||
Err(ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "list, binary or range".into(),
|
||||
|
Loading…
Reference in New Issue
Block a user