From 5f4abe31c34409702404d9ea7d8506d788df4556 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sun, 1 Jan 2023 15:51:32 -0500 Subject: [PATCH] unit tests --- docs/src/data/spaces.csv | 7 ++-- docs/src/reference-verbs.md | 66 +++++++++++++++++++++++++++++++++ docs/src/reference-verbs.md.in | 28 ++++++++++++++ test/cases/cli-help/0001/expout | 10 +++++ test/input/spaces.csv | 4 ++ 5 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 test/input/spaces.csv diff --git a/docs/src/data/spaces.csv b/docs/src/data/spaces.csv index b2838bcf13..5d2f5890de 100644 --- a/docs/src/data/spaces.csv +++ b/docs/src/data/spaces.csv @@ -1,4 +1,3 @@ -a b c,def,g h i -123,4567,890 -2468,1357,3579 -9987,3312,4543 +column 1, column 2, column 3 +apple,ball,cat +dale egg,fish,gale diff --git a/docs/src/reference-verbs.md b/docs/src/reference-verbs.md index 666203d8b7..1bbeb2e703 100644 --- a/docs/src/reference-verbs.md +++ b/docs/src/reference-verbs.md @@ -4078,6 +4078,72 @@ count color shape flag 2 yellow triangle 1 +## unspace + +
+mlr unspace --help
+
+
+Usage: mlr unspace [options]
+Replaces spaces in record keys and/or values with _. This is helpful for PPRINT output.
+Options:
+-f {x}    Replace spaces with specified filler character.
+-k        Unspace only keys, not keys and values.
+-v        Unspace only values, not keys and values.
+-h|--help Show this message.
+
+ +The primary use-case is for PPRINT output, which is space-delimited. For example: + +
+cat data/spaces.csv
+
+
+column 1, column 2, column 3
+apple,ball,cat
+dale egg,fish,gale
+
+ +
+mlr --icsv --opprint cat data/spaces.csv
+
+
+column 1  column 2  column 3
+apple    ball      cat
+dale egg fish      gale
+
+ +
+mlr --icsv --opprint cat data/spaces.csv
+
+
+column 1  column 2  column 3
+apple    ball      cat
+dale egg fish      gale
+
+ +
+mlr --icsv --opprint unspace data/spaces.csv
+
+
+column_1 _column_2 _column_3
+apple    ball      cat
+dale_egg fish      gale
+
+ +
+mlr --icsv --opprint unspace data/spaces.csv | mlr --ipprint --oxtab cat
+
+
+column_1  apple
+_column_2 ball
+_column_3 cat
+
+column_1  dale_egg
+_column_2 fish
+_column_3 gale
+
+ ## unsparsify
diff --git a/docs/src/reference-verbs.md.in b/docs/src/reference-verbs.md.in
index ff2776e41b..40fbbe4f1e 100644
--- a/docs/src/reference-verbs.md.in
+++ b/docs/src/reference-verbs.md.in
@@ -1229,6 +1229,34 @@ GENMD-RUN-COMMAND
 mlr --opprint uniq -a -c data/repeats.dkvp
 GENMD-EOF
 
+## unspace
+
+GENMD-RUN-COMMAND
+mlr unspace --help
+GENMD-EOF
+
+The primary use-case is for PPRINT output, which is space-delimited. For example:
+
+GENMD-RUN-COMMAND
+cat data/spaces.csv
+GENMD-EOF
+
+GENMD-RUN-COMMAND
+mlr --icsv --opprint cat data/spaces.csv
+GENMD-EOF
+
+GENMD-RUN-COMMAND
+mlr --icsv --opprint cat data/spaces.csv
+GENMD-EOF
+
+GENMD-RUN-COMMAND
+mlr --icsv --opprint unspace data/spaces.csv
+GENMD-EOF
+
+GENMD-RUN-COMMAND
+mlr --icsv --opprint unspace data/spaces.csv | mlr --ipprint --oxtab cat
+GENMD-EOF
+
 ## unsparsify
 
 GENMD-RUN-COMMAND
diff --git a/test/cases/cli-help/0001/expout b/test/cases/cli-help/0001/expout
index 45eb188237..1a276f7a47 100644
--- a/test/cases/cli-help/0001/expout
+++ b/test/cases/cli-help/0001/expout
@@ -1271,6 +1271,16 @@ Options:
               With -n, produces only one record which is the unique-record count.
               With neither -c nor -n, produces unique records.
 
+================================================================
+unspace
+Usage: mlr unspace [options]
+Replaces spaces in record keys and/or values with _. This is helpful for PPRINT output.
+Options:
+-f {x}    Replace spaces with specified filler character.
+-k        Unspace only keys, not keys and values.
+-v        Unspace only values, not keys and values.
+-h|--help Show this message.
+
 ================================================================
 unsparsify
 Usage: mlr unsparsify [options]
diff --git a/test/input/spaces.csv b/test/input/spaces.csv
new file mode 100644
index 0000000000..3e52728f33
--- /dev/null
+++ b/test/input/spaces.csv
@@ -0,0 +1,4 @@
+a b,c, d e
+1,,3
+4 5,6, 7  8
+9,10,11