Commit af6821b0 authored by Alf Kristian Støyle's avatar Alf Kristian Støyle

More tests, going to make cat-files an exercise as well.

parent 529b70b9
...@@ -11,4 +11,5 @@ ...@@ -11,4 +11,5 @@
:aot :all :aot :all
:uberjar-name "cat.jar" :uberjar-name "cat.jar"
:profiles {:dev {:dependencies [[midje "1.6.3"]] :profiles {:dev {:dependencies [[midje "1.6.3"]]
:plugins [[lein-midje "3.1.1"]]}}) :plugins [[lein-midje "3.1.1"]]
:resource-paths ["test-resources"]}})
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
;; You should implement the functions starting with (in increasing difficulty) ;; You should implement the functions starting with (in increasing difficulty)
;; * read-file ;; * read-file
;; * cat ;; * cat
;; * cat-files (after this you have the simplest version of cat!. try 'lein uberjar', and you can run 'java -jar target/cat.jar -h'
;; * number-lines ;; * number-lines
;; * number-non-blank-lines ;; * number-non-blank-lines
...@@ -80,9 +81,9 @@ ...@@ -80,9 +81,9 @@
(str/join \newline formatted-lines)])) (str/join \newline formatted-lines)]))
(defn cat-files (defn cat-files
"Takes options and a set of filenames to handle. First reads each file to text, then converts text "Takes options and a set of filenames to handle. First reads/conerts each file to text, then converts text
for each file over cat. Then converts each result vector to only the text (the second part of cat for each file over cat. Then converts each result vector to only the text (the second part of cat
result. Finally joins these with a \newline." result). Finally joins these with a \newline (check out clojure.string functions)."
[opts files] [opts files]
(str/join \newline (str/join \newline
(map second (map second
......
...@@ -5,13 +5,17 @@ ...@@ -5,13 +5,17 @@
(fact "read-file should actually read file contets" (fact "read-file should actually read file contets"
(read-file "project.clj") => not-empty) (read-file "test-resources/file1.txt") => "en\nto\ntre\n")
(fact "cat should return its input and state in a vector" (fact "cat should return its input and state in a vector"
(cat {} "1\n2") => [{} "1\n2"] (cat {} "1\n2") => [{} "1\n2"]
(cat {:state 1} "1\n2") => [{:state 1} "1\n2"]) (cat {:state 1} "1\n2") => [{:state 1} "1\n2"])
(fact "cat-files should be able to handle many files"
(cat-files {} ["test-resources/file1.txt" "test-resources/file2.txt"])
=> "en\nto\ntre\n\nfire\nfem\nseks\n")
(fact "Should number all lines" (fact "Should number all lines"
(number-lines {} "text") => (contains " 1 text") (number-lines {} "text") => (contains " 1 text")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment