mirror of
https://github.com/nushell/nushell.git
synced 2024-12-27 17:39:15 +01:00
1ba2269aa9
# Description This PR fixes #9556. Now, only a section will be added if it contains a key, value pair. With this change, `{record with 0 fields}`, should not appear anymore. For more context on empty sections, see issue on the [crate](https://github.com/zonyitoo/rust-ini/issues/109) ``` open -r whatever | from ini ╭─────────────┬──────────────────────────────────────────────────────────────╮ │ │ ╭───────────────────────┬──────────────────────────────────╮ │ │ placeholder │ │ aws_access_key_id │ AAAAAAAAAAAAAAAAAAAAA │ │ │ │ │ aws_secret_access_key │ BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB │ │ │ │ ╰───────────────────────┴──────────────────────────────────╯ │ │ │ ╭───────────────────────┬──────────────────────────╮ │ │ default │ │ aws_access_key_id │ AAAAAAAAAAAAAAAAAA │ │ │ │ │ aws_secret_access_key │ AAAAAAAAAAAAAAAAAAAAAAA │ │ │ │ │ aws_session_token │ BBBBBBBBBBBBBBBBBBBBBBBB │ │ │ │ │ region │ us-east-1 │ │ │ │ │ output │ json │ │ │ │ ╰───────────────────────┴──────────────────────────╯ │ ╰─────────────┴──────────────────────────────────────────────────────────────╯ ``` # Tests + Formatting Now test for exact `from ini` output --------- Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
60 lines
1.7 KiB
Rust
60 lines
1.7 KiB
Rust
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
use nu_test_support::nu_with_plugins;
|
|
use nu_test_support::playground::Playground;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
const TEST_CWD: &str = "tests/fixtures/formats";
|
|
|
|
#[test]
|
|
fn parses_ini() {
|
|
let actual = nu_with_plugins!(
|
|
cwd: TEST_CWD,
|
|
plugin: ("nu_plugin_formats"),
|
|
"open sample.ini | to nuon -r"
|
|
);
|
|
|
|
assert_eq!(
|
|
actual.out,
|
|
r#"{SectionOne: {key: value, integer: "1234", real: "3.14", "string1": "Case 1", "string2": "Case 2"}, SectionTwo: {key: "new value", integer: "5678", real: "3.14", "string1": "Case 1", "string2": "Case 2", "string3": "Case 3"}}"#
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn parses_utf16_ini() {
|
|
let actual = nu_with_plugins!(
|
|
cwd: TEST_CWD,
|
|
plugin: ("nu_plugin_formats"),
|
|
"open ./utf16.ini --raw | decode utf-16 | from ini | get '.ShellClassInfo' | get IconIndex"
|
|
);
|
|
|
|
assert_eq!(actual.out, "-236")
|
|
}
|
|
|
|
#[test]
|
|
fn read_ini_with_missing_session() {
|
|
Playground::setup("from ini with missiong session", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
"some_missing.ini",
|
|
r#"
|
|
min-width=450
|
|
max-width=820
|
|
[normal]
|
|
sound-file=/usr/share/sounds/freedesktop/stereo/dialog-information.oga
|
|
[critical]
|
|
border-color=FAB387ff
|
|
default-timeout=20
|
|
sound-file=/usr/share/sounds/freedesktop/stereo/dialog-warning.oga
|
|
"#,
|
|
)]);
|
|
|
|
let cwd = dirs.test();
|
|
let actual = nu_with_plugins!(
|
|
cwd: cwd,
|
|
plugin: ("nu_plugin_formats"),
|
|
r#"open some_missing.ini | get "".min-width "#
|
|
);
|
|
|
|
assert_eq!(actual.out, "450");
|
|
})
|
|
}
|