Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions haskell-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ execusion."
(remove-hook
'post-command-hook #'haskell-utils-async-update-post-command-flag t)))

(defun haskell-utils-reduce-string (s)
"Remove newlines and extra whitespace from S.
Removes all extra whitespace at the beginning of each line leaving
only a single space. Then removes all newlines."
(let ((s_ (replace-regexp-in-string "^\s+" " " s)))
(replace-regexp-in-string "\n" "" s_)))
(defun haskell-utils-reduce-string (str)
"Remove newlines and extra whitespace from string STR.
If line starts with a sequence of whitespaces, substitutes this
sequence with a single whitespace. Removes all newline
characters."
(let ((s (replace-regexp-in-string "^\s+" " " str)))
(replace-regexp-in-string "\r?\n" "" s)))

(defun haskell-utils-repl-response-error-status (response)
"Parse response REPL's RESPONSE for errors.
Expand Down
24 changes: 24 additions & 0 deletions tests/haskell-utils-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,28 @@ strings will change in future."
(should (equal r6 'no-error))
(should (equal r7 'no-error))))

(ert-deftest reduce-strign ()
"Test `haskell-utils-reduce-strign' command.
Whitespace sequences at beginning of lines should be replaced
with single whitespace, all newline characters should be
removed."
(should (string-equal "" (haskell-utils-reduce-string "\n")))
(should (string-equal "" (haskell-utils-reduce-string "\r\n")))
(should (string-equal " " (haskell-utils-reduce-string " \n")))
(should (string-equal
"TestTest"
(haskell-utils-reduce-string "Test\nTest")))
(should (string-equal
"Test Test"
(haskell-utils-reduce-string "Test\n Test")))
(should (string-equal
" Test Test"
(haskell-utils-reduce-string " Test\r\n Test")))
(should (string-equal
" TestTest"
(haskell-utils-reduce-string " Test\r\nTest")))
(should (string-equal
" TestTest Test test"
(haskell-utils-reduce-string " Test\r\nTest\n Test test"))))

;;; haskell-utils-tests.el ends here