[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
- [nongnu] elpa/inf-clojure 917ee77 268/313: Improve the README a bit, (continued)
- [nongnu] elpa/inf-clojure 917ee77 268/313: Improve the README a bit, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 91f4121 280/313: Bump the copyright years, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 8eaf885 275/313: [Fix #152] Sanitize should only remove whitespace at the end of a command, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure ec4a85e 285/313: Bump copyright years, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 2046b12 298/313: Make inf-clojure-repl-p a bit more flexible, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure e1d7007 297/313: Touch up the previous commit, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 9841b38 303/313: Remove some redundant code, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 3d31bee 313/313: Update my email, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 26a2076 305/313: Replace if + not with unless, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure be3e2e7 195/313: Introduce inf-clojure-reload, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 953feb0 198/313: Improve command sanitation code,
ELPA Syncer <=
- [nongnu] elpa/inf-clojure 7ed4f44 203/313: Remove emacs 24.3 and add 26 to Travis tests, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 010d859 219/313: Fix spelling issues (#156), ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 7bf6f3d 209/313: README: Improve formatting., ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 575538e 230/313: Create FUNDING.yml, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure bd06d4f 229/313: A few updates to links and formatting in README, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 49390d9 231/313: Bump the copyright years, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 799d937 250/313: Improve the README a bit, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure c30f90e 265/313: Ensure comint-truncate-buffer call is from the repl buffer, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 784eb40 279/313: Remove unused require, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 56810a7 284/313: Add a note about the required Emacs version, ELPA Syncer, 2021/08/11