forked from extern/nushell
don't use table compaction in to nuon if not a table (#4671)
* don't use table compaction in to nuon if not a table * Make a proper nuon conversion test * more nuon tests
This commit is contained in:
parent
ef70c8dbe4
commit
10364c4f22
@ -65,7 +65,7 @@ fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
|
|||||||
Value::Int { val, .. } => Ok(format!("{}", *val)),
|
Value::Int { val, .. } => Ok(format!("{}", *val)),
|
||||||
Value::List { vals, .. } => {
|
Value::List { vals, .. } => {
|
||||||
let headers = get_columns(vals);
|
let headers = get_columns(vals);
|
||||||
if vals.iter().all(|x| x.columns() == headers) {
|
if !headers.is_empty() && vals.iter().all(|x| x.columns() == headers) {
|
||||||
// Table output
|
// Table output
|
||||||
let headers_output = headers.join(", ");
|
let headers_output = headers.join(", ");
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ mod html;
|
|||||||
mod ics;
|
mod ics;
|
||||||
mod json;
|
mod json;
|
||||||
mod markdown;
|
mod markdown;
|
||||||
|
mod nuon;
|
||||||
mod ods;
|
mod ods;
|
||||||
mod sqlite;
|
mod sqlite;
|
||||||
mod ssv;
|
mod ssv;
|
||||||
|
104
crates/nu-command/tests/format_conversions/nuon.rs
Normal file
104
crates/nu-command/tests/format_conversions/nuon.rs
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
use nu_test_support::{nu, pipeline};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_nuon_correct_compaction() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
open appveyor.yml
|
||||||
|
| to nuon
|
||||||
|
| str length
|
||||||
|
| $in > 500
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_nuon_list_of_numbers() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
[1, 2, 3, 4]
|
||||||
|
| to nuon
|
||||||
|
| from nuon
|
||||||
|
| $in == [1, 2, 3, 4]
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_nuon_list_of_strings() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
[abc, xyz, def]
|
||||||
|
| to nuon
|
||||||
|
| from nuon
|
||||||
|
| $in == [abc, xyz, def]
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_nuon_table() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
[[my, columns]; [abc, xyz], [def, ijk]]
|
||||||
|
| to nuon
|
||||||
|
| from nuon
|
||||||
|
| $in == [[my, columns]; [abc, xyz], [def, ijk]]
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_nuon_bool() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
$false
|
||||||
|
| to nuon
|
||||||
|
| from nuon
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_nuon_negative_int() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
-1
|
||||||
|
| to nuon
|
||||||
|
| from nuon
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "-1");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_nuon_records() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
{name: "foo bar", age: 100, height: 10}
|
||||||
|
| to nuon
|
||||||
|
| from nuon
|
||||||
|
| $in == {name: "foo bar", age: 100, height: 10}
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "true");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user