diff --git a/.gitignore b/.gitignore index 9952d38d3..1e55ec70f 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,7 @@ debian/nu/ # Helix configuration folder .helix/* .helix + +# Coverage tools +lcov.info +tarpaulin-report.html diff --git a/crates/nu-command/src/filters/columns.rs b/crates/nu-command/src/filters/columns.rs index 2ad1b58cd..840b1e055 100644 --- a/crates/nu-command/src/filters/columns.rs +++ b/crates/nu-command/src/filters/columns.rs @@ -27,7 +27,14 @@ impl Command for Columns { Example { example: "[[name,age,grade]; [bill,20,a]] | columns", description: "Get the columns from the table", - result: None, + result: Some(Value::List { + vals: vec![ + Value::test_string("name"), + Value::test_string("age"), + Value::test_string("grade"), + ], + span: Span::test_data(), + }), }, Example { example: "[[name,age,grade]; [bill,20,a]] | columns | first", diff --git a/crates/nu-command/src/filters/drop/column.rs b/crates/nu-command/src/filters/drop/column.rs index 9f441c97c..2437ac175 100644 --- a/crates/nu-command/src/filters/drop/column.rs +++ b/crates/nu-command/src/filters/drop/column.rs @@ -57,11 +57,18 @@ impl Command for DropColumn { description: "Remove the last column of a table", example: "echo [[lib, extension]; [nu-lib, rs] [nu-core, rb]] | drop column", result: Some(Value::List { - vals: vec![Value::Record { - cols: vec!["lib".into()], - vals: vec![Value::test_string("nu-lib"), Value::test_string("nu-core")], - span: Span::test_data(), - }], + vals: vec![ + Value::Record { + cols: vec!["lib".into()], + vals: vec![Value::test_string("nu-lib")], + span: Span::test_data(), + }, + Value::Record { + cols: vec!["lib".into()], + vals: vec![Value::test_string("nu-core")], + span: Span::test_data(), + }, + ], span: Span::test_data(), }), }] @@ -180,3 +187,13 @@ fn get_keep_columns(input: Vec, mut num_of_columns_to_drop: i64) -> Vec< let num_of_columns_to_keep = (vlen - num_of_columns_to_drop) as usize; input[0..num_of_columns_to_keep].to_vec() } + +#[cfg(test)] +mod test { + #[test] + fn test_examples() { + use super::DropColumn; + use crate::test_examples; + test_examples(DropColumn {}) + } +} diff --git a/crates/nu-command/src/filters/reject.rs b/crates/nu-command/src/filters/reject.rs index d12150c68..f36a19312 100644 --- a/crates/nu-command/src/filters/reject.rs +++ b/crates/nu-command/src/filters/reject.rs @@ -205,3 +205,13 @@ fn reject_record_columns(cols: &mut Vec, vals: &mut Vec, rejects: } } } + +#[cfg(test)] +mod test { + #[test] + fn test_examples() { + use super::Reject; + use crate::test_examples; + test_examples(Reject {}) + } +} diff --git a/crates/nu-command/src/filters/wrap.rs b/crates/nu-command/src/filters/wrap.rs index 947a09077..2116dac56 100644 --- a/crates/nu-command/src/filters/wrap.rs +++ b/crates/nu-command/src/filters/wrap.rs @@ -70,13 +70,35 @@ impl Command for Wrap { description: "Wrap a list into a table with a given column name", example: "echo [1 2 3] | wrap num", result: Some(Value::List { - vals: vec![Value::Record { - cols: vec!["num".into()], - vals: vec![Value::test_int(1), Value::test_int(2), Value::test_int(3)], - span: Span::test_data(), - }], + vals: vec![ + Value::Record { + cols: vec!["num".into()], + vals: vec![Value::test_int(1)], + span: Span::test_data(), + }, + Value::Record { + cols: vec!["num".into()], + vals: vec![Value::test_int(2)], + span: Span::test_data(), + }, + Value::Record { + cols: vec!["num".into()], + vals: vec![Value::test_int(3)], + span: Span::test_data(), + }, + ], span: Span::test_data(), }), }] } } + +#[cfg(test)] +mod test { + #[test] + fn test_examples() { + use super::Wrap; + use crate::test_examples; + test_examples(Wrap {}) + } +} diff --git a/crates/nu-command/src/formats/from/ods.rs b/crates/nu-command/src/formats/from/ods.rs index 11a1caf70..d309158e8 100644 --- a/crates/nu-command/src/formats/from/ods.rs +++ b/crates/nu-command/src/formats/from/ods.rs @@ -55,12 +55,12 @@ impl Command for FromOds { vec![ Example { description: "Convert binary .ods data to a table", - example: "open test.txt | from ods", + example: "open --raw test.ods | from ods", result: None, }, Example { description: "Convert binary .ods data to a table, specifying the tables", - example: "open test.txt | from ods -s [Spreadsheet1]", + example: "open --raw test.ods | from ods -s [Spreadsheet1]", result: None, }, ] diff --git a/crates/nu-command/src/formats/from/xlsx.rs b/crates/nu-command/src/formats/from/xlsx.rs index 5dfce163c..c2594f84c 100644 --- a/crates/nu-command/src/formats/from/xlsx.rs +++ b/crates/nu-command/src/formats/from/xlsx.rs @@ -55,12 +55,12 @@ impl Command for FromXlsx { vec![ Example { description: "Convert binary .xlsx data to a table", - example: "open test.txt | from xlsx", + example: "open --raw test.xlsx | from xlsx", result: None, }, Example { description: "Convert binary .xlsx data to a table, specifying the tables", - example: "open test.txt | from xlsx -s [Spreadsheet1]", + example: "open --raw test.xlsx | from xlsx -s [Spreadsheet1]", result: None, }, ] diff --git a/crates/nu-command/src/formats/to/nuon.rs b/crates/nu-command/src/formats/to/nuon.rs index 49e29bbe8..750d506cb 100644 --- a/crates/nu-command/src/formats/to/nuon.rs +++ b/crates/nu-command/src/formats/to/nuon.rs @@ -39,7 +39,7 @@ impl Command for ToNuon { fn examples(&self) -> Vec { vec![Example { - description: "Outputs a nuon string representing the contents of this table", + description: "Outputs a nuon string representing the contents of this list", example: "[1 2 3] | to nuon", result: Some(Value::test_string("[1, 2, 3]")), }] @@ -147,3 +147,13 @@ fn to_nuon(call: &Call, input: PipelineData) -> Result { value_to_string(&v, call.head) } + +#[cfg(test)] +mod test { + #[test] + fn test_examples() { + use super::ToNuon; + use crate::test_examples; + test_examples(ToNuon {}) + } +} diff --git a/crates/nu-command/src/hash/base64.rs b/crates/nu-command/src/hash/base64.rs index 924e2f387..066ad1d93 100644 --- a/crates/nu-command/src/hash/base64.rs +++ b/crates/nu-command/src/hash/base64.rs @@ -232,9 +232,15 @@ fn action( #[cfg(test)] mod tests { - use super::{action, ActionType, Base64Config}; + use super::{action, ActionType, Base64, Base64Config}; use nu_protocol::{Span, Value}; + #[test] + fn test_examples() { + use crate::test_examples; + test_examples(Base64 {}) + } + #[test] fn base64_encode_standard() { let word = Value::string("username:password", Span::test_data()); diff --git a/crates/nu-command/src/path/parse.rs b/crates/nu-command/src/path/parse.rs index 00ad7ecbe..14b9b64db 100644 --- a/crates/nu-command/src/path/parse.rs +++ b/crates/nu-command/src/path/parse.rs @@ -77,7 +77,21 @@ On Windows, an extra 'prefix' column is added."# Example { description: "Parse a single path", example: r"'C:\Users\viking\spam.txt' | path parse", - result: None, + result: Some(Value::Record { + cols: vec![ + "prefix".into(), + "parent".into(), + "stem".into(), + "extension".into(), + ], + vals: vec![ + Value::test_string("C:"), + Value::test_string(r"C:\Users\viking"), + Value::test_string("spam"), + Value::test_string("txt"), + ], + span: Span::test_data(), + }), }, Example { description: "Replace a complex extension", @@ -87,7 +101,21 @@ On Windows, an extra 'prefix' column is added."# Example { description: "Ignore the extension", example: r"'C:\Users\viking.d' | path parse -e ''", - result: None, + result: Some(Value::Record { + cols: vec![ + "prefix".into(), + "parent".into(), + "stem".into(), + "extension".into(), + ], + vals: vec![ + Value::test_string("C:"), + Value::test_string(r"C:\Users"), + Value::test_string("viking.d"), + Value::test_string(""), + ], + span: Span::test_data(), + }), }, Example { description: "Parse all paths under the 'name' column", @@ -103,7 +131,15 @@ On Windows, an extra 'prefix' column is added."# Example { description: "Parse a path", example: r"'/home/viking/spam.txt' | path parse", - result: None, + result: Some(Value::Record { + cols: vec!["parent".into(), "stem".into(), "extension".into()], + vals: vec![ + Value::test_string("/home/viking"), + Value::test_string("spam"), + Value::test_string("txt"), + ], + span: Span::test_data(), + }), }, Example { description: "Replace a complex extension", @@ -113,7 +149,15 @@ On Windows, an extra 'prefix' column is added."# Example { description: "Ignore the extension", example: r"'/etc/conf.d' | path parse -e ''", - result: None, + result: Some(Value::Record { + cols: vec!["parent".into(), "stem".into(), "extension".into()], + vals: vec![ + Value::test_string("/etc"), + Value::test_string("conf.d"), + Value::test_string(""), + ], + span: Span::test_data(), + }), }, Example { description: "Parse all paths under the 'name' column", diff --git a/crates/nu-command/src/viewers/griddle.rs b/crates/nu-command/src/viewers/griddle.rs index 18d6755ea..bc7f3be6c 100644 --- a/crates/nu-command/src/viewers/griddle.rs +++ b/crates/nu-command/src/viewers/griddle.rs @@ -139,7 +139,7 @@ prints out the list properly."# description: "Render a simple list to a grid", example: "[1 2 3 a b c] | grid", result: Some(Value::String { - val: "1 │ 2 │ 3 │ a │ b │ c".to_string(), + val: "1 │ 2 │ 3 │ a │ b │ c\n".to_string(), span: Span::test_data(), }), }, @@ -147,7 +147,7 @@ prints out the list properly."# description: "The above example is the same as:", example: "[1 2 3 a b c] | wrap name | grid", result: Some(Value::String { - val: "1 │ 2 │ 3 │ a │ b │ c".to_string(), + val: "1 │ 2 │ 3 │ a │ b │ c\n".to_string(), span: Span::test_data(), }), }, @@ -155,7 +155,7 @@ prints out the list properly."# description: "Render a record to a grid", example: "{name: 'foo', b: 1, c: 2} | grid", result: Some(Value::String { - val: "foo".to_string(), + val: "foo\n".to_string(), span: Span::test_data(), }), }, @@ -163,7 +163,7 @@ prints out the list properly."# description: "Render a list of records to a grid", example: "[{name: 'A', v: 1} {name: 'B', v: 2} {name: 'C', v: 3}] | grid", result: Some(Value::String { - val: "A │ B │ C".to_string(), + val: "A │ B │ C\n".to_string(), span: Span::test_data(), }), }, @@ -171,7 +171,7 @@ prints out the list properly."# description: "Render a table with 'name' column in it to a grid", example: "[[name patch]; [0.1.0 false] [0.1.1 true] [0.2.0 false]] | grid", result: Some(Value::String { - val: "0.1.0 │ 0.1.1 │ 0.2.0".to_string(), + val: "0.1.0 │ 0.1.1 │ 0.2.0\n".to_string(), span: Span::test_data(), }), }, @@ -358,3 +358,13 @@ fn convert_to_list( None } } + +#[cfg(test)] +mod test { + #[test] + fn test_examples() { + use super::Griddle; + use crate::test_examples; + test_examples(Griddle {}) + } +}