Requested changes

This commit is contained in:
simon-curtis 2024-11-08 09:43:50 +00:00 committed by Simon Curtis
parent ced3866916
commit 946da5ea5f
4 changed files with 25 additions and 31 deletions

View File

@ -162,17 +162,15 @@ pub fn check_example_evaluates_to_expected_output(
if let Some(expected) = example.result.as_ref() { if let Some(expected) = example.result.as_ref() {
let expected = DebuggableValue(expected); let expected = DebuggableValue(expected);
let result = DebuggableValue(&result); let result = DebuggableValue(&result);
if result != expected { assert_eq!(
assert_eq!( result,
result, expected,
expected, "Error: The result of example '{}' for the command '{}' differs from the expected value.\n\nExpected: {:?}\nActual: {:?}\n",
"\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,
example.description, cmd_name,
cmd_name, expected,
expected, result,
result, );
);
}
} }
} }

View File

@ -85,15 +85,14 @@ impl Command for BytesAt {
}; };
if let PipelineData::ByteStream(stream, metadata) = input { if let PipelineData::ByteStream(stream, metadata) = input {
match stream.slice( let stream = stream.slice(
call.head, call.head,
call.arguments_span(), call.arguments_span(),
args.indexes.0, args.indexes.0,
args.indexes.1, args.indexes.1,
) { )?;
Ok(stream) => Ok(PipelineData::ByteStream(stream, metadata)),
Err(err) => Err(err), Ok(PipelineData::ByteStream(stream, metadata))
}
} else { } else {
operate(map_value, args, input, call.head, engine_state.signals()) 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; let range = &args.indexes;
match input { match input {
Value::Binary { val, .. } => { 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 iter = val.iter().copied();
let bytes: Vec<u8> = if start > end { 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 { let start = match range.0 {
start if start < 0 => match len as isize + start { start if start < 0 => len.checked_sub(start.abs() as usize).unwrap_or(0),
start if start < 0 => 0,
start => start as usize,
},
start => start as usize, start => start as usize,
}; };
let end = match range.1 { 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, end => end as usize,
}; };

View File

@ -94,10 +94,10 @@ impl Command for Skip {
PipelineData::ByteStream(stream, metadata) => { PipelineData::ByteStream(stream, metadata) => {
if stream.type_().is_binary_coercible() { if stream.type_().is_binary_coercible() {
let span = stream.span(); let span = stream.span();
match stream.skip(span, n as u64) { Ok(PipelineData::ByteStream(
Ok(stream) => Ok(PipelineData::ByteStream(stream, metadata)), stream.skip(span, n as u64)?,
Err(err) => Err(err), metadata,
} ))
} else { } else {
Err(ShellError::OnlySupportsThisInputType { Err(ShellError::OnlySupportsThisInputType {
exp_input_type: "list, binary or range".into(), exp_input_type: "list, binary or range".into(),

View File

@ -89,10 +89,10 @@ impl Command for Take {
PipelineData::ByteStream(stream, metadata) => { PipelineData::ByteStream(stream, metadata) => {
if stream.type_().is_binary_coercible() { if stream.type_().is_binary_coercible() {
let span = stream.span(); let span = stream.span();
match stream.take(span, rows_desired as u64) { Ok(PipelineData::ByteStream(
Ok(stream) => Ok(PipelineData::ByteStream(stream, metadata)), stream.take(span, rows_desired as u64)?,
Err(err) => Err(err), metadata,
} ))
} else { } else {
Err(ShellError::OnlySupportsThisInputType { Err(ShellError::OnlySupportsThisInputType {
exp_input_type: "list, binary or range".into(), exp_input_type: "list, binary or range".into(),