Skip to content
Merged
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
32 changes: 32 additions & 0 deletions test/clojure/string_test/split_lines.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(ns clojure.string-test.split-lines
(:require [clojure.string :as str]
[clojure.test :as t :refer [deftest testing is]]
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists] :as p]))

(when-var-exists str/split-lines
(deftest test-split-lines
(testing "Normal use"
#?(:cljr (is (= [] (str/split-lines "")))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmiller Is this an intended deviation?

:default (is (= [""] (str/split-lines ""))))
(is (= [] (str/split-lines "\n")))
(is (= [] (str/split-lines "\n\n")))
(is (= [] (str/split-lines "\r\n")))
Comment thread
djblue marked this conversation as resolved.
(is (= ["" "bar"] (str/split-lines "\nbar")))
(is (= ["foo"] (str/split-lines "foo\n")))
(is (= ["foo" "bar"] (str/split-lines "foo\nbar")))
(is (= ["foo" "" "bar"] (str/split-lines "foo\n\nbar")))
(is (= ["foo " " bar"] (str/split-lines "foo \n bar")))
(is (= ["foo"] (str/split-lines "foo\n\n")))
(is (= ["foo" "bar" "spam"] (str/split-lines "foo\nbar\r\nspam")))
(is (= ["🫸" "🫷"] (str/split-lines "🫸\n🫷"))))

#?(:cljs nil ;; CLJS will coerce the argument to a string so it will not throw
:default
(testing "Exceptions"
(is (p/thrown? (str/split-lines nil)))
(is (p/thrown? (str/split-lines \A)))
(is (p/thrown? (str/split-lines 0)))
(is (p/thrown? (str/split-lines 0.0)))
(is (p/thrown? (str/split-lines :foo)))
(is (p/thrown? (str/split-lines 'foo)))
(is (p/thrown? (str/split-lines [])))))))
Loading