Repository: nushell/nushell
File: crates/nu-command/src/formats/to/nuon.rs (Rust)

Code before:
        } else if let Some(t) = call.get_flag(engine_state, stack, "tabs")? {
            nuon::ToStyle::Tabs(t)
        } else if let Some(i) = call.get_flag(engine_state, stack, "indent")? {
            nuon::ToStyle::Spaces(i)
        } else {
            nuon::ToStyle::Raw
        };

        let span = call.head;
        let value = input.into_value(span)?;

        match nuon::to_nuon(engine_state, &value, style, Some(span), serialize_types) {
            Ok(serde_nuon_string) => Ok(Value::string(serde_nuon_string, span)
                .into_pipeline_data_with_metadata(Some(metadata))),
            Err(error) => {
                Ok(Value::error(error, span).into_pipeline_data_with_metadata(Some(metadata)))
            }
        }
    }

    fn examples(&self) -> Vec<Example> {
        vec![
            Example {
                description: "Outputs a NUON string representing the contents of this list, compact by default",
                example: "[1 2 3] | to nuon",
                result: Some(Value::test_string("[1,2,3]"))
            },
            Example {
                description: "Outputs a NUON array of ints, with pretty indentation",
                example: "[1 2 3] | to nuon --indent 2",
                result: Some(Value::test_string("[\n  1,\n  2,\n  3\n]")),
            },
            Example {
                description: "Overwrite any set option with --raw",
                example: "[1 2 3] | to nuon --indent 2 --raw",
                result: Some(Value::test_string("[1,2,3]"))
            },
            Example {
                description: "A more complex record with multiple data types",
                example: "{date: 2000-01-01, data: [1 [2 3] 4.56]} | to nuon --indent 2",
                result: Some(Value::test_string("{\n  date: 2000-01-01T00:00:00+00:00,\n  data: [\n    1,\n    [\n      2,\n      3\n    ],\n    4.56\n  ]\n}"))
            },
            Example {
                description: "Removes as much whitespace as possible from a complex record",
                example: "{date: 2000-01-01, data: [1 [2 3] 4.56]} | to nuon",
                result: Some(Value::test_string("{date:2000-01-01T00:00:00+00:00,data:[1,[2,3],4.56]}"))
            },
        ]
    }
}


Review comment (bug):
Before you have to continue fighting with all the tests, I am not sure if our intention was to change the separator rules for bare `to nuon` without `--raw`, right?

To get the failing (Rust) tests you can run:

```
cargo test --workspace --no-fail-fast
```
This should keep going even on failures in one crate.

and for the standard library test:

```
use toolkit.nu *
test stdlib
```

Code after:
        } else if let Some(t) = call.get_flag(engine_state, stack, "tabs")? {
            nuon::ToStyle::Tabs(t)
        } else if let Some(i) = call.get_flag(engine_state, stack, "indent")? {
            nuon::ToStyle::Spaces(i)
        } else {
            nuon::ToStyle::Default
        };

        let span = call.head;
        let value = input.into_value(span)?;

        match nuon::to_nuon(engine_state, &value, style, Some(span), serialize_types) {
            Ok(serde_nuon_string) => Ok(Value::string(serde_nuon_string, span)
                .into_pipeline_data_with_metadata(Some(metadata))),
            Err(error) => {
                Ok(Value::error(error, span).into_pipeline_data_with_metadata(Some(metadata)))
            }
        }
    }

    fn examples(&self) -> Vec<Example> {
        vec![
            Example {
                description: "Outputs a NUON string representing the contents of this list, compact by default",
                example: "[1 2 3] | to nuon",
                result: Some(Value::test_string("[1, 2, 3]"))
            },
            Example {
                description: "Outputs a NUON array of ints, with pretty indentation",
                example: "[1 2 3] | to nuon --indent 2",
                result: Some(Value::test_string("[\n  1,\n  2,\n  3\n]")),
            },
            Example {
                description: "Overwrite any set option with --raw",
                example: "[1 2 3] | to nuon --indent 2 --raw",
                result: Some(Value::test_string("[1,2,3]"))
            },
            Example {
                description: "A more complex record with multiple data types",
                example: "{date: 2000-01-01, data: [1 [2 3] 4.56]} | to nuon --indent 2",
                result: Some(Value::test_string("{\n  date: 2000-01-01T00:00:00+00:00,\n  data: [\n    1,\n    [\n      2,\n      3\n    ],\n    4.56\n  ]\n}"))
            },
            Example {
                description: "A more complex record with --raw",
                example: "{date: 2000-01-01, data: [1 [2 3] 4.56]} | to nuon --raw",
                result: Some(Value::test_string("{date:2000-01-01T00:00:00+00:00,data:[1,[2,3],4.56]}"))
            }
        ]
    }
}