]> git.proxmox.com Git - proxmox.git/commitdiff
proxmox-api: fix text_wrap() - use join instead of concat (separate by newlines)
authorDietmar Maurer <dietmar@proxmox.com>
Sun, 1 Dec 2019 11:29:26 +0000 (12:29 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Sun, 1 Dec 2019 11:30:50 +0000 (12:30 +0100)
proxmox-api/src/format.rs

index 16f3c17cf5781360c492d3b0aa606eb2dae8ed51..484ad58068b68cdeb40dcaa9de5edf33863ac4a0 100644 (file)
@@ -48,15 +48,26 @@ pub fn wrap_text(
         .filter(|p| !p.is_empty())
         .fold(String::new(), |mut acc, p| {
             if acc.is_empty() {
-                acc.push_str(&wrapper1.wrap(p).concat());
+                acc.push_str(&wrapper1.wrap(p).join("\n"));
             } else {
-                acc.push_str(&wrapper2.wrap(p).concat());
+                acc.push_str(&wrapper2.wrap(p).join("\n"));
             }
             acc.push_str("\n\n");
             acc
         })
 }
 
+#[test]
+fn test_wrap_text() {
+    let text = "Command. This may be a list in order to spefify nested sub-commands.";
+    let expect = "             Command. This may be a list in order to spefify nested sub-\n             commands.\n\n";
+
+    let indent = "             ";
+    let wrapped = wrap_text(indent, indent, text, 80);
+
+    assert_eq!(wrapped, expect);
+}
+
 /// TODO: Document output format.
 pub fn get_schema_type_text(schema: &Schema, _style: ParameterDisplayStyle) -> String {
     match schema {