File tree Expand file tree Collapse file tree 2 files changed +31
-6
lines changed Expand file tree Collapse file tree 2 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -100,12 +100,13 @@ execusion."
100100 (remove-hook
101101 'post-command-hook #'haskell-utils-async-update-post-command-flag t )))
102102
103- (defun haskell-utils-reduce-string (s )
104- " Remove newlines and extra whitespace from S.
105- Removes all extra whitespace at the beginning of each line leaving
106- only a single space. Then removes all newlines."
107- (let ((s_ (replace-regexp-in-string " ^\s +" " " s)))
108- (replace-regexp-in-string " \n " " " s_)))
103+ (defun haskell-utils-reduce-string (str )
104+ " Remove newlines and extra whitespace from string STR.
105+ If line starts with a sequence of whitespaces, substitutes this
106+ sequence with a single whitespace. Removes all newline
107+ characters."
108+ (let ((s (replace-regexp-in-string " ^\s +" " " str)))
109+ (replace-regexp-in-string " \r ?\n " " " s)))
109110
110111(defun haskell-utils-repl-response-error-status (response )
111112 " Parse response REPL's RESPONSE for errors.
Original file line number Diff line number Diff line change @@ -201,4 +201,28 @@ strings will change in future."
201201 (should (equal r6 'no-error ))
202202 (should (equal r7 'no-error ))))
203203
204+ (ert-deftest reduce-strign ()
205+ " Test `haskell-utils-reduce-strign' command.
206+ Whitespace sequences at beginning of lines should be replaced
207+ with single whitespace, all newline characters should be
208+ removed."
209+ (should (string-equal " " (haskell-utils-reduce-string " \n " )))
210+ (should (string-equal " " (haskell-utils-reduce-string " \r\n " )))
211+ (should (string-equal " " (haskell-utils-reduce-string " \n " )))
212+ (should (string-equal
213+ " TestTest"
214+ (haskell-utils-reduce-string " Test\n Test" )))
215+ (should (string-equal
216+ " Test Test"
217+ (haskell-utils-reduce-string " Test\n Test" )))
218+ (should (string-equal
219+ " Test Test"
220+ (haskell-utils-reduce-string " Test\r\n Test" )))
221+ (should (string-equal
222+ " TestTest"
223+ (haskell-utils-reduce-string " Test\r\n Test" )))
224+ (should (string-equal
225+ " TestTest Test test"
226+ (haskell-utils-reduce-string " Test\r\n Test\n Test test" ))))
227+
204228; ;; haskell-utils-tests.el ends here
You can’t perform that action at this time.
0 commit comments