Fix and Allow Number and Boolean type to be key in from yaml (#7607)

Fix and Allow Number and Boolean type to be key in Yaml .

For example : 
`"200 : " | from yaml` not allowed because of Number key type.

PR allow , we can use Boolean and Number for key. 
For example :
`"true : false" | from yaml`
`"5050 : it is number" | from yaml`

Fixes #7222 .
This commit is contained in:
Amirhossein Akhlaghpour
2022-12-27 11:28:24 -05:00
committed by GitHub
parent 4f812a7f34
commit 568927349d
2 changed files with 49 additions and 0 deletions

View File

@ -14,3 +14,40 @@ fn table_to_yaml_text_and_from_yaml_text_back_into_table() {
assert_eq!(actual.out, "nushell");
}
#[test]
fn convert_dict_to_yaml_with_boolean_key() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"true: BooleanKey " | from yaml
"#
));
assert!(actual.out.contains("BooleanKey"));
assert!(actual.err.is_empty());
}
#[test]
fn convert_dict_to_yaml_with_integer_key() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"200: [] " | from yaml
"#
));
assert!(actual.out.contains("200"));
assert!(actual.err.is_empty());
}
#[test]
fn convert_dict_to_yaml_with_integer_floats_key() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
"2.11: "1" " | from yaml
"#
));
assert!(actual.out.contains("2.11"));
assert!(actual.err.is_empty());
}