mirror of
https://github.com/nushell/nushell.git
synced 2024-11-28 19:33:47 +01:00
ea6493c041
# Description - fixes #14174 This PR addresses a bug in the `seq char` command where the command's behavior did not align with its help description, which stated that it prints a sequence of ASCII characters. The initial implementation only allowed alphabetic characters, leading to user confusion when non-alphabetic characters (e.g., digits, punctuation) were rejected or when unexpected behavior occurred for certain input ranges. ### Changes Made: - **Updated the input validation**: Modified the `is_single_character` function to accept any ASCII character instead of restricting to alphabetic characters. - **Enhanced error messages**: Clarified error messages to specify that any single ASCII character is acceptable. - **Expanded functionality**: Ensured that the command can now generate sequences that include non-alphabetic ASCII characters. - **Updated tests**: Added tests to cover new use cases involving non-alphabetic characters and improved validation. ### Examples After Fix: - `seq char '0' '9'` now outputs `['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']` - `seq char ' ' '/'` outputs a list of characters from space to `/` - `seq char 'A' 'z'` correctly includes alphabetic and non-alphabetic characters between `A` and `z` # User-Facing Changes - Users can now input any single ASCII character for the `start` and `end` parameters of `seq char`. - The output will accurately include all characters within the specified ASCII range, including digits and punctuation. # Tests + Formatting - Added new tests to ensure the `seq char` command supports sequences including non-alphabetic ASCII characters.
59 lines
1.2 KiB
Rust
59 lines
1.2 KiB
Rust
use nu_test_support::nu;
|
|
|
|
#[test]
|
|
fn fails_when_first_arg_is_multiple_chars() {
|
|
let actual = nu!("seq char aa z");
|
|
|
|
assert!(actual
|
|
.err
|
|
.contains("input should be a single ASCII character"));
|
|
}
|
|
|
|
#[test]
|
|
fn fails_when_second_arg_is_multiple_chars() {
|
|
let actual = nu!("seq char a zz");
|
|
|
|
assert!(actual
|
|
.err
|
|
.contains("input should be a single ASCII character"));
|
|
}
|
|
|
|
#[test]
|
|
fn generates_sequence_from_a_to_e() {
|
|
let actual = nu!("seq char a e | str join ''");
|
|
|
|
assert_eq!(actual.out, "abcde");
|
|
}
|
|
|
|
#[test]
|
|
fn generates_sequence_from_e_to_a() {
|
|
let actual = nu!("seq char e a | str join ''");
|
|
|
|
assert_eq!(actual.out, "edcba");
|
|
}
|
|
|
|
#[test]
|
|
fn fails_when_non_ascii_character_is_used_in_first_arg() {
|
|
let actual = nu!("seq char ñ z");
|
|
|
|
assert!(actual
|
|
.err
|
|
.contains("input should be a single ASCII character"));
|
|
}
|
|
|
|
#[test]
|
|
fn fails_when_non_ascii_character_is_used_in_second_arg() {
|
|
let actual = nu!("seq char a ñ");
|
|
|
|
assert!(actual
|
|
.err
|
|
.contains("input should be a single ASCII character"));
|
|
}
|
|
|
|
#[test]
|
|
fn joins_sequence_with_pipe() {
|
|
let actual = nu!("seq char a e | str join '|'");
|
|
|
|
assert_eq!(actual.out, "a|b|c|d|e");
|
|
}
|