emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/inf-clojure 953feb0 198/313: Improve command sanitation co


From: ELPA Syncer
Subject: [nongnu] elpa/inf-clojure 953feb0 198/313: Improve command sanitation code
Date: Wed, 11 Aug 2021 10:00:16 -0400 (EDT)

branch: elpa/inf-clojure
commit 953feb0041b631b49395c73a7f0a446a2faed698
Author: Andrea Richiardi <a.richiardi.work@gmail.com>
Commit: Bozhidar Batsov <bozhidar.batsov@gmail.com>

    Improve command sanitation code
    
    This patch improves the parsing and sanitation of command and make sure, 
with
    tests, that we do things correctly.
---
 CHANGELOG.md              |  2 ++
 inf-clojure.el            |  8 ++++----
 test/inf-clojure-tests.el | 20 ++++++++++++++++++++
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 31e1fa2..6701933 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
 
 ## master (unreleased)
 
+* [#135](https://github.com/clojure-emacs/inf-clojure/pull/135): Improve 
command sanitation code.
+
 ## 2.1.0 (2018-01-02)
 
 ### New Features
diff --git a/inf-clojure.el b/inf-clojure.el
index 817147d..61f7d73 100644
--- a/inf-clojure.el
+++ b/inf-clojure.el
@@ -307,10 +307,10 @@ It requires a REPL PROC for inspecting the correct type."
 
 (defun inf-clojure--single-linify (string)
   "Convert a multi-line STRING in a single-line STRING.
-It also reduces/adds redundant whitespace for readability.  Note
-that this function will transform the empty string in \" \" (it
-adds an empty space)."
-  (replace-regexp-in-string "[ \\|\n]+" " " string))
+It also reduces redundant whitespace for readability."
+  (thread-last string
+    (replace-regexp-in-string "[ \\|\n]+" " ")
+    (replace-regexp-in-string " $" "")))
 
 (defun inf-clojure--trim-newline-right (string)
   "Trim newlines (only) in STRING."
diff --git a/test/inf-clojure-tests.el b/test/inf-clojure-tests.el
index 994801c..6147dd3 100644
--- a/test/inf-clojure-tests.el
+++ b/test/inf-clojure-tests.el
@@ -111,4 +111,24 @@
          (expect (ict-bounds-string 
(inf-clojure-completion-bounds-of-expr-at-point))
                  :to-equal "deref")))))
 
+(describe "inf-clojure--single-linify"
+  (it "replaces newlines with whitespace"
+      (expect (inf-clojure--single-linify "(do\n(println \"hello world\")\n)") 
:to-equal "(do (println \"hello world\") )"))
+
+  (it "does not leave whitespace at the end"
+      (expect (inf-clojure--single-linify "(do\n(println \"hello 
world\")\n)\n\n") :to-equal "(do (println \"hello world\") )"))
+
+  (it "returns empty string in case of only newline"
+      (expect (inf-clojure--single-linify "\n\n\n\n") :to-equal "")))
+
+(describe "inf-clojure--sanitize-command"
+  (it "sanitizes the command correctly"
+     (expect (inf-clojure--sanitize-command "(doc println)") :to-equal "(doc 
println)\n"))
+
+  (it "trims newline at the right of a command"
+     (expect (inf-clojure--sanitize-command "(doc println)\n\n\n\n") :to-equal 
"(doc println)\n"))
+
+  (it "returns empty string when the command is empty"
+     (expect (inf-clojure--sanitize-command "   ") :to-equal "")))
+
 ;;; inf-clojure-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]