Fixed the final missing feature: if -o or --output is specified on the

command line, it is now honoured.
This commit is contained in:
Simon Brooke 2013-11-10 21:09:52 +00:00
parent fd36f8e1ca
commit 6b124ec989
3 changed files with 20 additions and 6 deletions

View file

@ -24,14 +24,15 @@ See http://codekata.pragprog.com/2007/01/kata_fourteen_t.html"
"The length of the sequences to analyse it into (integer)"
:parse-fn #(Integer. %)
:default 2])
file (arguments :file)]
file (arguments :file)
output (arguments :output)]
(cond
(= file nil) (print banner)
(arguments :help) (print banner)
true (synthesise/write-output
(synthesise/compose-nonsense
(analyse/analyse-file file (arguments :tuple-length))
(arguments :output-length))))
(arguments :output-length)) output))
(flush)))

View file

@ -159,7 +159,14 @@
TODO: does not yet work. Should take an optional second argument,
the file to write to if any (default to standard out).
output: a sequence of tokens to write."
[output]
(dorun (map write-token (top-and-tail output)))
(print "\n\n"))
output: a sequence of tokens to write;
destination: if not null, the name of the file to which to write it."
([output destination]
(cond
destination
(let [text (with-out-str (write-output output))]
(spit destination text))
true (write-output output)))
([output]
(dorun (map write-token (top-and-tail output)))
(print "\n\n")))

View file

@ -7,3 +7,9 @@
(is (= (top-and-tail '("a" "b" "c" "?" "d" "e" "f" "." "g" "h" "i" "!")) '("d" "e" "f" "." "g" "h" "i" "!")))
(is (= (top-and-tail '("a" "b" "c" "?" "d" "e" "f" "." "g" "h" "i")) '("d" "e" "f" ".")))
))
(deftest write-output-test
(testing "Test output to file"
(is (= (do ;; (spit "test.out" "")
(write-output '("Test" "output" ".") "test.out")
(slurp "test.out"))) "Test output.")))