Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move to speclj for testing

Mostly since that's what I use at work, so I know it better.
  • Loading branch information...
commit b592be1374b0b8c9c7e9b5093751b7ec98aa86b8 1 parent 22137dd
@trptcolin authored
View
2  .travis.yml
@@ -1,6 +1,6 @@
language: clojure
before_script: "lein compile"
-script: "lein test"
+script: "lein spec"
jdk:
- openjdk6
- openjdk7
View
8 project.clj
@@ -1,4 +1,4 @@
-(let [dev-deps '[[midje "1.4.0" :exclusions [org.clojure/clojure]]]]
+(let [dev-deps '[[speclj "2.3.0"]]]
(defproject reply "0.1.0-SNAPSHOT"
:description "REPL-y: A fitter, happier, more productive REPL for Clojure."
@@ -11,12 +11,16 @@
[com.cemerick/drawbridge "0.0.6"]
[trptcolin/versioneer "0.1.0"]
[clojure-complete "0.2.2"]
- [org.clojars.trptcolin/sjacket "0.1.1" :exclusions [org.cojure/clojure]]]
+ [org.clojars.trptcolin/sjacket "0.1.1"
+ :exclusions [org.cojure/clojure]]]
:profiles {:dev {:dependencies ~dev-deps}}
:dev-dependencies ~dev-deps
+ :plugins ~dev-deps
:aot [reply.reader.jline.JlineInputReader]
:source-path "src/clj"
:java-source-path "src/java"
+ :test-path "spec"
:source-paths ["src/clj"]
:java-source-paths ["src/java"]
+ :test-paths ["spec"]
:main ^{:skip-aot true} reply.main))
View
27 spec/reply/completion_spec.clj
@@ -0,0 +1,27 @@
+(ns reply.completion-spec
+ (:use [reply.completion]
+ [speclj.core]))
+
+(describe "get-word-ending-at"
+ (it "finds no words when there's nothing there"
+ (should= "" (get-word-ending-at "" 0))
+ (should= "" (get-word-ending-at " " 0))
+ (should= "" (get-word-ending-at "map" 0)))
+
+ (it "finds a plain symbol"
+ (should= "ma" (get-word-ending-at "map" 2))
+ (should= "map" (get-word-ending-at "map" 3))
+ (should= "map" (get-word-ending-at "(map first [0 1 2])" 4)))
+
+ (it "finds a namespace"
+ (should= "clojure.c" (get-word-ending-at "clojure.c" 9))
+ (should= "clojure.c" (get-word-ending-at "'clojure.c" 10)))
+
+ (it "omits brackets of several sorts (but takes asterisks)"
+ (should= "" (get-word-ending-at "(map " 5))
+ (should= "*foo" (get-word-ending-at "[*foo" 5))
+ (should= "*foo" (get-word-ending-at "{*foo" 5)))
+
+ (it "includes slashes (for namespaces and classes)"
+ (should= "str/split" (get-word-ending-at "str/split" 9))
+ (should= "Integer/MAX_VALUE" (get-word-ending-at "Integer/MAX_VALUE" 17))))
View
9 spec/reply/reader/jline/completion_spec.clj
@@ -0,0 +1,9 @@
+(ns reply.reader.jline.completion-spec
+ (:use [reply.reader.jline.completion]
+ [speclj.core]))
+
+(describe "construct-possible-completions-form"
+ (it "does correct quoting in completions form request"
+ (should= '(complete.core/completions (str "clojure.core/map-") *ns*)
+ (construct-possible-completions-form "clojure.core/map-"))))
+
View
45 spec/reply/reader/jline/jline_input_reader_spec.clj
@@ -0,0 +1,45 @@
+(ns reply.reader.jline.jline-input-reader-spec
+ (:use [speclj.core])
+ (:import [reply.reader.jline JlineInputReader]))
+
+(defprotocol LineReader
+ (readLine [_]))
+
+(defrecord FakeJlineReader [f]
+ LineReader
+ (readLine [this] (f)))
+
+(defn fake-reader
+ ([input-fn] (fake-reader input-fn #()))
+ ([input-fn set-empty-prompt]
+ (let [jline-reader (FakeJlineReader. input-fn)]
+ (JlineInputReader. {:jline-reader jline-reader
+ :set-empty-prompt set-empty-prompt}))))
+
+(describe "JLineInputReader"
+ (it "reads a -1 when nothing is available"
+ (should= -1 (.read (fake-reader (constantly nil)))))
+
+ (it "reads a newline"
+ (should= 10 (.read (fake-reader (constantly "")))))
+
+ (it "reads a few characters"
+ (let [reader (fake-reader (constantly "abcd"))]
+ (should= [97 98 99 100 10]
+ (for [i (range 5)] (.read reader)))))
+
+ (it "calls for more input on a newline"
+ (let [times-readLine-called (atom 0)
+ reader (fake-reader (constantly "")
+ #(swap! times-readLine-called inc))]
+ (should= [10 10 10]
+ (for [i (range 3)] (.read reader)))
+ (should= 3 @times-readLine-called)))
+
+ (it "makes no more calls to readLine than are necessary"
+ (let [times-readLine-called (atom 0)
+ reader (fake-reader (constantly "ab")
+ #(swap! times-readLine-called inc))]
+ (should= [97 98 10 97 98 10 97 98 10 97]
+ (for [i (range 10)] (.read reader)))
+ (should= 4 @times-readLine-called))))
View
18 test/reply/completion_test.clj
@@ -1,18 +0,0 @@
-(ns reply.completion-test
- (:use [reply.completion]
- [midje.sweet]))
-
-(facts "get-word-ending-at"
- (get-word-ending-at "" 0) => ""
- (get-word-ending-at " " 0) => ""
- (get-word-ending-at "map" 0) => ""
- (get-word-ending-at "map" 2) => "ma"
- (get-word-ending-at "map" 3) => "map"
- (get-word-ending-at "(map first [0 1 2])" 4) => "map"
- (get-word-ending-at "clojure.c" 9) => "clojure.c"
- (get-word-ending-at "'clojure.c" 10) => "clojure.c"
- (get-word-ending-at "(map " 5) => ""
- (get-word-ending-at "[*foo" 5) => "*foo"
- (get-word-ending-at "{*foo" 5) => "*foo"
- (get-word-ending-at "str/split" 9) => "str/split")
-
View
8 test/reply/reader/jline/completion_test.clj
@@ -1,8 +0,0 @@
-(ns reply.reader.jline.completion-test
- (:use [reply.reader.jline.completion]
- [midje.sweet]))
-
-(fact "correct quoting in completions form request"
- (construct-possible-completions-form "clojure.core/map-") =>
- '(complete.core/completions (str "clojure.core/map-") *ns*))
-
View
43 test/reply/reader/jline/jline_input_reader_test.clj
@@ -1,43 +0,0 @@
-(ns reply.reader.jline.jline-input-reader-test
- (:use [midje.sweet])
- (:import [reply.reader.jline JlineInputReader]))
-
-(defprotocol LineReader
- (readLine [_]))
-
-(defrecord FakeJlineReader [f]
- LineReader
- (readLine [this] (f)))
-
-(defn fake-reader
- ([input-fn] (fake-reader input-fn #()))
- ([input-fn set-empty-prompt]
- (let [jline-reader (FakeJlineReader. input-fn)]
- (JlineInputReader. {:jline-reader jline-reader
- :set-empty-prompt set-empty-prompt}))))
-
-(fact "reading nothing gives nothing"
- (.read (fake-reader (constantly nil))) => -1)
-
-(fact "reading an empty line gives a newline"
- (.read (fake-reader (constantly ""))) => 10)
-
-(let [reader (fake-reader (constantly "abcd"))]
- (fact "reading a few characters works"
- (for [i (range 5)]
- (.read reader)) => [97 98 99 100 10]))
-
-(let [times-readLine-called (atom 0)
- reader (fake-reader (constantly "") #(swap! times-readLine-called inc))]
- (facts "it calls for more input on a newline"
- (for [i (range 3)]
- (.read reader)) => [10 10 10]
- @times-readLine-called => 3))
-
-(let [times-readLine-called (atom 0)
- reader (fake-reader (constantly "ab") #(swap! times-readLine-called inc))]
- (facts "no more calls to readLine than are necessary"
- (for [i (range 10)]
- (.read reader)) => [97 98 10 97 98 10 97 98 10 97]
- @times-readLine-called => 4))
-
Please sign in to comment.
Something went wrong with that request. Please try again.