Tests passing

This commit is contained in:
Simon Curtis
2024-11-19 11:19:54 +00:00
committed by Simon Curtis
parent a13c71e631
commit 69f373850f
5 changed files with 110 additions and 65 deletions

View File

@ -5,18 +5,27 @@ pub fn returns_error_for_relative_range_on_infinite_stream() {
let actual = nu!("nu --testbin iecho 3 | bytes at ..-3");
assert!(
actual.err.contains(
"Relative range values cannot be used with streams that don't specify a length"
"Relative range values cannot be used with streams that don't have a known length"
),
"Expected error message for negative range with infinite stream"
);
}
#[test]
pub fn returns_bytes_for_fixed_range_on_infinite_stream() {
pub fn returns_bytes_for_fixed_range_on_infinite_stream_including_end() {
let actual = nu!("nu --testbin iecho 3 | bytes at ..10 | decode");
assert_eq!(
actual.out, "33333",
"Expected bytes from index 1 to 10, but got different output"
"Expected bytes from index 0 to 10, but got different output"
);
}
#[test]
pub fn returns_bytes_for_fixed_range_on_infinite_stream_excluding_end() {
let actual = nu!("nu --testbin iecho 3 | bytes at ..<9 | decode");
assert_eq!(
actual.out, "3333",
"Expected bytes from index 0 to 8, but got different output"
);
}
@ -28,7 +37,7 @@ pub fn test_string_returns_correct_slice_for_simple_positive_slice() {
#[test]
pub fn test_string_returns_correct_slice_for_negative_start() {
let actual = nu!("\"Hello World\" | encode utf8 | bytes at 6..11 | decode");
let actual = nu!("\"Hello World\" | encode utf8 | bytes at (-5)..10 | decode");
assert_eq!(actual.out, "World");
}
@ -46,7 +55,7 @@ pub fn test_string_returns_correct_slice_for_empty_slice() {
#[test]
pub fn test_string_returns_correct_slice_for_out_of_bounds() {
let actual = nu!("\"Hello World\" | encode utf8 | bytes at 0..20 | decode");
let actual = nu!("\"Hello World\" | encode utf8 | bytes at ..20 | decode");
assert_eq!(actual.out, "Hello World");
}