Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f21b29b

Browse filesBrowse files
committed
Improve command sanitation code
This patch improves the parsing and sanitation of command and make sure, with tests, that we do things correctly.
1 parent be3e2e7 commit f21b29b
Copy full SHA for f21b29b

File tree

2 files changed

+24
-4
lines changed
Filter options

2 files changed

+24
-4
lines changed

‎inf-clojure.el

Copy file name to clipboardExpand all lines: inf-clojure.el
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ It requires a REPL PROC for inspecting the correct type."
303303

304304
(defun inf-clojure--single-linify (string)
305305
"Convert a multi-line STRING in a single-line STRING.
306-
It also reduces/adds redundant whitespace for readability. Note
307-
that this function will transform the empty string in \" \" (it
308-
adds an empty space)."
309-
(replace-regexp-in-string "[ \\|\n]+" " " string))
306+
It also reduces redundant whitespace for readability."
307+
(thread-last string
308+
(replace-regexp-in-string "[ \\|\n]+" " ")
309+
(replace-regexp-in-string " $" "")))
310310

311311
(defun inf-clojure--trim-newline-right (string)
312312
"Trim newlines (only) in STRING."

‎test/inf-clojure-tests.el

Copy file name to clipboardExpand all lines: test/inf-clojure-tests.el
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,24 @@
111111
(expect (ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point))
112112
:to-equal "deref")))))
113113

114+
(describe "inf-clojure--single-linify"
115+
(it "replaces newlines with whitespace"
116+
(expect (inf-clojure--single-linify "(do\n(println \"hello world\")\n)") :to-equal "(do (println \"hello world\") )"))
117+
118+
(it "does not leave whitespace at the end"
119+
(expect (inf-clojure--single-linify "(do\n(println \"hello world\")\n)\n\n") :to-equal "(do (println \"hello world\") )"))
120+
121+
(it "returns empty string in case of only newline"
122+
(expect (inf-clojure--single-linify "\n\n\n\n") :to-equal "")))
123+
124+
(describe "inf-clojure--sanitize-command"
125+
(it "sanitizes the command correctly"
126+
(expect (inf-clojure--sanitize-command "(doc println)") :to-equal "(doc println)\n"))
127+
128+
(it "trims newline at the right of a command"
129+
(expect (inf-clojure--sanitize-command "(doc println)\n\n\n\n") :to-equal "(doc println)\n"))
130+
131+
(it "returns empty string when the command is empty"
132+
(expect (inf-clojure--sanitize-command " ") :to-equal "")))
133+
114134
;;; inf-clojure-tests.el ends here

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.