forked from extern/nushell
allow Range to expand to array-like when converting to json (#8047)
# Description Fixes #8002, which expands ranges `1..3` to expand to array-like when saving and converting to json. Now, ``` > 1..3 | save foo.json # foo.json [ 1, 2, 3 ] > 1..3 | to json [ 1, 2, 3 ] ``` # User-Facing Changes _(List of all changes that impact the user experience here. This helps us keep track of breaking changes.)_ # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - [X] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - [X] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - [X] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
@ -108,3 +108,26 @@ fn top_level_values_from_json() {
|
||||
assert_eq!(actual.out, type_name);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ranges_to_json_as_array() {
|
||||
let value = r#"[ 1, 2, 3]"#;
|
||||
let actual = nu!(r#"1..3 | to json"#);
|
||||
assert_eq!(actual.out, value);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unbounded_from_in_range_fails() {
|
||||
let actual = nu!(r#"1.. | to json"#);
|
||||
assert!(actual.err.contains("Cannot create range"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inf_in_range_fails() {
|
||||
let actual = nu!(r#"inf..5 | to json"#);
|
||||
assert!(actual.err.contains("Cannot create range"));
|
||||
let actual = nu!(r#"5..inf | to json"#);
|
||||
assert!(actual.err.contains("Cannot create range"));
|
||||
let actual = nu!(r#"-inf..inf | to json"#);
|
||||
assert!(actual.err.contains("Cannot create range"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user