diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2010-04-14 21:41:08 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-04-14 21:41:08 -0400 |
commit | af2a730fde0d8df0ab4a41153580105a36a20e7f (patch) | |
tree | 8a9e95268b9a61de82aa50badfa0a695aa40f6c8 /src | |
parent | 9cd7b155149c6e20b799528c6d5bf2f0e553e9f3 (diff) |
some tests for c.c.io byte-level support
Diffstat (limited to 'src')
-rw-r--r-- | src/test/clojure/clojure/contrib/test_io.clj | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/test/clojure/clojure/contrib/test_io.clj b/src/test/clojure/clojure/contrib/test_io.clj index 30ccd4a5..32d4909a 100644 --- a/src/test/clojure/clojure/contrib/test_io.clj +++ b/src/test/clojure/clojure/contrib/test_io.clj @@ -1,6 +1,6 @@ (ns clojure.contrib.test-io (:use clojure.test clojure.contrib.io) - (:import (java.io File) + (:import (java.io File FileInputStream BufferedInputStream) (java.net URL URI))) (deftest file-str-backslash @@ -41,3 +41,24 @@ (is (= "bar" (relative-path-string (File. "bar"))))) (testing "absolute File paths are forbidden" (is (thrown? IllegalArgumentException (relative-path-string (File. (str File/separator "quux"))))))) + +(defn stream-should-have [stream expected-bytes msg] + (let [actual-bytes (byte-array (alength expected-bytes))] + (.read stream actual-bytes) + (is (= -1 (.read stream)) (str msg " : should be end of stream")) + (is (= (seq expected-bytes) (seq actual-bytes)) (str msg " : byte arrays should match")))) + +(deftest test-input-stream + (let [file (File/createTempFile "test-input-stream" "txt") + bytes (.getBytes "foobar")] + (spit file "foobar") + (doseq [[expr msg] + [[file File] + [(FileInputStream. file) FileInputStream] + [(BufferedInputStream. (FileInputStream. file)) BufferedInputStream] + [(.. file toURI) URI] + [(.. file toURI toURL) URL] + [(.. file toURI toURL toString) "URL as String"] + [(.. file toString) "File as String"]]] + (with-open [s (input-stream expr)] + (stream-should-have s bytes msg))))) |