diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn new file mode 100644 index 00000000..0d10824a --- /dev/null +++ b/.clj-kondo/config.edn @@ -0,0 +1,4 @@ +{:lint-as {seesaw.test.examples.example/defexample clojure.core/defn} + :linters {:clojure-lsp/unused-public-var {:level :off} + :refer-all {:level :off} + :unused-binding {:level :off}}} diff --git a/.clj-kondo/imports/io.github.noahtheduke/lazytest/config.edn b/.clj-kondo/imports/io.github.noahtheduke/lazytest/config.edn new file mode 100644 index 00000000..8fc19407 --- /dev/null +++ b/.clj-kondo/imports/io.github.noahtheduke/lazytest/config.edn @@ -0,0 +1,13 @@ +{:lint-as {lazytest.core/defdescribe clojure.core/def + lazytest.core/defcontext clojure.core/def + lazytest.core/defsuite clojure.core/def + lazytest.core/given clojure.core/let + lazytest.core/around clojure.core/fn + ;; clojure.test interface + lazytest.experimental.interfaces.clojure-test/deftest clojure.test/deftest + lazytest.experimental.interfaces.clojure-test/testing clojure.test/testing + lazytest.experimental.interfaces.clojure-test/is clojure.test/is + lazytest.experimental.interfaces.clojure-test/are clojure.test/are + ;; xunit interface + lazytest.experimental.interfaces.xunit/defsuite clojure.core/def + }} diff --git a/.clj-kondo/imports/metosin/malli/config.edn b/.clj-kondo/imports/metosin/malli/config.edn new file mode 100644 index 00000000..0f8b25cc --- /dev/null +++ b/.clj-kondo/imports/metosin/malli/config.edn @@ -0,0 +1,2 @@ +{:lint-as {malli.experimental/defn schema.core/defn} + :linters {:unresolved-symbol {:exclude [(malli.core/=>)]}}} diff --git a/.clj-kondo/imports/nubank/matcher-combinators/config.edn b/.clj-kondo/imports/nubank/matcher-combinators/config.edn new file mode 100644 index 00000000..ea4ded72 --- /dev/null +++ b/.clj-kondo/imports/nubank/matcher-combinators/config.edn @@ -0,0 +1,4 @@ +{:linters + {:unresolved-symbol + {:exclude [(cljs.test/is [match? thrown-match?]) + (clojure.test/is [match? thrown-match?])]}}} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..889f54f0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +name: Clojure CI + +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] + +jobs: + clojure: + strategy: + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Prepare java + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '11' + + - name: Install clojure tools + uses: DeLaGuardo/setup-clojure@12.5 + with: + cli: 1.12.0.1479 + lein: 2.11.2 + + - name: Cache clojure dependencies + uses: actions/cache@v4 + with: + path: | + ~/.m2/repository + ~/.gitlibs + key: cljdeps-${{ hashFiles('project.clj') }} + restore-keys: cljdeps- + + - name: run tests + run: lein test diff --git a/.gitignore b/.gitignore index 4bc6ea46..9b20e3bd 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ autodoc/** .clj-kondo/.cache .lsp/.cache .portal/vs-code.edn +.nrepl-port diff --git a/project.clj b/project.clj index b25f2b1f..5f0d232f 100644 --- a/project.clj +++ b/project.clj @@ -12,21 +12,20 @@ :distribution :repo :comments "same as Clojure"} - :warn-on-reflection true - ; To run the examples: ; ; $ lein examples ; - :aliases { "examples" ["run" "-m" "seesaw.test.examples.launcher"] } + :aliases {"test" ["run" "-m" "lazytest.main"] + "examples" ["run" "-m" "seesaw.test.examples.launcher"]} - :dependencies [[org.clojure/clojure "1.4.0"] + :dependencies [[org.clojure/clojure "1.11.1"] [com.miglayout/miglayout "3.7.4"] [com.jgoodies/forms "1.2.1"] [org.swinglabs.swingx/swingx-core "1.6.3"] [j18n "1.0.2"] [com.fifesoft/rsyntaxtextarea "2.5.6"]] - :profiles { :dev {:dependencies [[com.stuartsierra/lazytest "1.1.2"] + :profiles {:dev {:dependencies [[io.github.noahtheduke/lazytest "1.2.0"] [lein-autodoc "0.9.0"]]}} :repositories [["stuartsierra-releases" "https://stuartsierra.com/maven2"]] :autodoc { diff --git a/src/seesaw/action.clj b/src/seesaw/action.clj index 310175d1..911110f1 100644 --- a/src/seesaw/action.clj +++ b/src/seesaw/action.clj @@ -84,7 +84,7 @@ See: http://download.oracle.com/javase/6/docs/api/javax/swing/Action.html " - [& opts] + ^Action [& opts] (let [a (proxy [AbstractAction] [] (actionPerformed [e] (if-let [f (get-meta this action-handler-property)] (f e))))] diff --git a/src/seesaw/core.clj b/src/seesaw/core.clj index 9a240f70..e73993f3 100644 --- a/src/seesaw/core.clj +++ b/src/seesaw/core.clj @@ -1178,7 +1178,7 @@ See: http://download.oracle.com/javase/6/docs/api/javax/swing/JLabel.html " - [& args] + ^JLabel [& args] (case (count args) 0 (label :text "") 1 (label :text (first args)) @@ -1532,8 +1532,7 @@ (seesaw.core/style-text!) http://download.oracle.com/javase/6/docs/api/javax/swing/JTextPane.html " - { :arglists '([& args]) } - [& {:as opts}] + ^JTextPane [& {:as opts}] (let [pane (proxy [JTextPane] [] (getScrollableTracksViewportWidth [] (boolean (get-meta this :wrap-lines?))))] @@ -1548,7 +1547,7 @@ (seesaw.core/text) http://download.oracle.com/javase/tutorial/uiswing/components/editorpane.html " - [^JTextPane target id ^Integer start ^Integer length] + ^JTextPane [^JTextPane target id ^Integer start ^Integer length] (check-args (instance? JTextPane target) "style-text! only applied to styled-text widgets") (.setCharacterAttributes (.getStyledDocument target) start length (.getStyle target (name id)) true) diff --git a/src/seesaw/graphics.clj b/src/seesaw/graphics.clj index e12d016b..5144b822 100644 --- a/src/seesaw/graphics.clj +++ b/src/seesaw/graphics.clj @@ -26,8 +26,8 @@ (.setRenderingHint RenderingHints/KEY_ANTIALIASING RenderingHints/VALUE_ANTIALIAS_ON))) (defn buffered-image - ([width height] (buffered-image width height BufferedImage/TYPE_INT_ARGB)) - ([width height t] (BufferedImage. width height t))) + (^BufferedImage [width height] (buffered-image width height BufferedImage/TYPE_INT_ARGB)) + (^BufferedImage [width height t] (BufferedImage. width height t))) (defn- to-image [v] (cond @@ -137,6 +137,8 @@ (.addPoint p x y)) p)) +(declare line-to move-to curve-to quad-to) + (def ^{:private true} path-ops { 'line-to '.lineTo 'move-to '.moveTo diff --git a/src/seesaw/icon.clj b/src/seesaw/icon.clj index 06864895..a3c3c32b 100644 --- a/src/seesaw/icon.clj +++ b/src/seesaw/icon.clj @@ -18,7 +18,7 @@ ;******************************************************************************* ; Icons -(defn ^javax.swing.Icon icon +(defn icon "Loads an icon. The parameter p can be any of the following: nil - returns nil @@ -33,7 +33,7 @@ This is the function used to process the :icon property on most widgets and windows. Thus, any of these values may be used for the :icon property. " - [p] + ^javax.swing.ImageIcon [p] (cond (nil? p) nil (instance? javax.swing.Icon p) p diff --git a/src/seesaw/keystroke.clj b/src/seesaw/keystroke.clj index fad57b22..6e5a86a6 100644 --- a/src/seesaw/keystroke.clj +++ b/src/seesaw/keystroke.clj @@ -41,7 +41,7 @@ arg can also be an i18n resource keyword. See http://download.oracle.com/javase/6/docs/api/javax/swing/KeyStroke.html#getKeyStroke(java.lang.String)" - [arg] + ^KeyStroke [arg] (cond (nil? arg) nil (instance? KeyStroke arg) arg diff --git a/src/seesaw/mig.clj b/src/seesaw/mig.clj index 9a8404f4..81d4cc8c 100644 --- a/src/seesaw/mig.clj +++ b/src/seesaw/mig.clj @@ -59,7 +59,7 @@ (seesaw.core/default-options) " { :seesaw {:class 'javax.swing.JPanel }} - [& opts] + ^javax.swing.JPanel [& opts] (abstract-panel (net.miginfocom.swing.MigLayout.) opts)) (extend-protocol LayoutManipulation diff --git a/src/seesaw/swingx.clj b/src/seesaw/swingx.clj index 82a546fa..87759959 100644 --- a/src/seesaw/swingx.clj +++ b/src/seesaw/swingx.clj @@ -64,7 +64,7 @@ (declare p-pattern) (declare p-fn) -(defn- ^HighlightPredicate to-p [v] +(defn- to-p ^HighlightPredicate [v] (cond (instance? HighlightPredicate v) v (instance? java.util.regex.Pattern v) (p-pattern v) @@ -159,7 +159,7 @@ :else (HighlighterFactory/createSimpleStriping))) -(defn ^Highlighter to-highlighter [v] +(defn to-highlighter ^Highlighter [v] (cond (instance? Highlighter v) v (= :shade v) (hl-shade) @@ -529,7 +529,7 @@ ;******************************************************************************* ; JXList -(def ^ {:private true} sort-order-table +(def ^:private sort-order-table { :ascending javax.swing.SortOrder/ASCENDING :descending javax.swing.SortOrder/DESCENDING}) @@ -585,7 +585,7 @@ See: (seesaw.core/listbox) " - [& args] + ^org.jdesktop.swingx.JXList [& args] (apply-options (doto (construct org.jdesktop.swingx.JXList) (.setAutoCreateRowSorter true) @@ -633,7 +633,7 @@ See: (seesaw.core/listbox) " - [& args] + ^org.jdesktop.swingx.JXTitledPanel [& args] (apply-options (construct org.jdesktop.swingx.JXTitledPanel) args)) @@ -666,7 +666,7 @@ (seesaw.core/tree-options) (seesaw.core/tree) " - [& args] + ^org.jdesktop.swingx.JXTree [& args] (apply-options (doto (construct org.jdesktop.swingx.JXTree) (.setRolloverEnabled true)) @@ -707,7 +707,7 @@ (seesaw.core/table-options) (seesaw.core/table) " - [& args] + ^org.jdesktop.swingx.JXTable [& args] (apply-options (doto (construct org.jdesktop.swingx.JXTable) (.setRolloverEnabled true) @@ -731,25 +731,25 @@ (defn- abstract-panel-x [layout opts] (abstract-panel (construct org.jdesktop.swingx.JXPanel) layout opts)) -(defn xyz-panel-x [& opts] +(defn xyz-panel-x ^org.jdesktop.swingx.JXPanel [& opts] (abstract-panel-x nil opts)) -(defn border-panel-x [& opts] +(defn border-panel-x ^org.jdesktop.swingx.JXPanel [& opts] (abstract-panel-x (java.awt.BorderLayout.) opts)) -(defn flow-panel-x [& opts] +(defn flow-panel-x ^org.jdesktop.swingx.JXPanel [& opts] (abstract-panel-x (java.awt.FlowLayout.) opts)) -(defn horizontal-panel-x [& opts] +(defn horizontal-panel-x ^org.jdesktop.swingx.JXPanel [& opts] (abstract-panel-x (box-layout :horizontal) opts)) -(defn vertical-panel-x [& opts] +(defn vertical-panel-x ^org.jdesktop.swingx.JXPanel [& opts] (abstract-panel-x (box-layout :vertical) opts)) (defn grid-panel-x - [& {:keys [rows columns] :as opts}] + ^org.jdesktop.swingx.JXPanel [& {:keys [rows columns] :as opts}] (abstract-panel-x (grid-layout rows columns) opts)) -(defn card-panel-x [& opts] +(defn card-panel-x ^org.jdesktop.swingx.JXPanel [& opts] (abstract-panel-x (java.awt.CardLayout.) opts)) diff --git a/src/seesaw/table.clj b/src/seesaw/table.clj index 9d8d3661..ed22d8a8 100644 --- a/src/seesaw/table.clj +++ b/src/seesaw/table.clj @@ -39,8 +39,8 @@ (let [[head [_ & tail]] (split-at pos row-vec)] (vec (concat head tail)))) -(defn- ^javax.swing.table.DefaultTableModel proxy-table-model - [column-names column-key-map column-classes] +(defn- proxy-table-model + ^javax.swing.table.DefaultTableModel [column-names column-key-map column-classes] (let [full-values (atom [])] (proxy [javax.swing.table.DefaultTableModel] [(object-array column-names) 0] (isCellEditable [row col] false) @@ -131,7 +131,7 @@ (seesaw.core/table) http://download.oracle.com/javase/6/docs/api/javax/swing/table/TableModel.html " - [& {:keys [columns rows] :as opts}] + ^javax.swing.table.DefaultTableModel [& {:keys [columns rows] :as opts}] (let [norm-cols (map normalize-column columns) col-names (map :text norm-cols) col-classes (map :class norm-cols) diff --git a/src/seesaw/timer.clj b/src/seesaw/timer.clj index f740bd0f..e5673aaf 100644 --- a/src/seesaw/timer.clj +++ b/src/seesaw/timer.clj @@ -40,7 +40,7 @@ See http://download.oracle.com/javase/6/docs/api/javax/swing/Timer.html " - [f & {:keys [start? initial-value] :or {start? true} :as opts}] + ^javax.swing.Timer [f & {:keys [start? initial-value] :or {start? true} :as opts}] (let [a (action :handler (timer-handler f initial-value)) t (javax.swing.Timer. 0 a)] (.setDelay t 1000) diff --git a/src/seesaw/util.clj b/src/seesaw/util.clj index 01b8f5ba..472be53f 100644 --- a/src/seesaw/util.clj +++ b/src/seesaw/util.clj @@ -111,19 +111,19 @@ (cast c x) (catch ClassCastException e nil))) -(defn ^URL to-url +(defn to-url "Try to parse (str s) as a URL. Returns new java.net.URL on success, nil otherwise. This is different from clojure.java.io/as-url in that it doesn't throw an exception and it uses (str) on the input." - [s] + ^URL [s] (if (instance? URL s) s (try (URL. (str s)) (catch MalformedURLException e nil)))) -(defn ^URI to-uri +(defn to-uri "Try to make a java.net.URI from s" - [s] + ^URI [s] (cond (instance? URI s) s (instance? URL s) (.toURI ^URL s) @@ -132,7 +132,7 @@ (catch URISyntaxException e nil)))) (defn to-dimension - [v] + ^java.awt.Dimension [v] (cond (instance? java.awt.Dimension v) v (and (vector? v) (= 3 (count v)) (= :by (second v))) diff --git a/src/seesaw/widgets/rounded_label.clj b/src/seesaw/widgets/rounded_label.clj index e07c0dac..f2b2271c 100644 --- a/src/seesaw/widgets/rounded_label.clj +++ b/src/seesaw/widgets/rounded_label.clj @@ -36,14 +36,14 @@ See: (seesaw.core/label) " - [& opts] + ^javax.swing.JLabel [& opts] (let [radius 15 paint (fn [^javax.swing.JLabel c ^java.awt.Graphics g] (doto g (.setColor (.getBackground c)) (.fillRoundRect 0 0 (dec (.getWidth c)) (dec (.getHeight c)) - @radius @radius))) + radius radius))) widget (rounded-label-proxy paint)] (apply-options widget opts))) diff --git a/test/seesaw/test/action.clj b/test/seesaw/test/action.clj index b2a4c5c3..c0835306 100644 --- a/test/seesaw/test/action.clj +++ b/test/seesaw/test/action.clj @@ -9,14 +9,15 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.action - (:use [seesaw.action] - [seesaw.core :only [config]] - [seesaw.keystroke :only [keystroke]]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)]) - (:import [javax.swing Action])) + (:require + [lazytest.core :refer [defdescribe describe expect expect-it it]] + [seesaw.action :refer [action]] + [seesaw.core :refer [config]] + [seesaw.keystroke :refer [keystroke]]) + (:import + [javax.swing Action])) -(describe action +(defdescribe action-test (it "sets the name, tooltip, and command" (let [a (action :name "Test" :tip "This is a tip" :command "Go!")] (expect (instance? Action a)) @@ -42,7 +43,7 @@ (expect (= (int \T) m)))) (it "calls the handler when actionPerformed is called" (let [called (atom false) - f (fn [e] (reset! called true)) + f (fn [_] (reset! called true)) a (action :handler f)] (.actionPerformed a nil) (expect @called))) @@ -70,16 +71,16 @@ (expect (= "A tip" (config a :tip))) (expect (= (keystroke "ctrl C") (config a :key))))) - (it "loads :icon from a resource" - (expect (instance? javax.swing.Icon (config (action :icon ::my-action.icon) :icon)))) - (it "loads :mnemonic from a resource" - (expect (= (int \X) (config (action :mnemonic ::my-action.mnemonic) :mnemonic)))) - (it "loads :command from a resource" - (expect (= "A command" (config (action :command ::my-action.command) :command)))) - (it "loads :name from a resource" - (expect (= "A name" (config (action :name ::my-action.name) :name)))) - (it "loads :key from a resource" - (expect (= (keystroke "ctrl C") (config (action :key ::my-action.key) :key)))) - (it "loads :tip from a resource" - (expect (= "A tip" (config (action :tip ::my-action.tip) :tip))))) + (expect-it "loads :icon from a resource" + (instance? javax.swing.Icon (config (action :icon ::my-action.icon) :icon))) + (expect-it "loads :mnemonic from a resource" + (= (int \X) (config (action :mnemonic ::my-action.mnemonic) :mnemonic))) + (expect-it "loads :command from a resource" + (= "A command" (config (action :command ::my-action.command) :command))) + (expect-it "loads :name from a resource" + (= "A name" (config (action :name ::my-action.name) :name))) + (expect-it "loads :key from a resource" + (= (keystroke "ctrl C") (config (action :key ::my-action.key) :key))) + (expect-it "loads :tip from a resource" + (= "A tip" (config (action :tip ::my-action.tip) :tip)))) diff --git a/test/seesaw/test/behave.clj b/test/seesaw/test/behave.clj index cf02c9dc..9e34ec43 100644 --- a/test/seesaw/test/behave.clj +++ b/test/seesaw/test/behave.clj @@ -9,12 +9,12 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.behave - (:use seesaw.behave) - (:use seesaw.core) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe expect it]] + [seesaw.behave :refer [when-focused-select-all]] + [seesaw.core :refer [text]])) -(describe when-focused-select-all +(defdescribe when-focused-select-all-test (it "causes all text in a text field to be selected when it gains focus" (let [t (text "Hi there") remove-fn (when-focused-select-all t)] diff --git a/test/seesaw/test/bind.clj b/test/seesaw/test/bind.clj index 8cd64607..b71f187e 100644 --- a/test/seesaw/test/bind.clj +++ b/test/seesaw/test/bind.clj @@ -1,11 +1,11 @@ (ns seesaw.test.bind (:refer-clojure :exclude [some filter]) - (:require [seesaw.core :as ssc]) - (:use seesaw.bind) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe describe expect it]] + [seesaw.bind :refer :all] + [seesaw.core :as ssc])) -(describe bind +(defdescribe bind-test (it "returns a composite bindable" (let [a (atom 0) b (atom 1) c (atom 2) d (atom 3) cb (bind a b c d) @@ -63,7 +63,7 @@ (reset! v false) (expect (not (.isEnabled b))))) - (testing "with a BoundedRangeModel" + (describe "with a BoundedRangeModel" (it "Updates an atom when the model changes" (let [a (atom -1) m (javax.swing.DefaultBoundedRangeModel. 50 0 2 100)] @@ -77,7 +77,7 @@ (reset! a 99) (expect (= 99 (.getValue m)))))) - (testing "given a text field" + (describe "given a text field" (it "should update an atom when the underlying document changes" (let [a (atom nil) t (ssc/text "initial")] @@ -92,7 +92,7 @@ (reset! a "foo") (expect (= "foo" (ssc/text t)))))) - (testing "given a slider" + (describe "given a slider" (it "should sync the value of the atom with the slider value, if slider value changed" (let [v (atom 15) sl (ssc/slider :value @v)] @@ -106,7 +106,7 @@ (reset! v 20) (expect (= (.getValue sl) 20))))) - (testing "given a toggle button (or any button/menu)" + (describe "given a toggle button (or any button/menu)" (it "should sync the selection state of the button" (let [v (atom nil) b (ssc/toggle :selected? false)] @@ -121,7 +121,7 @@ (reset! v true) (expect (.isSelected b))))) - (testing "given a combobox" + (describe "given a combobox" (it "should sync the selection state of the combobox" (let [v (atom nil) b (ssc/combobox :model [1 2 3 4])] @@ -136,7 +136,7 @@ (reset! v 4) (expect (= 4 (ssc/selection b)))))) - (testing "given a spinner" + (describe "given a spinner" (it "should sync the value of the atom with the spinner value, if spinner value changed" (let [v (atom 15) sl (ssc/spinner :model @v)] @@ -150,7 +150,7 @@ (reset! v 20) (expect (= (.getValue sl) 20))))) - (testing "given an agent" + (describe "given an agent" (it "should pass along changes to the agent's value" (let [start (agent nil) @@ -174,7 +174,7 @@ (catch RuntimeException e (= IllegalStateException (class (.getCause e))))))))) - (testing "given a Ref" + (describe "given a Ref" (it "should pass along changes to the ref's value" (let [start (ref nil) end (atom nil)] @@ -189,9 +189,9 @@ (bind start end) (reset! start "foo") (expect (= "foo" @start)) - (expect (= "foo" @end))))) ) + (expect (= "foo" @end)))))) -(describe b-do* +(defdescribe b-do*-test (it "executes a function with a single argument and ends a chain" (let [start (atom 0) called (atom nil) ] @@ -199,7 +199,7 @@ (reset! start 5) (expect (= 5 @called))))) -(describe b-do +(defdescribe b-do-test (it "executes body with a single argument and ends a chain" (let [start (atom [1 2]) called (atom nil)] @@ -207,7 +207,7 @@ (reset! start [3 4]) (expect (= 7 @called))))) -(describe tee +(defdescribe tee-test (it "creates a tee junction in a bind" (let [start (atom 0) end1 (atom 0) @@ -258,7 +258,7 @@ (reset! start :something) (expect (= :yum @end))))) -(describe selection +(defdescribe selection-test (it "sends out selection changes on a widget" (let [lb (ssc/listbox :model [:a :b :c]) output (atom nil)] @@ -272,7 +272,7 @@ (reset! input :b) (expect (= :b (ssc/selection lb)))))) -(describe value +(defdescribe value-test (it "maps its input to the value of a widget" (let [input (atom nil) lb (ssc/listbox :id :lb :model [:a :b :c]) @@ -282,7 +282,7 @@ (reset! input {:lb :b :text "hi"}) (expect (= {:lb :b :text "hi"} (ssc/value p)))))) -(describe to-bindable +(defdescribe to-bindable-test (it "returns arg if it's already bindable" (let [a (atom nil)] (expect (= a (to-bindable a))))) @@ -368,7 +368,7 @@ (expect (= {:value 99 :edt? true} @end))))) (describe subscribe - (testing "on an atom" + (describe "on an atom" (it "should return a function that unsubscribes" (let [calls (atom 0) target (atom "hi") @@ -379,7 +379,7 @@ (reset! target "b") (expect (= 1 @calls))))) - (testing "on an agent" + (describe "on an agent" (it "should return a function that unsubscribes" (let [calls (atom 0) target (agent "hi") @@ -390,7 +390,7 @@ (await (send target (fn [_] "b"))) (expect (= 1 @calls))))) - (testing "on a javax.swing.text.Document" + (describe "on a javax.swing.text.Document" (it "should return a function that unsubscribes" (let [calls (atom 0) target (.getDocument (ssc/text)) @@ -401,7 +401,7 @@ (.insertString target 0 "bye" nil) (expect (= 1 @calls)) ))) - (testing "on a javax.swing.BoundedRangeModel" + (describe "on a javax.swing.BoundedRangeModel" (it "should return a function that unsubscribes" (let [calls (atom 0) target (javax.swing.DefaultBoundedRangeModel. 50 0 2 100) @@ -412,7 +412,7 @@ (.setValue target 2) (expect (= 1 @calls))))) - (testing "on a funnel" + (describe "on a funnel" (it "should return a function that unsubscribes" (let [calls (atom 0) a (atom "hi") @@ -425,7 +425,7 @@ (expect (= 1 @calls)) ))) - (testing "on a widget property" + (describe "on a widget property" (it "should return a function that unsubscribes" (let [calls (atom 0) w (ssc/text) @@ -437,7 +437,7 @@ (.setEnabled w true) (expect (= 1 @calls)) ))) - (testing "on a transform" + (describe "on a transform" (it "should return a function that unsubscribes" (let [calls (atom 0) target (transform identity) @@ -448,7 +448,7 @@ (notify target "bye") (expect (= 1 @calls)) ))) - (testing "on a filter" + (describe "on a filter" (it "should return a function that unsubscribes" (let [calls (atom 0) target (filter (constantly true)) @@ -458,7 +458,7 @@ (unsub) (notify target "bye") (expect (= 1 @calls))))) - (testing "on a some" + (describe "on a some" (it "should return a function that unsubscribes" (let [calls (atom 0) target (some (constantly true)) diff --git a/test/seesaw/test/border.clj b/test/seesaw/test/border.clj index 15c8d22a..a37cc6a1 100644 --- a/test/seesaw/test/border.clj +++ b/test/seesaw/test/border.clj @@ -9,13 +9,18 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.border - (:use seesaw.border) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)]) - (:import [javax.swing.border EmptyBorder LineBorder MatteBorder TitledBorder] - [java.awt Insets Color])) + (:require + [lazytest.core :refer [defdescribe expect it expect-it]] + [seesaw.border :refer :all]) + (:import + [java.awt Color Insets] + [javax.swing.border + EmptyBorder + LineBorder + MatteBorder + TitledBorder])) -(describe empty-border +(defdescribe empty-border-test (it "creates a 1 pixel border by default" (let [b (empty-border)] (expect (= EmptyBorder (class b))) @@ -33,7 +38,7 @@ (expect (= EmptyBorder (class b))) (expect (= (Insets. 0 3 0 0) (.getBorderInsets b)))))) -(describe line-border +(defdescribe line-border-test (it "creates a black, one pixel border by default" (let [b (line-border)] (expect (= LineBorder (class b))) @@ -55,7 +60,7 @@ (expect (= (Insets. 2 0 0 0) (.getBorderInsets b))) (expect (= Color/BLACK (.getMatteColor b)))))) -(describe compound-border +(defdescribe compound-border-test (it "creates nested compound borders inner to outer" (let [in (line-border) mid (line-border) @@ -65,8 +70,8 @@ (expect (= mid (.. b (getInsideBorder) (getOutsideBorder)))) (expect (= in (.. b (getInsideBorder) (getInsideBorder))))))) -(describe to-border - (it "returns nil given nil" +(defdescribe to-border-test + (expect-it "returns nil given nil" (nil? (to-border nil))) (it "returns input if it's already a border" (let [b (line-border)] @@ -92,8 +97,8 @@ (expect (= "Outer" (.. b getOutsideBorder getTitle))) (expect (= "Inner" (.. b getInsideBorder getTitle)))))) -(describe custom-border - (it "creates a custom border implementation" +(defdescribe custom-border-test + (expect-it "creates a custom border implementation" (instance? javax.swing.border.Border (custom-border))) (it "returns integer insets" (let [b (custom-border :insets 3)] @@ -115,4 +120,3 @@ b (custom-border :paint (fn [c g x y w h] (reset! called true)))] (.paintBorder b nil nil 0 0 0 0) (expect @called)))) - diff --git a/test/seesaw/test/cells.clj b/test/seesaw/test/cells.clj index 354dd24d..5208f2af 100644 --- a/test/seesaw/test/cells.clj +++ b/test/seesaw/test/cells.clj @@ -9,13 +9,13 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.cells - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)] - [seesaw.core] - [seesaw.cells] - [seesaw.font])) + (:require + [lazytest.core :refer (defdescribe it expect expect-it)] + [seesaw.cells :refer :all] + [seesaw.core :refer [config!]] + [seesaw.font :refer [font]])) -(describe default-list-cell-renderer +(defdescribe default-list-cell-renderer-test (it "proxies a DefaultListCellRenderer which dispatches to a function" (let [expected-font (font :name "ARIAL-BOLD-18") jlist (javax.swing.JList.) @@ -31,7 +31,7 @@ (expect (= nil (.getIcon c))) (expect (= expected-font (.getFont c)))))) -(describe default-tree-cell-renderer +(defdescribe default-tree-cell-renderer-test (it "proxies a DefaultTreeCellRenderer which dispatches to a function" (let [expected-font (font :name "ARIAL-BOLD-18") jtree (javax.swing.JTree.) @@ -47,16 +47,14 @@ (expect (= nil (.getIcon c))) (expect (= expected-font (.getFont c)))))) -(describe to-cell-renderer - (it "throws an exception if it can't make a renderer for a component" +(defdescribe to-cell-renderer-test + (expect-it "throws an exception if it can't make a renderer for a component" (try - (to-cell-renderer (javax.swing.JLabel.) nil) false - (catch IllegalArgumentException e true))) + (to-cell-renderer (javax.swing.JLabel.) nil) false + (catch IllegalArgumentException e true))) (it "creates a tree cell renderer for a JTree" (instance? javax.swing.tree.TreeCellRenderer (to-cell-renderer (javax.swing.JTree.) (fn [r i])))) (it "creates a list cell renderer for a JList" (instance? javax.swing.ListCellRenderer (to-cell-renderer (javax.swing.JList.) (fn [r i])))) (it "creates a list cell renderer for a JComboBox" (instance? javax.swing.ListCellRenderer (to-cell-renderer (javax.swing.JComboBox.) (fn [r i]))))) - - diff --git a/test/seesaw/test/chooser.clj b/test/seesaw/test/chooser.clj index f4e9d5af..17f8a61c 100644 --- a/test/seesaw/test/chooser.clj +++ b/test/seesaw/test/chooser.clj @@ -9,11 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.chooser - (:use seesaw.chooser) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe expect-it]] + [seesaw.chooser :refer :all])) -(describe file-filter - (it "should create a FileFilter" +(defdescribe file-filter-test + (expect-it "should create a FileFilter" (instance? javax.swing.filechooser.FileFilter (file-filter "All files" (constantly true))))) diff --git a/test/seesaw/test/color.clj b/test/seesaw/test/color.clj index 7056197a..08befa1b 100644 --- a/test/seesaw/test/color.clj +++ b/test/seesaw/test/color.clj @@ -9,16 +9,17 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.color - (:use seesaw.color) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)]) - (:import [java.awt Color])) + (:require + [lazytest.core :refer [defdescribe expect expect-it it]] + [seesaw.color :refer :all]) + (:import + [java.awt Color])) -(describe get-rgba - (it "returns vector [r g b a] as integers" +(defdescribe get-rgba-test + (expect-it "returns vector [r g b a] as integers" (= [1 2 3 4] (get-rgba (color 1 2 3 4))))) -(describe color +(defdescribe color-test (it "can create a color from rgb integers" (let [c (color 1 2 3)] (expect (= (Color. 1 2 3) c)))) @@ -40,20 +41,20 @@ (it "can create a color from a #-prefixed rgb hex keyword and alpha" (let [c (color :#010203 23)] (expect (= (Color. 1 2 3 23) c)))) - (it "can create a color from a CSS-style name" - (expect (= (Color. 240 248 255) (color "aliceblue")))) - (it "can create a color from a CSS-style keyword name" - (expect (= (Color. 0 255 127) (color :springgreen)))) - (it "can create a color from a mixed-case CSS-style name" - (expect (= (Color. 240 248 255) (color "AlIceBlUe"))))) + (expect-it "can create a color from a CSS-style name" + (= (Color. 240 248 255) (color "aliceblue"))) + (expect-it "can create a color from a CSS-style keyword name" + (= (Color. 0 255 127) (color :springgreen))) + (expect-it "can create a color from a mixed-case CSS-style name" + (= (Color. 240 248 255) (color "AlIceBlUe")))) -(describe to-color - (it "returns nil for nil input" +(defdescribe to-color-test + (expect-it "returns nil for nil input" (nil? (to-color nil))) - (it "returns its input if its a color" - (expect (= Color/BLACK (to-color Color/BLACK))))) + (expect-it "returns its input if its a color" + (= Color/BLACK (to-color Color/BLACK)))) -(describe default-color +(defdescribe default-color-test (it "retrieve a default color from the UIManager" (let [name "Label.foreground" c (default-color name) diff --git a/test/seesaw/test/config.clj b/test/seesaw/test/config.clj index 28affa1b..541dae81 100644 --- a/test/seesaw/test/config.clj +++ b/test/seesaw/test/config.clj @@ -9,9 +9,9 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.config - (:use [seesaw.config :only [config config!]]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [seesaw.config :refer [config config!]] + [lazytest.core :refer [defdescribe expect it]])) ; Pretty much tested in core diff --git a/test/seesaw/test/core.clj b/test/seesaw/test/core.clj index 1fbec73b..e7acf982 100644 --- a/test/seesaw/test/core.clj +++ b/test/seesaw/test/core.clj @@ -9,105 +9,117 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.core - (:require [seesaw.selector :as selector] - [seesaw.cursor :as cursor] - seesaw.meta - clojure.java.io) - (:use seesaw.core - seesaw.font - seesaw.graphics - seesaw.cells - [seesaw.util :only (to-dimension children root-cause)] - [seesaw.color :only (color)] - [seesaw.options :only [apply-options]]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)] - [clojure.string :only (capitalize split)]) - (:import [javax.swing SwingConstants - ScrollPaneConstants - Action - JFrame - JToolBar JTabbedPane - JPanel JLabel JButton JTextField JTextArea Box Box$Filler BoxLayout JTextPane - JToggleButton JCheckBox JRadioButton - JScrollPane - JSplitPane] - [javax.swing.text StyleConstants] - [java.awt Insets Color Dimension FlowLayout BorderLayout] - [java.awt.event ActionEvent])) - -(describe id-of - (it "returns nil if a widget doesn't have an id" + (:require + [clojure.java.io :as io] + [lazytest.core :refer [defdescribe describe expect expect-it it]] + [seesaw.cells :refer :all] + [seesaw.core :refer :all] + [seesaw.cursor :as cursor] + [seesaw.font :refer :all] + [seesaw.graphics :refer :all] + [seesaw.meta :as meta] + [seesaw.options :refer [apply-options]] + [seesaw.selector :as selector] + [seesaw.util :refer [root-cause]]) + (:import + [java.awt + BorderLayout + Color + Dimension + FlowLayout] + [java.awt.event ActionEvent] + [javax.swing + Action + BoxLayout + JButton + JCheckBox + JFrame + JLabel + JPanel + JRadioButton + JScrollPane + JTabbedPane + JTextArea + JTextField + JTextPane + JToggleButton + ScrollPaneConstants + SwingConstants] + [javax.swing.text StyleConstants])) + +(defdescribe id-of-test + (expect-it "returns nil if a widget doesn't have an id" (nil? (id-of (label)))) (it "coerces to a widget before getting the id" (let [b (button :id :my-button) e (java.awt.event.ActionEvent. b java.awt.event.ActionEvent/ACTION_PERFORMED "")] (expect (= :my-button (id-of e))))) - (it "returns the correct id, as a keyword, if a widget has an id" + (expect-it "returns the correct id, as a keyword, if a widget has an id" (= (keyword "id of the label") (id-of (label :id "id of the label"))))) -(describe user-data - (it "returns the value of the :user-data option" +(defdescribe user-data-test + (expect-it "returns the value of the :user-data option" (= :got-it (user-data (combobox :user-data :got-it))))) -(describe "Applying default options" - (testing "the :id option" - (it "does nothing when omitted" - (expect (nil? (-> (JPanel.) (apply-options {}) id-of)))) - (it "sets the component's id as a keyword if given" - (expect (= :hi (-> (JLabel.) (apply-options {:id "hi"}) id-of)))) - (it "throws IllegalStateException if the widget's id is already set" +(defdescribe applying-default-test + "Applying default options" + (describe "the :id option" + (expect-it "does nothing when omitted" + (nil? (-> (JPanel.) (apply-options {}) id-of))) + (expect-it "sets the component's id as a keyword if given" + (= :hi (-> (JLabel.) (apply-options {:id "hi"}) id-of))) + (expect-it "throws IllegalStateException if the widget's id is already set" (try - (do (config! (label :id :foo) :id :bar) false) + (config! (label :id :foo) :id :bar) false (catch IllegalStateException e true)))) - (testing "the :class option" - (it "does nothing when omitted" - (expect (nil? (-> (JPanel.) (apply-options {}) selector/class-of)))) - (it "sets the class of the widget" - (expect (= #{"foo"} (selector/class-of (flow-panel :class :foo))))) - (it "sets the classes of a widget" - (expect (= #{"foo" "bar"} (selector/class-of (flow-panel :class #{:foo :bar})))))) + (describe "the :class option" + (expect-it "does nothing when omitted" + (nil? (-> (JPanel.) (apply-options {}) selector/class-of))) + (expect-it "sets the class of the widget" + (= #{"foo"} (selector/class-of (flow-panel :class :foo)))) + (expect-it "sets the classes of a widget" + (= #{"foo" "bar"} (selector/class-of (flow-panel :class #{:foo :bar}))))) - (testing "the :paint option" + (describe "the :paint option" (it "sets the paint-property to a function" (let [f (fn [g c]) b (button :paint f) - pp (seesaw.meta/get-meta b "seesaw-paint")] + pp (meta/get-meta b "seesaw-paint")] (expect (= f (:after pp)))))) - (testing "the :user-data option" - (it "associates user data with the widget" - (expect (= "I'm some user data" - (-> (label :user-data "I'm some user data") - (config :user-data)))))) + (describe "the :user-data option" + (expect-it "associates user data with the widget" + (= "I'm some user data" + (-> (label :user-data "I'm some user data") + (config :user-data))))) - (testing "the :layout option" + (describe "the :layout option" (it "sets the layout of the widget" (let [layout (java.awt.BorderLayout.) b (button :layout layout)] (expect (= layout (config b :layout)))))) - (testing "the :focusable? option" - (it "makes a widget focusable" + (describe "the :focusable? option" + (expect-it "makes a widget focusable" (.isFocusable (label :text "focusable" :focusable? true)))) - (testing "the :preferred-size option" + (describe "the :preferred-size option" (it "set the component's preferred size using to-dimension" (let [p (apply-options (JPanel.) {:preferred-size [10 :by 20]})] (expect (= (Dimension. 10 20) (.getPreferredSize p)))))) - (testing "the :minimum-size option" + (describe "the :minimum-size option" (it "set the component's minimum size using to-dimension" (let [p (apply-options (JPanel.) {:minimum-size [10 :by 20]})] (expect (= (Dimension. 10 20) (.getMinimumSize p)))))) - (testing "the :maximum-size option" + (describe "the :maximum-size option" (it "set the component's maximum size using to-dimension" (let [p (apply-options (JPanel.) {:maximum-size [10 :by 20]})] (expect (= (Dimension. 10 20) (.getMaximumSize p)))))) - (testing "the :size option" + (describe "the :size option" (it "set the component's min, max, and preferred size using to-dimension" (let [p (apply-options (JPanel.) {:size [11 :by 21]}) d (Dimension. 11 21)] @@ -115,7 +127,7 @@ (expect (= d (.getMinimumSize p))) (expect (= d (.getMaximumSize p)))))) - (testing "the :location option" + (describe "the :location option" (it "sets the component's location with a two-element vector" (let [p (apply-options (JPanel.) {:location [23 45]}) l (.getLocation p)] @@ -132,7 +144,7 @@ (let [p (apply-options (JPanel.) {:location (java.awt.Rectangle. 23 45 99 100)}) l (.getLocation p)] (expect (= [23 45] [(.x l) (.y l)]))))) - (testing "the :bounds option" + (describe "the :bounds option" (it "sets the component's bounds with a [x y width height] vector" (let [p (apply-options (JPanel.) {:bounds [23 45 67 89]}) b (.getBounds p)] @@ -158,7 +170,7 @@ b (.getBounds p)] (expect (= [23 45 67 89] [(.x b) (.y b) (.width b) (.height b)]))))) - (testing "the :cursor option" + (describe "the :cursor option" (it "sets the widget's cursor when given a cursor" (let [c (cursor/cursor :hand) p (apply-options (JPanel.) {:cursor c})] @@ -167,7 +179,7 @@ (let [p (apply-options (JPanel.) {:cursor :hand})] (expect (= java.awt.Cursor/HAND_CURSOR (.getType (.getCursor p))))))) - (testing "setting enabled option" + (describe "setting enabled option" (it "does nothing when omitted" (let [c (apply-options (JPanel.) {})] (expect (.isEnabled c)))) @@ -180,7 +192,7 @@ (it "sets enabled when provided a falsey value" (let [c (apply-options (JPanel.) {:enabled? nil})] (expect (= false (.isEnabled c)))))) - (testing "setting visible? option" + (describe "setting visible? option" (it "does nothing when omitted" (let [c (apply-options (JPanel.) {})] (expect (.isVisible c)))) @@ -194,14 +206,14 @@ (let [c (apply-options (JPanel.) {:visible? nil})] (expect (= false (.isVisible c)))))) - (testing "setting opaque? option" + (describe "setting opaque? option" (it "does nothing when omitted" (let [c (apply-options (JPanel.) {})] (expect (.isOpaque c)))) (it "sets opacity when provided" (let [c (apply-options (JPanel.) {:opaque? false})] (expect (not (.isOpaque c)))))) - (testing "the :model property" + (describe "the :model property" (it "sets the model when provided" (let [model (javax.swing.DefaultButtonModel.) widget (button :model model)] @@ -222,18 +234,18 @@ (let [c (apply-options (JPanel.) {:cursor :hand})] (expect (= java.awt.Cursor/HAND_CURSOR (.getType (.getCursor c))))))) -(describe show! - (it "makes a widget visible and returns it" +(defdescribe show!-test + (expect-it "makes a widget visible and returns it" (.isVisible (show! (doto (JPanel.) (.setVisible false)))))) -(describe hide! - (it "hides a widget and returns it" +(defdescribe hide!-test + (expect-it "hides a widget and returns it" (not (.isVisible (hide! (doto (JPanel.) (.setVisible true))))))) -(describe make-widget - (it "throws an exception for unsupported arguments" +(defdescribe make-widget-test + (expect-it "throws an exception for unsupported arguments" (try (make-widget 99) false (catch Exception e true))) - (it "returns nil if input is nil" + (expect-it "returns nil if input is nil" (= nil (make-widget nil))) (it "returns input if it's already a widget" (let [c (JPanel.)] @@ -249,7 +261,7 @@ c (make-widget a)] (expect (instance? javax.swing.JButton c)) (expect (= "Test" (.getText c))))) - (it "creates a separator for :separator" + (expect-it "creates a separator for :separator" (instance? javax.swing.JSeparator (make-widget :separator))) (it "creates horizontal glue for :fill-h" (let [c (make-widget :fill-h)] @@ -286,10 +298,10 @@ (expect (= 12.0 (.. c getPreferredSize getWidth))) (expect (= 34.0 (.. c getPreferredSize getHeight)))))) -(describe to-widget - (it "returns nil for unknown inputs" +(defdescribe to-widget-test + (expect-it "returns nil for unknown inputs" (= nil (to-widget "a string"))) - (it "returns nil if input is nil" + (expect-it "returns nil if input is nil" (= nil (to-widget nil))) (it "returns input if it's already a widget" (let [c (JPanel.)] @@ -302,8 +314,8 @@ e (ActionEvent. b 0 "hi")] (expect (= b (to-widget e)))))) -(describe to-document - (it "returns nil if input is nil" +(defdescribe to-document-test + (expect-it "returns nil if input is nil" (nil? (to-document nil))) (it "returns input if it's already a document" (let [d (javax.swing.text.PlainDocument.)] @@ -312,23 +324,24 @@ (let [t (text)] (expect (= (.getDocument t) (to-document t)))))) -(defmacro verify-config [target key getter] +(defmacro verify-config + [target key getter] (let [t (gensym "t")] `(it ~(str "can retrieve the value of " key " from a widget") - (let [~t ~target - expected# ~(if (symbol? getter) `(. ~t ~getter) getter) - actual# (config ~t ~key)] - (expect (= expected# actual#)))))) + (let [~t ~target + expected# ~(if (symbol? getter) `(. ~t ~getter) getter) + actual# (config ~t ~key)] + (expect (= expected# actual#)))))) -(describe config - (it "throws IllegalArgumentException for an unknown option" +(defdescribe config-test + (expect-it "throws IllegalArgumentException for an unknown option" (try (config (text "HI") :textish) false (catch IllegalArgumentException e true))) - (it "can retrieve the :id of a widget" + (expect-it "can retrieve the :id of a widget" (= :foo (config (text :id :foo) :id))) - (it "can retrieve the :class of a widget" + (expect-it "can retrieve the :class of a widget" (= #{"foo"} (config (text :class :foo) :class))) (verify-config (text :drag-enabled? true) :drag-enabled? true) @@ -374,7 +387,7 @@ (verify-config (slider) :model getModel) ) -(describe config! +(defdescribe config!-test (it "configures the properties given to it on a single target" (let [p (JPanel.) result (config! p :foreground Color/RED :background Color/BLUE :enabled? false)] @@ -408,7 +421,7 @@ (config! a :name "bar") (expect (= "bar" (.getValue a Action/NAME)))))) -(describe flow-panel +(defdescribe flow-panel-test (it "should create a FlowLayout of :items list" (let [[a b c] [(JPanel.) (JPanel.) (JPanel.)] p (flow-panel :items [a b c] :align :trailing :hgap 99 :vgap 12 :align-on-baseline? true) @@ -423,20 +436,20 @@ (let [items [(JPanel.) (JPanel.) (JPanel.)] p (flow-panel :items items)] (expect (= items (config p :items))))) - (it "should throw IllegalArgumentException if a nil item is given" + (expect-it "should throw IllegalArgumentException if a nil item is given" (try (flow-panel :items [nil]) false (catch IllegalArgumentException e true)))) -(describe xyz-panel - (it "should create a JPanel" +(defdescribe xyz-panel-test + (expect-it "should create a JPanel" (instance? JPanel (xyz-panel))) - (it "should create a JPanel with a nil layout" + (expect-it "should create a JPanel with a nil layout" (nil? (.getLayout (xyz-panel)))) (it "should add items" (let [[a b c :as items] [(label :text "a") (label :text "b") (button :text "c")] p (xyz-panel :items items)] (expect (= items (vec (.getComponents p))))))) -(describe border-panel +(defdescribe border-panel-test (it "should create a BorderLayout with given h and v gaps" (let [p (border-panel :hgap 99 :vgap 12) l (.getLayout p)] @@ -463,7 +476,7 @@ p (border-panel :hgap 99 :vgap 12 :items items)] (expect (= items (config p :items)))))) -(describe horizontal-panel +(defdescribe horizontal-panel-test (it "should create a horizontal box of :items list" (let [[a b c] [(JPanel.) (JPanel.) (JPanel.)] p (horizontal-panel :items [a b c])] @@ -474,7 +487,7 @@ p (horizontal-panel :items items)] (expect (= items (config p :items)))))) -(describe vertical-panel +(defdescribe vertical-panel-test (it "should create a vertical box of :items list" (let [[a b c] [(JPanel.) (JPanel.) (JPanel.)] p (vertical-panel :items [a b c])] @@ -485,7 +498,7 @@ p (vertical-panel :items items)] (expect (= items (config p :items)))))) -(describe grid-panel +(defdescribe grid-panel-test (it "should default to 1 column" (let [g (grid-panel) l (.getLayout g)] @@ -510,8 +523,8 @@ g (grid-panel :items items)] (expect (= items (config g :items)))))) -(describe form-panel - (it "should create a JPanel with a GridBagLayout" +(defdescribe form-panel-test + (expect-it "should create a JPanel with a GridBagLayout" (= java.awt.GridBagLayout (class (.getLayout (form-panel))))) (it "should add an item with grid bag constraints" (let [p (form-panel :items [["hi" :weighty 999 :gridwidth 1]]) @@ -521,34 +534,35 @@ (expect (= java.awt.GridBagConstraints (class gbcs))) (expect (= 999.0 (.weighty gbcs)))))) -(describe "for an arbitrary widget" +(defdescribe arbitrary-widget-test + "for an arbitrary widget" (it "should support the :font property" (let [f (font "ARIAL-BOLD-18") l (label :font f)] (expect (= f (.getFont l)))))) -(describe label +(defdescribe label-test (it "should create an empty label" (let [l (label)] (expect (instance? JLabel l)) (expect (= "" (.getText l))))) - (it "should create a label with tooltip" - (expect (= "HI" (.getToolTipText (label :tip "HI"))))) - (it "should create a label with text when given a single argument" - (expect (= "test label" (.getText (label "test label"))))) - (it "should create a label with text" - (expect (= "test label" (.getText (label :text "test label"))))) - (it "should create a label with horizontal alignment" + (expect-it "should create a label with tooltip" + (= "HI" (.getToolTipText (label :tip "HI")))) + (expect-it "should create a label with text when given a single argument" + (= "test label" (.getText (label "test label")))) + (expect-it "should create a label with text" + (= "test label" (.getText (label :text "test label")))) + (expect-it "should create a label with horizontal alignment" (= SwingConstants/LEFT (.getHorizontalAlignment (label :halign :left)))) - (it "should create a label with horizontal text position" + (expect-it "should create a label with horizontal text position" (= SwingConstants/LEFT (.getHorizontalTextPosition (label :h-text-position :left)))) - (it "should create a label with vertical text position" + (expect-it "should create a label with vertical text position" (= SwingConstants/BOTTOM (.getVerticalTextPosition (label :v-text-position :bottom)))) - (it "should create a label with vertical alignment" + (expect-it "should create a label with vertical alignment" (= SwingConstants/BOTTOM (.getVerticalAlignment (label :valign :bottom))))) -(describe text! - (it "should throw IllegalArgumentException if it doesn't know what to do" +(defdescribe text!-test + (expect-it "should throw IllegalArgumentException if it doesn't know what to do" (try (do (text! (border-panel) "no") false) (catch IllegalArgumentException e true))) @@ -564,11 +578,11 @@ r (text! d "BYE!")] (expect (= d r)) (expect (= "BYE!" (text d))))) - (it "With nil input it should set the text of a text widget to \"\"" + (expect-it "With nil input it should set the text of a text widget to \"\"" (= "" (text (text! (text "HI") nil)))) - (it "should set the text of a single text widget argument" + (expect-it "should set the text of a single text widget argument" (= "BYE" (text (text! (text "HI") "BYE")))) - (it "should set the text of a single button argument" + (expect-it "should set the text of a single button argument" (= "BYE" (text (text! (button :text "HI") "BYE")))) (it "should set the text of a seq of widget arguments" (let [[a b] [(text "HI") (text "BYE")] @@ -576,29 +590,29 @@ (expect (= [a b] result)) (expect (= "YUM" (text a))) (expect (= "YUM" (text b))))) - (it "should set the text of a widget to an integer" + (expect-it "should set the text of a widget to an integer" (= "99" (text (text! (text "initial") 99)))) - (it "should set the text of a widget to a double" + (expect-it "should set the text of a widget to a double" (= (str 3.14) (text (text! (text "initial") 3.14)))) - (it "should set the text of a widget to a rational" + (expect-it "should set the text of a widget to a rational" (= (str 1/3) (text (text! (text "initial") 1/3)))) (it "should set the text of a widget to the contents of a non-string 'slurpable'" (let [t (text :multi-line? true)] - (text! t (clojure.java.io/resource "seesaw/test/core.text.txt")) + (text! t (io/resource "seesaw/test/core.text.txt")) ; Be careful editing the test file with vim. It will silently add ; a trailing newline on save. (expect (= "Some text in a resource" (text t)))))) -(describe text - (it "should throw IllegalArgumentException if argument is nil" +(defdescribe text-test + (expect-it "should throw IllegalArgumentException if argument is nil" (try (do (text nil) false) (catch IllegalArgumentException e true))) - (it "should throw IllegalArgumentException if it doesn't know what to do" + (expect-it "should throw IllegalArgumentException if it doesn't know what to do" (try (do (text (border-panel)) false) (catch IllegalArgumentException e true))) - (it "should return the text of a single text widget argument" + (expect-it "should return the text of a single text widget argument" (= "HI" (text (text "HI")))) (it "should return the text of the selection in a combobox" (let [cb (combobox :model ["a" "b"])] @@ -614,11 +628,11 @@ javax.swing.event.DocumentEvent$EventType/CHANGE)] (.insertString doc 0 "Hello" nil) (expect (= "Hello" (text evt))))) - (it "should return the text of a button argument" + (expect-it "should return the text of a button argument" (= "HI" (text (button :text "HI")))) - (it "should return the text of a label argument" + (expect-it "should return the text of a label argument" (= "HI" (text (label "HI")))) - (it "should return the text of a seq of widget arguments" + (expect-it "should return the text of a seq of widget arguments" (= ["HI" "BYE"] (text [(text "HI") (button :text "BYE")]))) (it "should create a text field given a string argument" (let [t (text "HI")] @@ -638,25 +652,25 @@ (it "should create a text area with the given :columns" (let [t (text :text "HI" :multi-line? true :columns 91)] (expect (= 91 (.getColumns t))))) - (it "should default line wrapping to false" + (expect-it "should default line wrapping to false" (not (.getLineWrap (text :multi-line? true)))) (it "should enable line wrapping on words when :wrap-lines? is true" (let [t (text :multi-line? true :wrap-lines? true)] (expect (.getLineWrap t)) (expect (.getWrapStyleWord t)))) (verify-config (text :multi-line? true :wrap-lines? true) :wrap-lines? true) - (it "should set tab size with :tab-size" + (expect-it "should set tab size with :tab-size" (= 22 (.getTabSize (text :multi-line? true :tab-size 22)))) - (it "should set number of rows with :rows" + (expect-it "should set number of rows with :rows" (= 123 (.getRows (text :multi-line? true :rows 123)))) (verify-config (text :text "hello there" :caret-position 5) :caret-position 5) - (it "should set the :caret-color" + (expect-it "should set the :caret-color" (= Color/ORANGE (.getCaretColor (text :caret-color Color/ORANGE)))) - (it "should set the :disabled-text-color" + (expect-it "should set the :disabled-text-color" (= Color/ORANGE (.getDisabledTextColor (text :disabled-text-color Color/ORANGE)))) - (it "should set the :selected-text-color" + (expect-it "should set the :selected-text-color" (= Color/ORANGE (.getSelectedTextColor (text :selected-text-color Color/ORANGE)))) - (it "should set the :selection-color" + (expect-it "should set the :selection-color" (= Color/ORANGE (.getSelectionColor (text :selection-color Color/ORANGE)))) (it "should handle the :margin option with to-insets" (let [t (text :margin 1) @@ -666,7 +680,7 @@ (let [t (text :text "HI" :editable? false :multi-line? true)] (expect (not (.isEditable t)))))) -(describe styled-text +(defdescribe styled-text-test (it "should create a text pane" (let [t (styled-text :text "HI")] (expect (instance? JTextPane t)) @@ -698,38 +712,38 @@ v (.getAttribute s StyleConstants/FontSize)] (expect (instance? Integer v)) (expect (= 30 v)))) - (it "should override getScrollableTracksViewportWidth with :wrap-lines?" + (expect-it "should override getScrollableTracksViewportWidth with :wrap-lines?" (not (.getScrollableTracksViewportWidth (styled-text)))) - (it "should override getScrollableTracksViewportWidth with :wrap-lines?" + (expect-it "should override getScrollableTracksViewportWidth with :wrap-lines?" (.getScrollableTracksViewportWidth (styled-text :wrap-lines? true)))) -(describe style-text! +(defdescribe style-text!-test (let [t (styled-text :text "HI" :styles [[:big :size 30] [:small :size 3]])] (it "should style the text" - (expect (= t (style-text! t :big 0 2))) - (expect (.containsAttribute (.getCharacterAttributes t) - StyleConstants/FontSize 30))))) + (expect (= t (style-text! t :big 0 2))) + (expect (.containsAttribute (.getCharacterAttributes t) + StyleConstants/FontSize (int 30)))))) -(describe password - (it "should create a JPasswordField" +(defdescribe password-test + (expect-it "should create a JPasswordField" (instance? javax.swing.JPasswordField (password))) - (it "should set the initial text" + (expect-it "should set the initial text" (= "secret" (text (password :text "secret")))) - (it "should set the columns" + (expect-it "should set the columns" (= 30 (.getColumns (password :columns 30)))) - (it "should set the echo char with a char" + (expect-it "should set the echo char with a char" (= \S (.getEchoChar (password :echo-char \S))))) -(describe with-password* +(defdescribe with-password*-test (it "should call the handler with the password in a character array" (let [s (atom nil) p (password :text "secret")] (with-password* p (fn [chars] (reset! s (apply str chars)))) (expect (= "secret" @s)))) - (it "should return the return value of the handler" + (expect-it "should return the return value of the handler" (= "HEY!" (with-password* (password) (fn [chars] "HEY!")))) (it "should fill the password character array with zeroes after then handler has completed" @@ -738,12 +752,12 @@ (with-password* p (fn [chars] (reset! s chars))) (expect (= [\0 \0 \0 \0 \0 \0] (vec @s)))))) -(describe editor-pane - (it "should create a JEditorPane" +(defdescribe editor-pane-test + (expect-it "should create a JEditorPane" (instance? javax.swing.JEditorPane (editor-pane)))) -(describe button-group - (it "should create a ButtonGroup" +(defdescribe button-group-test + (expect-it "should create a ButtonGroup" (instance? javax.swing.ButtonGroup (button-group))) (it "should create a button group with a list of buttons" (let [[a b c] [(radio) (checkbox) (toggle)] @@ -756,7 +770,7 @@ ;(expect (= [a b c] (enumeration-seq (.getElements bg)))) ))) -(describe button +(defdescribe button-test (it "should create a JButton" (let [b (button :text "HI")] (expect (instance? JButton b)) @@ -778,54 +792,54 @@ (expect (instance? JButton b)) (expect (= a (.getAction b))))) - (it "should set the :mnemonic of the button given an integer keycode" + (expect-it "should set the :mnemonic of the button given an integer keycode" (= 100 (.getMnemonic (button :mnemonic 100)))) - (it "should set the :mnemonic of the button given a char" + (expect-it "should set the :mnemonic of the button given a char" (= (int \Y) (.getMnemonic (button :mnemonic \Y)))) - (it "should set the :mnemonic of the button given a lower-case char" + (expect-it "should set the :mnemonic of the button given a lower-case char" (= (int \Z) (.getMnemonic (button :mnemonic \z))))) -(describe toggle +(defdescribe toggle-test (it "should create a JToggleButton" (let [t (toggle :text "HI")] (expect (instance? JToggleButton t)) - (expect (= "HI" (.getText t)))) - (expect (not (.isSelected t)))) + (expect (= "HI" (.getText t))) + (expect (not (.isSelected t))))) (it "should honor the :selected property" (let [t (toggle :text "HI" :selected? true)] (expect (.isSelected t))))) -(describe checkbox +(defdescribe checkbox-test (it "should create a JCheckBox" (let [t (checkbox :text "HI")] (expect (instance? JCheckBox t)) - (expect (= "HI" (.getText t)))) - (expect (not (.isSelected t)))) + (expect (= "HI" (.getText t))) + (expect (not (.isSelected t))))) (it "should honor the :selected property" (let [t (checkbox :text "HI" :selected? true)] (expect (.isSelected t))))) -(describe radio +(defdescribe radio-test (it "should create a JRadioButton" (let [t (radio :text "HI")] (expect (instance? JRadioButton t)) - (expect (= "HI" (.getText t)))) - (expect (not (.isSelected t)))) + (expect (= "HI" (.getText t))) + (expect (not (.isSelected t))))) (it "should honor the :selected property" (let [t (radio :text "HI" :selected? true)] (.isSelected t)))) -(describe listbox +(defdescribe listbox-test (verify-config (listbox :selection-mode :single) :selection-mode :single) (verify-config (listbox :layout-orientation :vertical) :layout-orientation :vertical) (verify-config (listbox :layout-orientation :horizontal-wrap) :layout-orientation :horizontal-wrap) (verify-config (listbox :layout-orientation :vertical-wrap) :layout-orientation :vertical-wrap) - (it "should create a JList" + (expect-it "should create a JList" (instance? javax.swing.JList (listbox))) - (it "should create a JList with :fixed-cell-height set" + (expect-it "should create a JList with :fixed-cell-height set" (= 98 (.getFixedCellHeight (listbox :fixed-cell-height 98)))) - (it "should create a JList and set the selection mode" - (expect (= javax.swing.ListSelectionModel/SINGLE_SELECTION (.getSelectionMode (listbox :selection-mode :single))))) + (expect-it "should create a JList and set the selection mode" + (= javax.swing.ListSelectionModel/SINGLE_SELECTION (.getSelectionMode (listbox :selection-mode :single)))) (it "should create a JList using a seq as its model" (let [lb (listbox :model [1 2 3 4]) model (.getModel lb)] @@ -837,14 +851,14 @@ (expect (= renderer (.getCellRenderer lb))) (expect (= renderer (config lb :renderer)))))) -(describe combobox +(defdescribe combobox-test (it "should create a JComboBox" (let [lb (combobox)] (instance? javax.swing.JComboBox lb))) - (testing "the :editable? property" - (it "should create a non-editable JComboBox when false" + (describe "the :editable? property" + (expect-it "should create a non-editable JComboBox when false" (not (.isEditable (combobox :editable? false)))) - (it "should create an editable JComboBox when true" + (expect-it "should create an editable JComboBox when true" (.isEditable (combobox :editable? true)))) (it "should set the combobox's cell renderer, if given" (let [render-fn (fn [renderer info] nil) @@ -858,7 +872,7 @@ (expect (= [1 2 3 4] (map #(.getElementAt model %1) (range (.getSize model))))) (expect (= 1 (.getSelectedItem model)))))) -(describe spinner-model +(defdescribe spinner-model-test (it "should create a number spinner model" (let [m (spinner-model 3.5 :from 1.5 :to 4.5 :by 0.5)] (expect (instance? javax.swing.SpinnerNumberModel m)) @@ -877,8 +891,8 @@ (expect (= s (.getStart m))) (expect (= e (.getEnd m)))))) -(describe spinner - (it "should create a JSpinner" +(defdescribe spinner-test + (expect-it "should create a JSpinner" (instance? javax.swing.JSpinner (spinner))) (it "should set the model with the :model option" (let [model (javax.swing.SpinnerListModel.) @@ -908,14 +922,14 @@ (expect @called))) ) -(describe table - (it "should create a JTable" +(defdescribe table-test + (expect-it "should create a JTable" (instance? javax.swing.JTable (table))) - (it "should create a JTable with :single selection-mode set" + (expect-it "should create a JTable with :single selection-mode set" (= javax.swing.ListSelectionModel/SINGLE_SELECTION (.. (table :selection-mode :single) getSelectionModel getSelectionMode))) - (it "should create a JTable with :multi-interval selection-mode set" + (expect-it "should create a JTable with :multi-interval selection-mode set" (= javax.swing.ListSelectionModel/MULTIPLE_INTERVAL_SELECTION (.. (table :selection-mode :multi-interval) getSelectionModel getSelectionMode))) - (it "should fill viewport height by default" + (expect-it "should fill viewport height by default" (.getFillsViewportHeight (table))) (it "should set the table's model from a TableModel" (let [m (javax.swing.table.DefaultTableModel.) @@ -934,19 +948,19 @@ (verify-config (table :show-vertical-lines? false) :show-vertical-lines? false) (verify-config (table :show-horizontal-lines? true) :show-horizontal-lines? true) (verify-config (table :show-horizontal-lines? false) :show-horizontal-lines? false) - (it "should honor :auto-resize :off" + (expect-it "should honor :auto-resize :off" (= javax.swing.JTable/AUTO_RESIZE_OFF (.getAutoResizeMode (table :auto-resize :off)))) - (it "should honor :auto-resize :next-column" + (expect-it "should honor :auto-resize :next-column" (= javax.swing.JTable/AUTO_RESIZE_NEXT_COLUMN (.getAutoResizeMode (table :auto-resize :next-column)))) - (it "should honor :auto-resize :subsequent-columns" + (expect-it "should honor :auto-resize :subsequent-columns" (= javax.swing.JTable/AUTO_RESIZE_SUBSEQUENT_COLUMNS (.getAutoResizeMode (table :auto-resize :subsequent-columns)))) - (it "should honor :auto-resize :last-column" + (expect-it "should honor :auto-resize :last-column" (= javax.swing.JTable/AUTO_RESIZE_LAST_COLUMN (.getAutoResizeMode (table :auto-resize :last-column)))) - (it "should honor :auto-resize :all-columns" + (expect-it "should honor :auto-resize :all-columns" (= javax.swing.JTable/AUTO_RESIZE_ALL_COLUMNS (.getAutoResizeMode (table :auto-resize :all-columns))))) -(describe tree - (it "should create a JTree" +(defdescribe tree-test + (expect-it "should create a JTree" (instance? javax.swing.JTree (tree))) (verify-config (tree :expands-selected-paths? true) :expands-selected-paths? true) (verify-config (tree :expands-selected-paths? false) :expands-selected-paths? false) @@ -958,35 +972,35 @@ (verify-config (tree :toggle-click-count 1) :toggle-click-count 1) (verify-config (tree :visible-row-count 20) :visible-row-count 20) (verify-config (tree :selection-mode :single) :selection-mode :single) - (it "should create a JTree with :root-visible? true" + (expect-it "should create a JTree with :root-visible? true" (.isRootVisible (tree :root-visible? true))) - (it "should create a JTree with :root-visible? false" + (expect-it "should create a JTree with :root-visible? false" (not (.isRootVisible (tree :root-visible? false)))) - (it "should create a JTree with :shows-root-handles? true" + (expect-it "should create a JTree with :shows-root-handles? true" (.getShowsRootHandles (tree :shows-root-handles? true))) - (it "should create a JTree with :shows-root-handles? false" + (expect-it "should create a JTree with :shows-root-handles? false" (not (.getShowsRootHandles (tree :shows-root-handles? false)))) - (it "should create a JTree with :single selection-mode set" + (expect-it "should create a JTree with :single selection-mode set" (= javax.swing.tree.TreeSelectionModel/SINGLE_TREE_SELECTION (.. (tree :selection-mode :single) getSelectionModel getSelectionMode))) - (it "should create a JTree with :discontiguous selection-mode set" + (expect-it "should create a JTree with :discontiguous selection-mode set" (= javax.swing.tree.TreeSelectionModel/DISCONTIGUOUS_TREE_SELECTION (.. (tree :selection-mode :discontiguous) getSelectionModel getSelectionMode))) - (it "should create a JTree with :contiguous selection-mode set" + (expect-it "should create a JTree with :contiguous selection-mode set" (= javax.swing.tree.TreeSelectionModel/CONTIGUOUS_TREE_SELECTION (.. (tree :selection-mode :contiguous) getSelectionModel getSelectionMode))) (it "should set the tree's model from a TreeModel" (let [m (javax.swing.tree.DefaultTreeModel. nil) t (tree :model m)] (= m (.getModel t))))) -(describe scrollable +(defdescribe scrollable-test (it "should create a JScrollPane" (let [l (label :text "Test") s (scrollable l)] (expect (instance? JScrollPane s)) (expect (= l (.. s getViewport getView))))) - (it "should create a scroll pane with horizontal policy" - (expect (= ScrollPaneConstants/HORIZONTAL_SCROLLBAR_NEVER (.getHorizontalScrollBarPolicy (scrollable (text) :hscroll :never))))) - (it "should create a scroll pane with vertical policy" - (expect (= ScrollPaneConstants/VERTICAL_SCROLLBAR_NEVER (.getVerticalScrollBarPolicy (scrollable (text) :vscroll :never))))) + (expect-it "should create a scroll pane with horizontal policy" + (= ScrollPaneConstants/HORIZONTAL_SCROLLBAR_NEVER (.getHorizontalScrollBarPolicy (scrollable (text) :hscroll :never)))) + (expect-it "should create a scroll pane with vertical policy" + (= ScrollPaneConstants/VERTICAL_SCROLLBAR_NEVER (.getVerticalScrollBarPolicy (scrollable (text) :vscroll :never)))) (it "should create a JScrollPane with a :row-header-view" (let [hv (label) s (scrollable (button) :row-header hv)] @@ -1007,7 +1021,7 @@ s (scrollable l :id "MY-ID")] (expect (= (keyword "MY-ID") (id-of s)))))) -(describe splitter +(defdescribe splitter-test (it "should create a JSplitPane with with two panes" (let [left (label :text "Left") right (label :text "Right") @@ -1023,24 +1037,24 @@ (let [s (splitter :top-bottom "top" "bottom" :divider-location 0.5)] ; We can't really test this since the expected divider location (in pixels) ; is pretty hard to predict and because of the JSplitPane visibility hack - ; that's required, it won't actually happen until it's displayed in a frame :( + ; that's required, expect-it won't actually happen until it's displayed in a frame :( (expect true))) (it "should set the divider location to a percentage location with a rational (eventually)" (let [s (splitter :top-bottom "top" "bottom" :divider-location 1/2)] ; We can't really test this since the expected divider location (in pixels) ; is pretty hard to predict and because of the JSplitPane visibility hack - ; that's required, it won't actually happen until it's displayed in a frame :( + ; that's required, expect-it won't actually happen until it's displayed in a frame :( (expect true))) - (it "should set the :divider-side" + (expect-it "should set the :divider-side" (= 93 (.getDividerSize (splitter :left-right (label) (label) :divider-size 93)))) - (it "should set the :resize-weight" + (expect-it "should set the :resize-weight" (= 0.75 (.getResizeWeight (splitter :left-right (label) (label) :resize-weight 0.75)))) - (it "should set :one-touch-expandable?" + (expect-it "should set :one-touch-expandable?" (.isOneTouchExpandable (splitter :left-right (label) (label) :one-touch-expandable? true)))) -(describe menu-item - (it "should create a JMenuItem" - (expect (instance? javax.swing.JMenuItem (menu-item)))) +(defdescribe menu-item-test + (expect-it "should create a JMenuItem" + (instance? javax.swing.JMenuItem (menu-item))) (it "should create a menu item with an accelerator key" (let [ks (seesaw.keystroke/keystroke "ctrl S") mi (menu-item :key ks)] @@ -1050,9 +1064,9 @@ mi (menu-item :action a)] (expect (= a (.getAction mi)))))) -(describe menu - (it "should create a JMenu" - (expect (instance? javax.swing.JMenu (menu)))) +(defdescribe menu-test + (expect-it "should create a JMenu" + (instance? javax.swing.JMenu (menu))) (it "should create a JMenu with the given items" (let [a (action) b :separator @@ -1065,9 +1079,9 @@ (expect (= c ic)) (expect (= "Just a string" (.getText id)))))) -(describe popup - (it "should create a JPopupMenu" - (expect (instance? javax.swing.JPopupMenu (popup)))) +(defdescribe popup-test + (expect-it "should create a JPopupMenu" + (instance? javax.swing.JPopupMenu (popup))) (it "should create a JPopupMenu with the given items" (let [a (action) b :separator @@ -1080,8 +1094,8 @@ (expect (= c ic)) (expect (= "Just a string" (.getText id)))))) -(describe menubar - (it "should create a JMenuBar" +(defdescribe menubar-test + (expect-it "should create a JMenuBar" (instance? javax.swing.JMenuBar (menubar))) (it "should create a JMenuBar with the given items" (let [a (menu) @@ -1089,7 +1103,7 @@ mb (menubar :items [a b])] (expect (= [a b] (vec (.getComponents mb))))))) -(describe toolbar +(defdescribe toolbar-test (it "should create a JToolBar with the given items" (let [tb (toolbar :items ["a" "b" "c"]) items (.getComponents tb)] @@ -1108,7 +1122,7 @@ (let [tb (toolbar :items [:separator])] (expect (instance? javax.swing.JToolBar$Separator (.getComponent tb 0)))))) -(describe separator +(defdescribe separator-test (it "should create a horizontal JSeparator by default" (let [s (separator)] (expect (instance? javax.swing.JSeparator s)) @@ -1122,7 +1136,7 @@ (expect (instance? javax.swing.JSeparator s)) (expect (= SwingConstants/VERTICAL (.getOrientation s)))))) -(describe tabbed-panel +(defdescribe tabbed-panel-test (it "should create a JTabbedPane with desired tab placement and layout" (let [tp (tabbed-panel :placement :bottom :overflow :wrap)] (expect (instance? JTabbedPane tp)) @@ -1137,7 +1151,7 @@ (expect (= ["tip A" "tip B"] [(.getToolTipTextAt tp 0) (.getToolTipTextAt tp 1)])) (expect (= [a b] [(.getComponentAt tp 0) (.getComponentAt tp 1)]))))) -(describe canvas +(defdescribe canvas-test (it "should create a subclass of JPanel with no layout manager" (let [c (canvas)] (expect (instance? JPanel c)) @@ -1156,12 +1170,12 @@ (.paintComponent c (.getGraphics (buffered-image 100 100))) ; fake with buffered image (expect (= 1 @called))))) -(describe window - (it "should create a jwindow" +(defdescribe window-test + (expect-it "should create a jwindow" (instance? javax.swing.JWindow (window))) - (it "should create a window with an id" + (expect-it "should create a window with an id" (= :my-frame (id-of (window :id :my-frame)))) - (it "should create a window with 0 width and height" + (expect-it "should create a window with 0 width and height" (= (java.awt.Dimension. 0 0) (.getSize (window)))) (it "should create a window and set its title, width, and height" (let [f (window :width 99 :height 88)] @@ -1176,10 +1190,10 @@ f (window :content c)] (expect (= c (.getContentPane f)))))) -(describe frame - (it "should create a frame with an id" +(defdescribe frame-test + (expect-it "should create a frame with an id" (= :my-frame (id-of (frame :id :my-frame)))) - (it "should create a frame with 0 width and height" + (expect-it "should create a frame with 0 width and height" (= (java.awt.Dimension. 0 0) (.getSize (frame)))) (it "should create a JFrame and set its title, width, and height" (let [f (frame :title "Hello" :width 99 :height 88)] @@ -1214,10 +1228,10 @@ (let [i (buffered-image 16 16) f (frame :icon i)] (expect (= i (.getIconImage f))))) - (it "should, by default, set location by platform to true" + (expect-it "should, by default, set location by platform to true" (.isLocationByPlatform (frame)))) -(describe to-root +(defdescribe to-root-test (it "should convert a widget to its parent applet" (let [c (label :text "HI") a (javax.swing.JApplet.)] @@ -1232,8 +1246,8 @@ (let [c (label :text "HI")] (expect (nil? (to-root c)))))) -(describe to-frame - (it "should be an alias for to-root" +(defdescribe to-frame-test + (expect-it "should be an alias for to-root" (= to-frame to-root))) (letfn [(test-dlg-blocking @@ -1249,8 +1263,8 @@ @v))] (describe custom-dialog - (testing "argument passing" - (it "should create a dialog with an id" + (describe "argument passing" + (expect-it "should create a dialog with an id" (= :my-dialog (id-of (custom-dialog :id :my-dialog)))) (it "should create a JDialog and set its title, width, and height" (let [f (custom-dialog :title "Hello" :width 99 :height 88)] @@ -1276,7 +1290,7 @@ (let [c (label :text "HI") f (custom-dialog :content c)] (expect (= c (.getContentPane f)))))) - (testing "blocking" + (describe "blocking" (it "should block until dialog is being disposed of" (let [dlg (custom-dialog :content "Nothing" :modal? true)] (expect (= (test-dlg-blocking dlg) 'dialog-is-blocking)))) @@ -1299,28 +1313,28 @@ (it "should not block" (let [dlg (dialog :content "Nothing" :modal? false)] (expect (= (test-dlg-blocking dlg) dlg)))) - (testing "return-from-dialog" + (describe "return-from-dialog" (let [ok (make-widget (action :name "Ok" :handler (fn [e] (return-from-dialog e :ok)))) cancel (make-widget (action :name "Cancel" :handler (fn [e] (return-from-dialog e :cancel)))) dlg (dialog :content "Nothing" :options (map make-widget [ok cancel]))] - (it "should return value passed to RETURN-FROM-DIALOG from clicking on ok button" - (expect (= (test-dlg-blocking - dlg - :future-fn #(do - (Thread/sleep 90) - (invoke-now (.doClick ok)) - (Thread/sleep 50))) :ok))) - (it "should return value passed to RETURN-FROM-DIALOG from clicking on cancel button" - (expect (= (test-dlg-blocking - dlg - :future-fn #(do - (Thread/sleep 90) - (invoke-now (.doClick cancel)) - (Thread/sleep 50))) :cancel))))))) - - -(describe slider + (expect-it "should return value passed to RETURN-FROM-DIALOG from clicking on ok button" + (= (test-dlg-blocking + dlg + :future-fn #(do + (Thread/sleep 90) + (invoke-now (.doClick ok)) + (Thread/sleep 50))) :ok)) + (expect-it "should return value passed to RETURN-FROM-DIALOG from clicking on cancel button" + (= (test-dlg-blocking + dlg + :future-fn #(do + (Thread/sleep 90) + (invoke-now (.doClick cancel)) + (Thread/sleep 50))) :cancel)))))) + + +(defdescribe slider-test (it "should create a slider with a min, max, and value" (let [s (slider :min 40 :max 99 :value 55)] (expect (instance? javax.swing.JSlider s)) @@ -1344,20 +1358,20 @@ (verify-config (slider :inverted? true) :inverted? true) (verify-config (slider :inverted? false) :inverted? false)) -(describe progress-bar - (it "should create a JProgressBar" - (expect (instance? javax.swing.JProgressBar (progress-bar)))) +(defdescribe progress-bar-test + (expect-it "should create a JProgressBar" + (instance? javax.swing.JProgressBar (progress-bar))) (it "should set the progress bars min, max and initial value" (let [pb (progress-bar :value 5 :min 1 :max 6)] (expect (= 5 (.getValue pb))) (expect (= 1 (.getMinimum pb))) (expect (= 6 (.getMaximum pb)))))) -(describe select - (it "should throw an exception if selector is not a vector" +(defdescribe select-test + (expect-it "should throw an exception if selector is not a vector" (try (do (select nil 99) false) (catch IllegalArgumentException e true))) - (testing "when performing an #id query" + (describe "when performing an #id query" (it "should return a single widget" (let [f (frame :id :my-frame)] (expect (= f (select f [:#my-frame]))))) @@ -1369,7 +1383,7 @@ (expect (= c (select f [:#hi]))) (expect (= p (select f ["#panel"]))))))) -(describe select-with +(defdescribe select-with-test (it "should return the equivalent of (partial select widget)" (let [lbl (label :id :foo) p (border-panel :center lbl) @@ -1380,7 +1394,7 @@ $ (select-with p)] (expect (= p (to-widget $)))))) -(describe group-by-id +(defdescribe group-by-id-test (it "should return a map of widgets, keyed by id" (let [a (label :id :a) b (button :id :b) @@ -1391,7 +1405,7 @@ result (group-by-id f)] (expect (= result {:a a :b b :d d :f f}))))) -(describe with-widgets +(defdescribe with-widgets-test (it "should create a binding for the :id of each new widget" (let [a-value 99 b-value 100 @@ -1402,7 +1416,7 @@ (expect (= a [:id :a :value a-value])) (expect (= b [:id :b :value b-value])) (expect (= c [:value c-value :id :c]))))) - (it "should throw IllegalArgumentException for a missing :id" + (expect-it "should throw IllegalArgumentException for a missing :id" (try (eval `(with-widgets [(vector :value 99)])) false (catch IllegalArgumentException e true) @@ -1410,8 +1424,8 @@ (catch Exception e (instance? IllegalArgumentException (root-cause e)))))) -(describe add! - (testing "When called on a panel with a FlowLayout" +(defdescribe add!-test + (describe "When called on a panel with a FlowLayout" (it "adds a widget to the end of the panel" (let [p (flow-panel) l (label) @@ -1427,7 +1441,7 @@ (expect (= label0 (first (.getComponents p)))) (expect (= label1 (second (.getComponents p))))))) - (testing "When called on a panel with a BoxLayout" + (describe "When called on a panel with a BoxLayout" (it "adds a widget to the end of the panel" (let [p (vertical-panel) l (label) @@ -1435,7 +1449,7 @@ (expect (= result p)) (expect (= l (first (.getComponents p))))))) - (testing "When called on a panel with a BorderLayout" + (describe "When called on a panel with a BorderLayout" (it "adds a widget at the given location" (let [p (border-panel) l (label) @@ -1443,7 +1457,7 @@ (expect (= result p)) (expect (= BorderLayout/NORTH (.getConstraints (.getLayout p) l))))))) -(describe remove! +(defdescribe remove!-test (it "removes widgets from a container" (let [l0 (label) l1 (label) p (border-panel :north l0 :south l1) @@ -1451,8 +1465,8 @@ (expect (= p result)) (expect (= 0 (count (.getComponents p))))))) -(describe replace! - (testing "when called on a panel with a generic layout (e.g. flow)" +(defdescribe replace!-test + (describe "when called on a panel with a generic layout (e.g. flow)" (it "replaces the given widget with a new widget" (let [l0 (label "l0") l1 (label "l1") @@ -1461,7 +1475,7 @@ result (replace! p l1 l2)] (expect (= p result)) (expect (= [l0 l2] (vec (.getComponents p))))))) - (testing "when called on a panel with a border layout" + (describe "when called on a panel with a border layout" (it "replaces the given widget with a new widget and maintains constraints" (let [l0 (label "l0") l1 (label "l1") @@ -1472,14 +1486,14 @@ (expect (= [l0 l2] (vec (.getComponents p)))) (expect (= BorderLayout/SOUTH (-> p .getLayout (.getConstraints l2)))))))) -(describe selection +(defdescribe selection-test (it "should get the selection from a button-group" (let [a (radio) b (radio :selected? true) bg (button-group :buttons [a b])] (expect (= b (selection bg)))))) -(describe selection! +(defdescribe selection!-test (it "should set the selection of a button-group" (let [a (radio) b (radio) @@ -1488,7 +1502,7 @@ (selection! bg b) (expect (= b (selection bg)))))) -(describe dispose! +(defdescribe dispose!-test (it "should dispose of a JFrame" (let [f (pack! (frame :title "dispose!"))] (expect (.isDisplayable f)) @@ -1502,15 +1516,15 @@ (expect (= result f)) (expect (not (.isDisplayable f))))))) -(describe assert-ui-thread +(defdescribe assert-ui-thread-test ; TODO test non-exception case - (it "should throw an IllegalStateException if not called on the Swing UI thread" + (expect-it "should throw an IllegalStateException if not called on the Swing UI thread" @(future (try (do (assert-ui-thread "some message") false) (catch IllegalStateException e true))))) -(describe move! +(defdescribe move!-test (it "should move the widget to the back of the z order" (let [a (label) b (label) @@ -1571,7 +1585,7 @@ (expect (= :test (id-of p#))) (expect (= p# (config! p# :paint (fn [~'g ~'c] nil))))))) -(describe paintable +(defdescribe paintable-test ; exercise paintable on all the widget types (test-paintable flow-panel javax.swing.JPanel) (test-paintable label javax.swing.JLabel) @@ -1605,18 +1619,18 @@ (expect (instance? javax.swing.JLabel lbl)) (expect (= :foo (id-of lbl))))) - (it "creates a button subclass" + (expect-it "creates a button subclass" (instance? javax.swing.JButton (paintable javax.swing.JButton :paint nil)))) -(describe width - (it "returns the width of a widget" +(defdescribe width-test + (expect-it "returns the width of a widget" (= 100 (width (xyz-panel :bounds [0 0 100 101]))))) -(describe height - (it "returns the height of a widget" +(defdescribe height-test + (expect-it "returns the height of a widget" (= 101 (height (xyz-panel :bounds [0 0 100 101]))))) -(describe card-panel +(defdescribe card-panel-test (it "creates a panel with a CardLayout" (let [p (card-panel :hgap 4 :vgap 3 :items [["Label" :first] [(button) :second]])] (expect (instance? javax.swing.JPanel p)) @@ -1635,7 +1649,7 @@ (show-card! p "b") (expect (visible? b))))) -(describe show-card! +(defdescribe show-card!-test (it "sets the visible card in a card panel" (let [a (label) b (button) diff --git a/test/seesaw/test/cursor.clj b/test/seesaw/test/cursor.clj index c4f7988b..9fe300b4 100644 --- a/test/seesaw/test/cursor.clj +++ b/test/seesaw/test/cursor.clj @@ -9,19 +9,20 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.cursor - (:use seesaw.cursor) - (:use seesaw.graphics) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)]) - (:import [java.awt Cursor])) + (:require + [lazytest.core :refer [defdescribe describe expect it]] + [seesaw.cursor :refer :all] + [seesaw.graphics :refer :all]) + (:import + [java.awt Cursor])) (defmacro test-built-ins [] - `(testing "creating a built-in cursor" + `(describe "creating a built-in cursor" ~@(for [[key value] (dissoc @#'seesaw.cursor/built-in-cursor-map :custom)] `(it ~(str "should create a " key " cursor") (expect (= ~value (-> (cursor ~key) (.getType)))))))) -(describe cursor +(defdescribe cursor-test (test-built-ins) (it "should return its input if given a cursor" (let [c (cursor :hand)] @@ -30,15 +31,14 @@ (let [img (buffered-image 16 16) cur (cursor img)] ; Can't actually test that the image was set - (= (Cursor/CUSTOM_CURSOR) (.getType cur)))) + (expect (= (Cursor/CUSTOM_CURSOR) (.getType cur))))) (it "should create a custom cursor from an image with an [x y] hotspot" (let [img (buffered-image 16 16) cur (cursor img [5 5])] ; Can't actually test that the hotspot was set - (= (Cursor/CUSTOM_CURSOR) (.getType cur)))) + (expect (= (Cursor/CUSTOM_CURSOR) (.getType cur))))) (it "should create a custom cursor from an icon with an [x y] hotspot" (let [icon (javax.swing.ImageIcon. (buffered-image 16 16)) cur (cursor icon [5 5])] ; Can't actually test that the hotspot was set - (= (Cursor/CUSTOM_CURSOR) (.getType cur))))) - + (expect (= (Cursor/CUSTOM_CURSOR) (.getType cur)))))) diff --git a/test/seesaw/test/dnd.clj b/test/seesaw/test/dnd.clj index 5ea162e6..3cb07f3a 100644 --- a/test/seesaw/test/dnd.clj +++ b/test/seesaw/test/dnd.clj @@ -9,15 +9,15 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.dnd - (:use seesaw.dnd) - (:use [seesaw.graphics] - [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)]) - (:import [java.awt.datatransfer DataFlavor StringSelection - UnsupportedFlavorException] - [javax.swing TransferHandler])) + (:require + [lazytest.core :refer [defdescribe describe expect expect-it it]] + [seesaw.dnd :refer :all] + [seesaw.graphics :refer :all]) + (:import + [java.awt.datatransfer DataFlavor StringSelection UnsupportedFlavorException] + [javax.swing TransferHandler])) -(describe local-object-flavor +(defdescribe local-object-flavor-test (it "creates a JVM local flavor for an arbitrary class" (let [c (class []) f (local-object-flavor c)] @@ -25,18 +25,18 @@ (it "creates a JVM local flavor for an arbitrary value" (= (local-object-flavor (class [])) (local-object-flavor [])))) -(describe uri-list-flavor +(defdescribe uri-list-flavor-test (it "implements to-remote to convert list of URIs to uri-list" (= "http://google.com\r\nhttp://github.com" - (to-remote uri-list-flavor - [(java.net.URI. "http://google.com") - (java.net.URI. "http://github.com")]))) + (to-remote uri-list-flavor + [(java.net.URI. "http://google.com") + (java.net.URI. "http://github.com")]))) (it "implements to-local to convert uri-list to list of URIs" (= [(java.net.URI. "http://google.com") (java.net.URI. "http://github.com")] - (to-local uri-list-flavor "http://google.com\r\nhttp://github.com" )))) + (to-local uri-list-flavor "http://google.com\r\nhttp://github.com" )))) -(describe default-transferable - (testing "resulting transferable" +(defdescribe default-transferable-test + (describe "resulting transferable" (it "can hold an arbitrary object" (let [o ["hi"] t (default-transferable [string-flavor o])] @@ -48,8 +48,8 @@ (expect (= 99 (.getTransferData t (to-raw-flavor (local-object-flavor Integer))))))) (it "throws UnsupportedFlavorException correctly" (let [t (default-transferable [string-flavor "hi"])] - (try (.getTransferData t (to-raw-flavor file-list-flavor)) false - (catch UnsupportedFlavorException e true)))) + (expect (try (.getTransferData t (to-raw-flavor file-list-flavor)) false + (catch UnsupportedFlavorException e true))))) (it "implements (getTransferDataFlavors)" (let [t (default-transferable [(local-object-flavor []) []]) flavors (.getTransferDataFlavors t)] @@ -62,44 +62,42 @@ (defn fake-transfer-support [t] (javax.swing.TransferHandler$TransferSupport. (javax.swing.JLabel.) t)) -(describe default-transfer-handler - (testing "(default-transfer-handler)" - (it "creates a transfer handler" - (instance? javax.swing.TransferHandler (default-transfer-handler))) - (it "throws an ex-info if there is a handler-map without an on-drop key" - (try - (default-transfer-handler :import [string-flavor {}]) false - (catch clojure.lang.ExceptionInfo e true)))) +(defdescribe default-transfer-handler-test + (describe "(default-transfer-handler)" + (it "creates a transfer handler" + (instance? javax.swing.TransferHandler (default-transfer-handler))) + (expect-it "throws an ex-info if there is a handler-map without an on-drop key" + (try + (default-transfer-handler :import [string-flavor {}]) false + (catch clojure.lang.ExceptionInfo e true)))) - (testing "(canImport)" - (it "returns false if the :import map is missing or empty" + (describe "(canImport)" + (expect-it "returns false if the :import map is missing or empty" (not (.canImport (default-transfer-handler) (fake-transfer-support (StringSelection. "hi"))))) (it "only accepts flavors in the keys of the :import map" (let [th (default-transfer-handler :import [string-flavor (fn [info])])] (expect (.canImport th (fake-transfer-support (StringSelection. "hi")))) (expect (not (.canImport th (fake-transfer-support (default-transferable []))))))) - + (let [transfer-handler (default-transfer-handler :import [string-flavor {:on-drop (fn [info]) :can-drop? (fn [info] (= info "should match"))}])] - (testing ":can-drop?" - (it "returns false if the import handler is a map and :can-drop? returns false" - (not (.canImport transfer-handler - (fake-transfer-support (StringSelection. "should not match"))))) - - (it "returns true if the import handler is a map and :can-drop? returns true" - (.canImport transfer-handler - (fake-transfer-support (StringSelection. "should match")))) - - (let [transfer-handler (default-transfer-handler - :import [string-flavor {:on-drop (fn [info])}])] - (it "returns true if the import handler is a map and :can-drop? is not given" - (.canImport transfer-handler - (fake-transfer-support (StringSelection. "should match")))))))) + (describe ":can-drop?" + (expect-it "returns false if the import handler is a map and :can-drop? returns false" + (not (.canImport transfer-handler + (fake-transfer-support (StringSelection. "should not match"))))) + (expect-it "returns true if the import handler is a map and :can-drop? returns true" + (.canImport transfer-handler + (fake-transfer-support (StringSelection. "should match")))) + (let [transfer-handler (default-transfer-handler + :import [string-flavor {:on-drop (fn [info])}])] + (expect-it "returns true if the import handler is a map and :can-drop? is not given" + (.canImport transfer-handler + (fake-transfer-support (StringSelection. "should match")))))))) - (testing "(importData)" + (describe "(importData)" (it "returns false immediately if (canImport) returns false" (let [called (atom false) th (default-transfer-handler :import [string-flavor (fn [info] (reset! called true))])] @@ -117,14 +115,14 @@ :target (.getComponent support) :support support}))))) - (testing "(createTransferable)" + (describe "(createTransferable)" (it "returns a transferable given :import/:start " (let [c (javax.swing.JTextField. "some text") th (default-transfer-handler :export { :start (fn [c] [string-flavor (.getText c)]) }) trans (.createTransferable th c)] (expect (= "some text" (.getTransferData trans (to-raw-flavor string-flavor))))))) - (testing "(getSourceActions)" + (describe "(getSourceActions)" (it "returns :none if :export is omitted" (let [c (javax.swing.JTextField. "some text") th (default-transfer-handler) @@ -145,7 +143,7 @@ th (default-transfer-handler :export { :actions (fn [c] :link) }) actions (.getSourceActions th c)] (expect (= TransferHandler/LINK actions))))) - (testing "(exportDone)" + (describe "(exportDone)" (it "returns false if :export is omitted" (let [th (default-transfer-handler)] (expect (not (.exportDone th nil nil TransferHandler/MOVE))))) @@ -159,5 +157,3 @@ th (default-transfer-handler :export { :finish (fn [v] (reset! called v) true) })] (.exportDone th source tr TransferHandler/MOVE) (expect (= {:source source :data tr :action :move} @called)))))) - - diff --git a/test/seesaw/test/event.clj b/test/seesaw/test/event.clj index 070bd738..6b313e01 100644 --- a/test/seesaw/test/event.clj +++ b/test/seesaw/test/event.clj @@ -9,11 +9,10 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.event - (:use seesaw.event - [seesaw.util :only [root-cause]]) - (:require [seesaw.core :as sc]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)]) + (:require [seesaw.event :refer :all] + [seesaw.util :refer [root-cause]] + [seesaw.core :as sc] + [lazytest.core :refer [defdescribe describe expect expect-it it]]) (:import [javax.swing JPanel JTextField JButton JRadioButton JToggleButton] [javax.swing.event ChangeListener] [java.awt.event ComponentListener ItemListener MouseListener MouseMotionListener])) @@ -39,7 +38,7 @@ [listener-type & args] (every? true? (map (fn [[hk df]] (verify-listener listener-type hk df)) (partition 2 args)))) -(describe append-listener +(defdescribe append-listener-test (it "inserts necessary keys and creates an initial list" (let [listener #(println %)] (expect (= {:test-key [listener]} (append-listener {} :test-key listener))))) @@ -48,47 +47,47 @@ (expect (= {:test-key [:dummy listener]} (append-listener {:test-key [:dummy]} :test-key listener)))))) -(describe unappend-listener +(defdescribe unappend-listener-test (it "can remove a listener" (let [initial {:list-key [:a :b :c]} result (unappend-listener initial :list-key :b)] (expect (= {:list-key [:a :c]} result))))) -(describe reify-listener - (testing "for ComponentListener" - (it "instantiates a ComponentListener instance" +(defdescribe reify-listener-test + (describe "for ComponentListener" + (expect-it "instantiates a ComponentListener instance" (instance? ComponentListener (reify-listener ComponentListener (ref {})))) - (it "makes an instance that does nothing when there's no handler" + (expect-it "makes an instance that does nothing when there's no handler" (verify-empty-listener ComponentListener :component-resized #(.componentResized % nil))) - (it "makes an instance that calls expected methods" + (expect-it "makes an instance that calls expected methods" (verify-listeners ComponentListener :component-hidden #(.componentHidden % nil) :component-moved #(.componentMoved % nil) :component-resized #(.componentResized % nil) :component-shown #(.componentShown % nil)))) - (testing "for ChangeListener" - (it "instantiates a ChangeListener instance" + (describe "for ChangeListener" + (expect-it "instantiates a ChangeListener instance" (instance? ChangeListener (reify-listener ChangeListener (ref {})))) - (it "makes an instance that does nothing when there's no handler" + (expect-it "makes an instance that does nothing when there's no handler" (verify-empty-listener ChangeListener :state-changed #(.stateChanged % nil))) - (it "makes an instance that calls :state-changed" + (expect-it "makes an instance that calls :state-changed" (verify-listener ChangeListener :state-changed #(.stateChanged % nil)))) - (testing "for ItemListener" - (it "instantiates an ItemListener instance" + (describe "for ItemListener" + (expect-it "instantiates an ItemListener instance" (instance? ItemListener (reify-listener ItemListener (ref {})))) - (it "makes an instance that does nothing when there's no handler" + (expect-it "makes an instance that does nothing when there's no handler" (verify-empty-listener ItemListener :item-state-changed #(.itemStateChanged % nil))) - (it "makes an instance that calls :item-state-changed" + (expect-it "makes an instance that calls :item-state-changed" (verify-listener ItemListener :item-state-changed #(.itemStateChanged % nil)))) - (testing "for MouseListener" - (it "instantiates an MouseListener instance" + (describe "for MouseListener" + (expect-it "instantiates an MouseListener instance" (instance? MouseListener (reify-listener MouseListener (ref {})))) - (it "makes an instance that does nothing when there's no handlers" + (expect-it "makes an instance that does nothing when there's no handlers" (verify-empty-listener MouseListener :mouse-clicked #(.mouseClicked % nil))) - (it "makes an instance that calls expected methods" + (expect-it "makes an instance that calls expected methods" (verify-listeners MouseListener :mouse-clicked #(.mouseClicked % nil) :mouse-entered #(.mouseEntered % nil) @@ -96,19 +95,19 @@ :mouse-pressed #(.mousePressed % nil) :mouse-released #(.mouseReleased % nil)))) - (testing "for MouseMotionListener" - (it "instantiates an MouseMotionListener instance" + (describe "for MouseMotionListener" + (expect-it "instantiates an MouseMotionListener instance" (instance? MouseMotionListener (reify-listener MouseMotionListener (ref {})))) - (it "makes an instance that does nothing when there's no handlers" + (expect-it "makes an instance that does nothing when there's no handlers" (verify-empty-listener MouseMotionListener :mouse-moved #(.mouseMoved % nil))) - (it "makes an instance that calls expected methods" + (expect-it "makes an instance that calls expected methods" (verify-listeners MouseMotionListener :mouse-moved #(.mouseMoved % nil) :mouse-dragged #(.mouseDragged % nil))))) -(describe listen - (it "throws IllegalArgumentException if its event/handler pair list isn't even length" +(defdescribe listen-test + (expect-it "throws IllegalArgumentException if its event/handler pair list isn't even length" (try (listen :something-something (fn [_])) false @@ -116,7 +115,7 @@ true) (catch RuntimeException e (instance? IllegalArgumentException (root-cause e))))) - (it "throws IllegalArgumentException if its first arguments isn't an event source" + (expect-it "throws IllegalArgumentException if its first arguments isn't an event source" (try (listen :something-something (fn [_]) :another) false @@ -125,7 +124,7 @@ ; TODO 1.2 event wrapping (catch RuntimeException e (instance? IllegalArgumentException (root-cause e))))) - (it "throws IllegalArgumentException if a handler isn't a function or var" + (expect-it "throws IllegalArgumentException if a handler isn't a function or var" (try (listen (javax.swing.JPanel.) :mouse "foo") false @@ -134,7 +133,7 @@ ; TODO 1.2 event wrapping (catch RuntimeException e (instance? IllegalArgumentException (root-cause e))))) - (it "throws IllegalArgumentException for unknown event types" + (expect-it "throws IllegalArgumentException for unknown event types" (try (listen (JPanel.) :something-something (fn [_])) false @@ -360,7 +359,7 @@ (.. (first (.getActionListeners mi)) (actionPerformed nil)) (expect @called))))) -(describe listen-to-property +(defdescribe listen-to-property-test (it "registers a property change listener" (let [b (javax.swing.JButton.) called (atom nil) @@ -372,4 +371,3 @@ (remove-fn) (.setText b "BYE") (expect (nil? @called))))) - diff --git a/test/seesaw/test/examples/behave.clj b/test/seesaw/test/examples/behave.clj index 2d49d5b4..9d7cd897 100644 --- a/test/seesaw/test/examples/behave.clj +++ b/test/seesaw/test/examples/behave.clj @@ -8,9 +8,11 @@ ; the terms of this license. ; You must not remove this notice, or any other, from this software. -(ns seesaw.test.examples.behave - (:use [seesaw core behave] - seesaw.test.examples.example)) +(ns seesaw.test.examples.behave + (:require + [seesaw.behave :refer [when-focused-select-all]] + [seesaw.core :refer [combobox frame text vertical-panel]] + [seesaw.test.examples.example :refer [defexample]])) ; Examples of stuff in (seesaw.behave). @@ -26,7 +28,7 @@ (combobox :editable? true :model ["Same here. Hit tab!" "First" "Second" "Third"]) when-focused-select-all)])) -(defexample [] +(defexample run [] (frame :title "seesaw.behave examples" :content (focus-select))) ;(run :dispose) diff --git a/test/seesaw/test/examples/bind.clj b/test/seesaw/test/examples/bind.clj index a3e48e5a..4599c208 100644 --- a/test/seesaw/test/examples/bind.clj +++ b/test/seesaw/test/examples/bind.clj @@ -9,9 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.bind - (:use [seesaw core border] - seesaw.test.examples.example) - (:require [seesaw.bind :as b])) + (:require + [seesaw.bind :as b] + [seesaw.border :refer [line-border]] + [seesaw.core :refer [border-panel checkbox frame label select text]] + [seesaw.test.examples.example :refer [defexample]])) (defn regex-box [& opts] (let [pattern (text :id :search :columns 20 :border [5 (line-border)]) @@ -37,8 +39,7 @@ :center pattern :south status :vgap 5 :border 5))) -(defexample [] - +(defexample run [] (let [f (frame :title "Seesaw (bind) example" :content (border-panel :north (checkbox :id :enable diff --git a/test/seesaw/test/examples/button_group.clj b/test/seesaw/test/examples/button_group.clj index 35c67285..dd0620a8 100644 --- a/test/seesaw/test/examples/button_group.clj +++ b/test/seesaw/test/examples/button_group.clj @@ -8,9 +8,10 @@ ; the terms of this license. ; You must not remove this notice, or any other, from this software. -(ns seesaw.test.examples.button-group - (:use seesaw.core - seesaw.test.examples.example)) +(ns seesaw.test.examples.button-group + (:require + [seesaw.core :refer [button-group label border-panel horizontal-panel radio listen text! text to-widget selection frame]] + [seesaw.test.examples.example :refer [defexample]])) ; An example of putting radio buttons (or toggle buttons, or menu items, etc) ; in a button group to ensure mutual exclusion. Note that the group is a @@ -48,7 +49,6 @@ panel)) (defexample run [] - (frame :title "Seesaw Button Group Example" :height 150 :width 300 diff --git a/test/seesaw/test/examples/canvas.clj b/test/seesaw/test/examples/canvas.clj index 9a72f6df..2a01e45b 100644 --- a/test/seesaw/test/examples/canvas.clj +++ b/test/seesaw/test/examples/canvas.clj @@ -9,10 +9,10 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.canvas - (:use seesaw.core - seesaw.graphics - seesaw.color - seesaw.test.examples.example)) + (:require [seesaw.core :refer [action to-frame config! frame border-panel canvas horizontal-panel select]] + [seesaw.graphics :refer [draw polygon style stroke path move-to line-to ellipse push rotate string-shape translate]] + [seesaw.color :refer [color]] + [seesaw.test.examples.example :refer [defexample]])) ; A very rudimentary example of (canvas). @@ -79,8 +79,8 @@ (select [:#canvas]) (config! :paint paint)))) -(defexample [] - (frame +(defexample run [] + (frame :title "Canvas Example" :width 500 :height 300 :content diff --git a/test/seesaw/test/examples/cell_renderers.clj b/test/seesaw/test/examples/cell_renderers.clj index cb6bad03..3ebfb241 100644 --- a/test/seesaw/test/examples/cell_renderers.clj +++ b/test/seesaw/test/examples/cell_renderers.clj @@ -1,6 +1,8 @@ (ns seesaw.test.examples.cell-renderers - (:use [seesaw core font] - seesaw.test.examples.example)) + (:require + [seesaw.core :refer [config! frame listbox scrollable]] + [seesaw.font :refer [font]] + [seesaw.test.examples.example :refer [defexample]])) (def even-font (font "ARIAL-ITALIC-18")) (def odd-font (font "ARIAL--18")) @@ -17,7 +19,7 @@ [:text (str v " is even") :font even-font :foreground "#000033"] [:text (str v " is odd") :font odd-font :foreground "#aaaaee"])))) -(defexample [] +(defexample run [] (frame :title "Cell Renderer Example" :content (scrollable (listbox :model (range 5 25) diff --git a/test/seesaw/test/examples/clock.clj b/test/seesaw/test/examples/clock.clj index 741a2ca0..eb439284 100644 --- a/test/seesaw/test/examples/clock.clj +++ b/test/seesaw/test/examples/clock.clj @@ -9,10 +9,10 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.clock - (:use seesaw.core - seesaw.graphics - seesaw.color - seesaw.test.examples.example)) + (:require [seesaw.core :refer [canvas timer repaint! frame]] + [seesaw.graphics :refer [path move-to line-to style stroke translate scale push rotate draw circle line]] + [seesaw.color :refer [color]] + [seesaw.test.examples.example :refer [defexample]])) ; A very rudimentary example of (canvas) that draws an analog clock @@ -76,9 +76,9 @@ ; Draw a little circle in the middle (draw g (circle 0 0 3) tick-style))) -(defexample [] - (let [cvs (canvas :id :canvas :background "#BBBBBB" :paint paint-clock) - t (timer (fn [e] (repaint! cvs)) :delay 1000)] +(defexample run [] + (let [cvs (canvas :id :canvas :background "#BBBBBB" :paint paint-clock)] + (timer (fn [e] (repaint! cvs)) :delay 1000) (frame :title "Seesaw Canvas Clock" :width 400 :height 400 diff --git a/test/seesaw/test/examples/custom_border.clj b/test/seesaw/test/examples/custom_border.clj index 05b8e871..fd1d11fa 100644 --- a/test/seesaw/test/examples/custom_border.clj +++ b/test/seesaw/test/examples/custom_border.clj @@ -9,11 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.custom-border - (:use [seesaw.core :only [frame label show!]] - [seesaw.border :only [custom-border]] - seesaw.test.examples.example)) + (:require [seesaw.core :refer [frame label]] + [seesaw.border :refer [custom-border]] + [seesaw.test.examples.example :refer [defexample]])) -(defexample [] +(defexample run [] (frame :size [400 :by 400] :content (label :text "I have a custom border" diff --git a/test/seesaw/test/examples/custom_dialog.clj b/test/seesaw/test/examples/custom_dialog.clj index 1b55a48c..ef7f5287 100644 --- a/test/seesaw/test/examples/custom_dialog.clj +++ b/test/seesaw/test/examples/custom_dialog.clj @@ -9,8 +9,12 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.custom-dialog - (:use [seesaw core font border mig] - seesaw.test.examples.example)) + (:require + [seesaw.test.examples.example :refer [defexample]] + [seesaw.core :refer [action return-from-dialog custom-dialog flow-panel pack! show! value to-frame alert label combobox slider frame]] + [seesaw.mig :refer [mig-panel]] + [seesaw.border :refer [line-border]] + [seesaw.font :refer [font default-font]])) (defn open-more-options-dlg [] @@ -63,7 +67,7 @@ pack! show!))) -(defexample [] +(defexample run [] (frame :title "Custom Dialog Example" :content (action :name "Show Dialog" :handler (fn [e] diff --git a/test/seesaw/test/examples/dialog.clj b/test/seesaw/test/examples/dialog.clj index cb1720bf..8a51718c 100644 --- a/test/seesaw/test/examples/dialog.clj +++ b/test/seesaw/test/examples/dialog.clj @@ -9,10 +9,15 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.dialog - (:use [seesaw core font border util color pref mig] - [clojure.pprint :only (cl-format)] - seesaw.test.examples.example) - (:require [seesaw.bind :as bind])) + (:require + [clojure.pprint :refer (cl-format)] + [seesaw.bind :as bind] + [seesaw.test.examples.example :refer [defexample]] + [seesaw.core :refer :all] + [seesaw.pref :refer [bind-preference-to-atom]] + [seesaw.mig :refer [mig-panel]] + [seesaw.font :refer [font default-font]] + [seesaw.color :refer [color]])) (defmethod print-dup java.awt.Color [x writer] (binding [*print-dup* false] @@ -93,7 +98,7 @@ lbl) "growx, wrap"] ])) pack! show!))) -(defexample [] +(defexample run [] (frame :title "Custom Dialog Example" :resizable? false :content (vertical-panel :items [(action :name "Show Dialog with custom :success-fn" diff --git a/test/seesaw/test/examples/dnd.clj b/test/seesaw/test/examples/dnd.clj index c98b92bd..5fd145bb 100644 --- a/test/seesaw/test/examples/dnd.clj +++ b/test/seesaw/test/examples/dnd.clj @@ -89,7 +89,7 @@ (scrollable icon-label) :divider-location 1/2))) -(defexample [] +(defexample run [] (frame :title "Seesaw Drag-n-Drop Example" :content diff --git a/test/seesaw/test/examples/dynamic_layout.clj b/test/seesaw/test/examples/dynamic_layout.clj index d7e8501b..42db55af 100644 --- a/test/seesaw/test/examples/dynamic_layout.clj +++ b/test/seesaw/test/examples/dynamic_layout.clj @@ -1,6 +1,7 @@ (ns seesaw.test.examples.dynamic-layout - (:use seesaw.core - seesaw.test.examples.example)) + (:require + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]])) ; Extremely basic example of a panel that changes what it shows based on ; whether it has enough room. @@ -46,7 +47,7 @@ (grid-panel :columns 1 :items (for [i (range 10)] (make-dynamic-panel i)))) -(defexample [] +(defexample run [] (-> (frame :content (make-vertical-panel)) pack! show!)) diff --git a/test/seesaw/test/examples/editor_pane_hyperlink.clj b/test/seesaw/test/examples/editor_pane_hyperlink.clj index 1c9dbacd..64b07a84 100644 --- a/test/seesaw/test/examples/editor_pane_hyperlink.clj +++ b/test/seesaw/test/examples/editor_pane_hyperlink.clj @@ -9,10 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.editor-pane-hyperlink - (:use seesaw.core - seesaw.test.examples.example) - (:import javax.swing.event.HyperlinkEvent - javax.swing.event.HyperlinkEvent$EventType)) + (:require + [seesaw.core :refer [alert editor-pane frame listen select]] + [seesaw.test.examples.example :refer [defexample]]) + (:import + javax.swing.event.HyperlinkEvent$EventType)) (defn make-editor-pane [] @@ -40,7 +41,7 @@ (alert e (str "Clicked: " (.getDescription e))))))) root) -(defexample [] +(defexample run [] (-> (frame :title "Editor Pane Hyperlinks" diff --git a/test/seesaw/test/examples/example.clj b/test/seesaw/test/examples/example.clj index 762780df..afb94862 100644 --- a/test/seesaw/test/examples/example.clj +++ b/test/seesaw/test/examples/example.clj @@ -1,5 +1,5 @@ (ns seesaw.test.examples.example - (:use [seesaw.core :only [config! pack! show! invoke-now]])) + (:require [seesaw.core :refer [config! pack! show! invoke-now]])) (defmacro defexample "Does the boilerplate for an example. @@ -17,9 +17,9 @@ See the plethora of examples in this directory for usage examples. " - [arg-vec & body] + [fn-name arg-vec & body] `(do - (defn ~'run [on-close# & args#] + (defn ~fn-name [on-close# & args#] (let [~arg-vec args# f# (invoke-now ~@body)] (config! f# :on-close on-close#) @@ -28,4 +28,4 @@ (show! f#))) (defn ~'-main [& args#] - (apply ~'run :exit args#)))) + (apply ~fn-name :exit args#)))) diff --git a/test/seesaw/test/examples/explorer.clj b/test/seesaw/test/examples/explorer.clj index eeba18d5..2735f0f0 100644 --- a/test/seesaw/test/examples/explorer.clj +++ b/test/seesaw/test/examples/explorer.clj @@ -9,10 +9,13 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.explorer - (:use [seesaw core tree] - seesaw.test.examples.example) - (:import [java.io File] - [javax.swing.filechooser FileSystemView])) + (:require + [seesaw.core :refer [border-panel config! frame label left-right-split + listbox listen scrollable select selection tree]] + [seesaw.test.examples.example :refer [defexample]] + [seesaw.tree :refer [simple-tree-model]]) + (:import + [java.io File])) ; Make a model for the directory tree (def tree-model @@ -43,12 +46,12 @@ :south (label :id :status :text "Ready")))) -(defexample [] +(defexample run [] (let [f (make-frame)] ; Hook up a selection listener to the tree to update stuff (listen (select f [:#tree]) :selection (fn [e] - (if-let [dir (last (selection e))] + (when-let [dir (last (selection e))] (let [files (.listFiles dir)] (config! (select f [:#current-dir]) :text (.getAbsolutePath dir)) (config! (select f [:#status]) :text (format "Ready (%d items)" (count files))) diff --git a/test/seesaw/test/examples/form.clj b/test/seesaw/test/examples/form.clj index e0e7d9a7..767be65d 100644 --- a/test/seesaw/test/examples/form.clj +++ b/test/seesaw/test/examples/form.clj @@ -1,10 +1,10 @@ (ns seesaw.test.examples.form - (:use seesaw.core - seesaw.test.examples.example)) + (:require [seesaw.core :refer [frame form-panel label text grid-panel button checkbox]] + [seesaw.test.examples.example :refer [defexample]])) ;http://www.leepoint.net/notes-java/GUI/layouts/gridbag-example.html -(defexample [] +(defexample run [] (frame :title "Find/Replace" :content (form-panel :items [ diff --git a/test/seesaw/test/examples/forms.clj b/test/seesaw/test/examples/forms.clj index bd6cb130..119d23e4 100644 --- a/test/seesaw/test/examples/forms.clj +++ b/test/seesaw/test/examples/forms.clj @@ -9,8 +9,10 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.forms - (:use [seesaw [core :exclude (separator)] forms] - seesaw.test.examples.example)) + (:require + [seesaw.core :refer :all] + [seesaw.forms :refer [forms-panel span]] + [seesaw.test.examples.example :refer [defexample]])) ; Example similar to miglayout @@ -27,7 +29,7 @@ "R/mm" (text :columns 10) "D/mm" (text :columns 10)] :default-dialog-border? true)) -(defexample [] +(defexample run [] (frame :title "jGoodies FormLayout Example" :resizable? false :content (frame-content))) diff --git a/test/seesaw/test/examples/full_screen.clj b/test/seesaw/test/examples/full_screen.clj index bb6ca700..449ed1dc 100644 --- a/test/seesaw/test/examples/full_screen.clj +++ b/test/seesaw/test/examples/full_screen.clj @@ -9,8 +9,9 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.full-screen - (:use [seesaw core] - seesaw.test.examples.example)) + (:require + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]])) ; Example usage of toggle-full-screen!. In this example, the frame is undecorated ; so we have to provide an explicit close button. @@ -30,7 +31,7 @@ (listen (select root [:#close]) :action (fn [e] (dispose! root))) root) -(defexample [] +(defexample run [] (-> (make-frame) add-behaviors show!)) diff --git a/test/seesaw/test/examples/game_of_life.clj b/test/seesaw/test/examples/game_of_life.clj index 90a5c14d..4f662f65 100644 --- a/test/seesaw/test/examples/game_of_life.clj +++ b/test/seesaw/test/examples/game_of_life.clj @@ -1,13 +1,14 @@ (ns seesaw.test.examples.game-of-life - (:use [seesaw.dev] - [seesaw.core] - [seesaw.graphics] - [seesaw.behave] - [seesaw.border] - seesaw.test.examples.example) - (:require [clojure.java.io :as jio] - [seesaw.dnd :as dnd] - [seesaw.bind :as b])) + (:require + [clojure.java.io :as jio] + [seesaw.behave :refer [when-mouse-dragged]] + [seesaw.bind :as b] + [seesaw.border :refer [line-border]] + [seesaw.core :refer :all] + [seesaw.dev :refer [debug!]] + [seesaw.dnd :as dnd] + [seesaw.graphics :refer [draw rect style]] + [seesaw.test.examples.example :refer [defexample]])) (debug!) ; Adapted from http://tech.puredanger.com/2011/11/17/clojure-and-processing/ @@ -65,7 +66,7 @@ (->> grid (map-indexed (fn [y s] (map-indexed (fn [x c] - (if (= \O c) [x y])) + (when (= \O c) [x y])) s))) (apply concat) (filter identity) @@ -163,7 +164,7 @@ root) -(defexample [] +(defexample run [] (-> (make-ui) add-behaviors)) ;(run :dispose) diff --git a/test/seesaw/test/examples/hotpotatoes.clj b/test/seesaw/test/examples/hotpotatoes.clj index 985f0532..1849f397 100644 --- a/test/seesaw/test/examples/hotpotatoes.clj +++ b/test/seesaw/test/examples/hotpotatoes.clj @@ -9,9 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.hotpotatoes - (:use seesaw.core seesaw.util seesaw.font - seesaw.test.examples.example) - (:require [clojure.java.io :only reader])) + (:require + [clojure.java.io :only reader] + [seesaw.core :refer :all] + [seesaw.util :refer [to-url]] + [seesaw.test.examples.example :refer [defexample]])) ; A simple HTTP request app. Enter a URL and click "Go". It does the request in ; the background and displays the response. @@ -23,7 +25,7 @@ "Invalid URL")] (invoke-later (f result))))) -(defexample [] +(defexample run [] (let [exit-action (action :handler dispose! :name "Exit") url-text (text "http://google.com") status (label "Ready") diff --git a/test/seesaw/test/examples/j18n.clj b/test/seesaw/test/examples/j18n.clj index b969e678..62be9a8b 100644 --- a/test/seesaw/test/examples/j18n.clj +++ b/test/seesaw/test/examples/j18n.clj @@ -9,10 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.j18n - (use [seesaw.core] - seesaw.test.examples.example)) + (:require + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]])) -(defexample [] +(defexample run [] (let [a (action ; Use a set of properties for the action, all with prefix "action" :resource ::my-action diff --git a/test/seesaw/test/examples/kitchensink.clj b/test/seesaw/test/examples/kitchensink.clj index 6c52fae2..7cc18772 100644 --- a/test/seesaw/test/examples/kitchensink.clj +++ b/test/seesaw/test/examples/kitchensink.clj @@ -9,18 +9,20 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.kitchensink - (:require clojure.java.io) - (:use seesaw.core - seesaw.border - seesaw.test.examples.example) - (:import (javax.swing JFrame JLabel) - (java.awt Color))) + (:require + [clojure.java.io :as io] + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]] + [seesaw.border :refer [empty-border line-border]]) + (:import + (java.awt Color) + (javax.swing JLabel))) ; NOTE: This was the first Seesaw example written. It shows fairly randomly ; how to do a bunch of stuff, but it's unfocused, messy and generally a ; bad example of how to structure a Seesaw (or any) app. -(def rss-url (clojure.java.io/resource "seesaw/test/examples/rss.gif")) +(def rss-url (io/resource "seesaw/test/examples/rss.gif")) (def redditor "http://static.reddit.com/reddit.com.header.png") (defn make-frame [] @@ -119,7 +121,7 @@ :south (label :id :table-sel :text "Table selection: ")) } ]))))) -(defexample [] +(defexample run [] (let [f (make-frame)] (listen (select f [:#tabs]) :selection #(let [tp (to-widget %) diff --git a/test/seesaw/test/examples/kotka_bind.clj b/test/seesaw/test/examples/kotka_bind.clj index b90ec309..307980df 100644 --- a/test/seesaw/test/examples/kotka_bind.clj +++ b/test/seesaw/test/examples/kotka_bind.clj @@ -9,9 +9,9 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.kotka-bind - (:require [seesaw.bind :as bind]) - (:use [seesaw.core] - seesaw.test.examples.example)) + (:require [seesaw.bind :as bind] + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]])) ; seesaw.bind applied to http://kotka.de/blog/2010/05/Decoupling_Logic_and_GUI.html ; @@ -26,7 +26,7 @@ (swap! progress inc)) (reset! done? true)) -(defexample [] +(defexample run [] (let [items (take 500 (iterate inc 0)) progress (atom 0) done? (atom false) diff --git a/test/seesaw/test/examples/launcher.clj b/test/seesaw/test/examples/launcher.clj index 595a4e62..7d206943 100644 --- a/test/seesaw/test/examples/launcher.clj +++ b/test/seesaw/test/examples/launcher.clj @@ -9,10 +9,13 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.launcher - (:use [seesaw core swingx keymap] - seesaw.test.examples.example) - (:require [seesaw.bind :as b] - [seesaw.dev :as dev])) + (:require + [seesaw.bind :as b] + [seesaw.core :refer :all] + [seesaw.dev :as dev] + [seesaw.keymap :refer [map-key]] + [seesaw.swingx :refer [hl-color hl-simple-striping listbox-x]] + [seesaw.test.examples.example :refer [defexample]])) ; A simple launcher for all the examples. @@ -103,7 +106,7 @@ (selection! list (first examples))) f) -(defexample [] +(defexample run [] (dev/debug!) (-> (make-frame) add-behaviors)) diff --git a/test/seesaw/test/examples/log_window.clj b/test/seesaw/test/examples/log_window.clj index 1c36d69f..77e47ee0 100644 --- a/test/seesaw/test/examples/log_window.clj +++ b/test/seesaw/test/examples/log_window.clj @@ -9,12 +9,10 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.log-window - (:use [seesaw.core] - [seesaw.widgets.log-window] - [seesaw.invoke :only [signaller]] - [seesaw.options :only [apply-options]] - seesaw.test.examples.example) - (:require [seesaw.dev :as dev])) + (:require [seesaw.dev :as dev] + [seesaw.core :refer :all] + [seesaw.widgets.log-window :refer [log-window log]] + [seesaw.test.examples.example :refer [defexample]])) ; Example usage of seesaw.widgets.log-window/log-window @@ -39,7 +37,7 @@ (loop [i 0] (log lw (str prefix " - " i " asdf asdf asdf asdf asdf asdf\n")) (Thread/sleep 100) - (if @go + (when @go (recur (inc i))))) (defn add-behaviors [f] @@ -47,8 +45,8 @@ go (atom false)] (listen limit? - :selection (fn [_] (config! log-window :limit (if (value limit?) - (value limit))))) + :selection (fn [_] (config! log-window :limit (when (value limit?) + (value limit))))) (listen stop :action (fn [_] (reset! go false))) @@ -59,7 +57,7 @@ (future (spammer log-window (System/currentTimeMillis) go))))) f) -(defexample [] +(defexample run [] (-> (make-frame) add-behaviors)) ;(run :dispose) diff --git a/test/seesaw/test/examples/make_widget.clj b/test/seesaw/test/examples/make_widget.clj index eb021117..d8255c6d 100644 --- a/test/seesaw/test/examples/make_widget.clj +++ b/test/seesaw/test/examples/make_widget.clj @@ -9,8 +9,12 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.make-widget - (:use [seesaw core border make-widget mig] - seesaw.test.examples.example)) + (:require + [seesaw.border :refer [line-border]] + [seesaw.core :refer :all] + [seesaw.make-widget :refer [MakeWidget]] + [seesaw.mig :refer [mig-panel]] + [seesaw.test.examples.example :refer [defexample]])) ; This example shows how to implement the MakeWidget protocol for a new type. ; Is this cute? Yes. Useful? Hell if I know. @@ -43,7 +47,7 @@ ; Pass the people as the :items of a panel and we get a scrollable ; list of widgets. -(defexample [] +(defexample run [] (frame :title "People" :content (scrollable (vertical-panel :items people)))) diff --git a/test/seesaw/test/examples/mig.clj b/test/seesaw/test/examples/mig.clj index 51a190f9..4e291e88 100644 --- a/test/seesaw/test/examples/mig.clj +++ b/test/seesaw/test/examples/mig.clj @@ -9,8 +9,9 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.mig - (:use [seesaw core mig] - seesaw.test.examples.example)) + (:require [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]] + [seesaw.mig :refer [mig-panel]])) ; http://www.devx.com/Java/Article/38017/1954 @@ -36,7 +37,7 @@ [ "D/mm" "gap 10"] [ (text :columns 10) ""]])) -(defexample [] +(defexample run [] (frame :title "MigLayout Example" :resizable? false :content (frame-content))) ;(run :dispose) diff --git a/test/seesaw/test/examples/multi_dialog.clj b/test/seesaw/test/examples/multi_dialog.clj index cd13d255..cdcae32d 100644 --- a/test/seesaw/test/examples/multi_dialog.clj +++ b/test/seesaw/test/examples/multi_dialog.clj @@ -9,7 +9,8 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.multi-dialog - (:use [seesaw core])) + (:require + [seesaw.core :refer :all])) ; Tiny test for showing multiple "document modal" dialogs at the same time. diff --git a/test/seesaw/test/examples/paintable.clj b/test/seesaw/test/examples/paintable.clj index c320b97f..a9a95c2c 100644 --- a/test/seesaw/test/examples/paintable.clj +++ b/test/seesaw/test/examples/paintable.clj @@ -9,8 +9,10 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.paintable - (:use [seesaw core graphics] - seesaw.test.examples.example)) + (:require + [seesaw.core :refer :all] + [seesaw.graphics :refer [draw line style]] + [seesaw.test.examples.example :refer [defexample]])) (defn draw-a-red-x "Draw a red X on a widget with the given graphics context" @@ -31,7 +33,7 @@ (label :text "I'm a bad label!" :font "ARIAL-BOLD-40" :paint draw-a-red-x) (button :text "I'm a bad button!" :font "ARIAL-BOLD-40" :paint draw-a-red-x)])) -(defexample [] +(defexample run [] (frame :title "Seesaw :paint example" :content (content))) diff --git a/test/seesaw/test/examples/pan_on_drag.clj b/test/seesaw/test/examples/pan_on_drag.clj index 14d1932c..7e81d8f1 100644 --- a/test/seesaw/test/examples/pan_on_drag.clj +++ b/test/seesaw/test/examples/pan_on_drag.clj @@ -1,11 +1,11 @@ (ns seesaw.test.examples.pan-on-drag - (:use seesaw.test.examples.example) - (:require [seesaw.core :as sc] - [seesaw.behave :as behave])) + (:require [seesaw.core :refer :all] + [seesaw.behave :as behave] + [seesaw.test.examples.example :refer [defexample]])) (defn scrollable-image [id] - (sc/scrollable - (sc/label :id id + (scrollable + (label :id id ;:icon "file:///Users/dave/Desktop/IMG_0058.JPG" ))) @@ -30,28 +30,28 @@ (pan view-to-pan (* dx sx speed) (* dy sy speed))))))) (defn add-behaviors [root] - (pan-on-drag (sc/select root [:#image])) - (pan-on-drag (sc/select root [:#image]) - :panner (sc/select root [:#panner]) + (pan-on-drag (select root [:#image])) + (pan-on-drag (select root [:#image]) + :panner (select root [:#panner]) :scale 5.0) root) (defn app [] - (sc/frame + (frame :title "Pan on drag" :size [480 :by 480] :content - (sc/border-panel + (border-panel :north "Click and drag to pan the image" :center (scrollable-image :image) - :south (sc/flow-panel + :south (flow-panel :items ["Or drag on the blue field to pan the image" - (sc/label + (label :id :panner :size [50 :by 50] :background :blue)])))) -(defexample [] +(defexample run [] (-> (app) add-behaviors)) ;(run :dispose) diff --git a/test/seesaw/test/examples/pi.clj b/test/seesaw/test/examples/pi.clj index 9d9b0c17..fcd54975 100644 --- a/test/seesaw/test/examples/pi.clj +++ b/test/seesaw/test/examples/pi.clj @@ -9,9 +9,9 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.pi - (:use seesaw.core - seesaw.test.examples.example) - (:require seesaw.invoke) + (:require [seesaw.invoke] + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]]) (:import [java.util.concurrent LinkedBlockingQueue TimeUnit])) (defn calculate-pi-for @@ -157,7 +157,7 @@ (apply listen (select root sel) (reduce concat handlers))) root) -(defexample [] +(defexample run [] (-> (make-frame) (apply-stylesheet stylesheet) (apply-behaviors behaviors))) diff --git a/test/seesaw/test/examples/piano.clj b/test/seesaw/test/examples/piano.clj index 0fe47366..dc497715 100644 --- a/test/seesaw/test/examples/piano.clj +++ b/test/seesaw/test/examples/piano.clj @@ -9,8 +9,10 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.piano - (:use [seesaw core border] - seesaw.test.examples.example)) + (:require + [seesaw.border :refer [line-border]] + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]])) (def num-octaves 7) (def piano-key-info @@ -70,7 +72,7 @@ (println "You hit " note "/" midi))))) root) -(defexample [] +(defexample run [] (-> (frame :title "Seesaw piano example" :content (border-panel diff --git a/test/seesaw/test/examples/popup.clj b/test/seesaw/test/examples/popup.clj index 8aaa9c1e..37d7d423 100644 --- a/test/seesaw/test/examples/popup.clj +++ b/test/seesaw/test/examples/popup.clj @@ -8,8 +8,10 @@ ; the terms of this license. ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.popup - (:use [seesaw core border] - seesaw.test.examples.example)) + (:require + [seesaw.border :refer [line-border]] + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]])) ; An example of adding a popup (i.e. right-click/context) menu to a component. @@ -22,7 +24,7 @@ [event] [(str "HI-" (rand)) "BYE"]) -(defexample [] +(defexample run [] (frame :title "Popup Menu Example" :width 500 :height 300 :content (left-right-split diff --git a/test/seesaw/test/examples/reorderable_listbox.clj b/test/seesaw/test/examples/reorderable_listbox.clj index 07d3ff4d..2f2b432a 100644 --- a/test/seesaw/test/examples/reorderable_listbox.clj +++ b/test/seesaw/test/examples/reorderable_listbox.clj @@ -9,9 +9,10 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.reorderable-listbox - (:use seesaw.core - seesaw.test.examples.example) - (:require [seesaw.dnd :as dnd])) + (:require + [seesaw.core :refer :all] + [seesaw.dnd :as dnd] + [seesaw.test.examples.example :refer [defexample]])) (defn list-with-elem-at-index @@ -83,7 +84,7 @@ new items are allowed to be added, nor may existing items be removed." [dnd/string-flavor (selection c)])})))) -(defexample [] +(defexample run [] (let [atom-with-cur-item-order (atom ["Pie" "Cake" "Cookies" "Ice Cream" "Donut"])] (frame diff --git a/test/seesaw/test/examples/rpn.clj b/test/seesaw/test/examples/rpn.clj index 512187c6..954ace56 100644 --- a/test/seesaw/test/examples/rpn.clj +++ b/test/seesaw/test/examples/rpn.clj @@ -9,10 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.rpn - (:use [seesaw.core] - [seesaw.style :only [apply-stylesheet]] - seesaw.test.examples.example) - (:require [seesaw.bind :as bind])) + (:require + [seesaw.bind :as bind] + [seesaw.core :refer :all] + [seesaw.style :refer [apply-stylesheet]] + [seesaw.test.examples.example :refer [defexample]])) ;; A simple RPN calculator @@ -118,7 +119,7 @@ :editable? false} [:#stack] {:font "ARIAL-PLAIN-20"} }) -(defexample [] +(defexample run [] (-> (layout) behave diff --git a/test/seesaw/test/examples/rsyntax.clj b/test/seesaw/test/examples/rsyntax.clj index db354df6..f9c31eaa 100644 --- a/test/seesaw/test/examples/rsyntax.clj +++ b/test/seesaw/test/examples/rsyntax.clj @@ -9,10 +9,10 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.rsyntax - (:use [seesaw core] - seesaw.test.examples.example) (:require [seesaw.rsyntax :as rsyntax] - [clojure.java.io :as io])) + [seesaw.core :refer :all] + [clojure.java.io :as io] + [seesaw.test.examples.example :refer [defexample]])) (defn make-frame [] (frame :title "RSyntax Example" :width 500 :height 400 @@ -21,8 +21,8 @@ :text (io/resource "seesaw/test/examples/rsyntax.clj") :syntax :clojure)))) -(defexample [] - (make-frame) ) +(defexample run [] + (make-frame)) ;(run :dispose) diff --git a/test/seesaw/test/examples/scribble.clj b/test/seesaw/test/examples/scribble.clj index 1bbeb515..712dc958 100644 --- a/test/seesaw/test/examples/scribble.clj +++ b/test/seesaw/test/examples/scribble.clj @@ -9,8 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.scribble - (:use [seesaw core color graphics behave] - seesaw.test.examples.example)) + (:require + [seesaw.behave :refer [when-mouse-dragged]] + [seesaw.core :refer :all] + [seesaw.graphics :refer [draw ellipse line move-to path rect style update-style]] + [seesaw.test.examples.example :refer [defexample]])) (def colors [:black :white :blue :green :red :yellow :orange :purple nil]) @@ -135,7 +138,7 @@ :preferred-size [500 :by 500] :background :white))))) -(defexample [] +(defexample run [] (-> (make-ui) add-behaviors)) ;(run :dispose) diff --git a/test/seesaw/test/examples/scroll.clj b/test/seesaw/test/examples/scroll.clj index ed26204a..8d9c574b 100644 --- a/test/seesaw/test/examples/scroll.clj +++ b/test/seesaw/test/examples/scroll.clj @@ -8,10 +8,10 @@ ; the terms of this license. ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.scroll - (:use seesaw.core - seesaw.test.examples.example) - (:require [seesaw.bind :as bind] - seesaw.scroll)) + (:require + [seesaw.bind :as bind] + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]])) (defn top [target] (action :name "(scroll! v :to :top)" @@ -96,7 +96,7 @@ {:title "table" :content (jtable)} {:title "text" :content (jtext)}])) -(defexample [] +(defexample run [] (frame :title "Seesaw Scroll Demo" :size [800 :by 400] :content (app-panel))) diff --git a/test/seesaw/test/examples/slider.clj b/test/seesaw/test/examples/slider.clj index aff1faf2..4adb7e12 100644 --- a/test/seesaw/test/examples/slider.clj +++ b/test/seesaw/test/examples/slider.clj @@ -9,8 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.slider - (:use [seesaw core color border] - seesaw.test.examples.example)) + (:require + [seesaw.border :refer [line-border]] + [seesaw.color :refer [color]] + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]])) (defn make-frame [] (frame @@ -31,7 +34,7 @@ (config! (select root [:#canvas]) :background (color red green blue)))) -(defexample [] +(defexample run [] (let [root (make-frame)] (listen (map #(select root [%]) [:#red :#green :#blue]) :change (fn [e] diff --git a/test/seesaw/test/examples/spinner.clj b/test/seesaw/test/examples/spinner.clj index c0703a20..02be6b64 100644 --- a/test/seesaw/test/examples/spinner.clj +++ b/test/seesaw/test/examples/spinner.clj @@ -8,10 +8,11 @@ ; the terms of this license. ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.spinner - (:use [seesaw.core] - seesaw.test.examples.example)) + (:require + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]])) -(defexample [] +(defexample run [] (frame :title "Spinner Example" :content diff --git a/test/seesaw/test/examples/swingx.clj b/test/seesaw/test/examples/swingx.clj index 168b8c9d..bd9e4cbd 100644 --- a/test/seesaw/test/examples/swingx.clj +++ b/test/seesaw/test/examples/swingx.clj @@ -9,10 +9,13 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.swingx - (:use [seesaw.core] - [seesaw.swingx] - seesaw.test.examples.example) - (:require [seesaw.bind :as b])) + (:require + [seesaw.bind :as b] + [seesaw.core :refer :all] + [seesaw.swingx :refer [busy-label color-selection-button header hl-color + hl-simple-striping hyperlink label-x listbox-x + table-x task-pane task-pane-container titled-panel]] + [seesaw.test.examples.example :refer [defexample]])) ; A demo program that shows some of the components in Seesaw's SwingX support. (defn demo [title desc content] @@ -119,7 +122,7 @@ (@demos (selection chooser)) )))) root) -(defexample [] +(defexample run [] (-> (make-ui) add-behaviors)) ;(run :dispose) diff --git a/test/seesaw/test/examples/table.clj b/test/seesaw/test/examples/table.clj index a740d31c..4390f21d 100644 --- a/test/seesaw/test/examples/table.clj +++ b/test/seesaw/test/examples/table.clj @@ -9,8 +9,10 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.table - (:use [seesaw core table] - seesaw.test.examples.example)) + (:require + [seesaw.core :refer :all] + [seesaw.table :refer [value-at]] + [seesaw.test.examples.example :refer [defexample]])) ; A simple example of (table) for basic tabular data @@ -34,7 +36,7 @@ :center (scrollable (make-table)) :south (label :id :sel :text "Selection: ")))) -(defexample [] +(defexample run [] (let [f (show! (make-frame)) t (select f [:#table])] ; Listen for selection changes and show them in the label diff --git a/test/seesaw/test/examples/temp.clj b/test/seesaw/test/examples/temp.clj index 69152b9d..f5264d14 100644 --- a/test/seesaw/test/examples/temp.clj +++ b/test/seesaw/test/examples/temp.clj @@ -9,9 +9,9 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.temp - (:use seesaw.core - seesaw.font - seesaw.test.examples.example)) + (:require + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]])) ; See http://stuartsierra.com/2010/01/06/heating-up-clojure-swing @@ -38,7 +38,7 @@ (listen source :document (fn [e] (update-temp source target f))) source) -(defexample [] +(defexample run [] (let [c (text :tip "Enter Celsius temperature") f (text :tip "Enter Fahrenheit temperature")] (frame diff --git a/test/seesaw/test/examples/text_editor.clj b/test/seesaw/test/examples/text_editor.clj index e6af5462..802ce8bd 100644 --- a/test/seesaw/test/examples/text_editor.clj +++ b/test/seesaw/test/examples/text_editor.clj @@ -1,9 +1,10 @@ (ns seesaw.test.examples.text-editor - (:use seesaw.core - seesaw.chooser - seesaw.mig - seesaw.test.examples.example - [clojure.java.io :only [file]])) + (:require + [clojure.java.io :refer [file]] + [seesaw.chooser :refer [choose-file]] + [seesaw.core :refer :all] + [seesaw.mig :refer [mig-panel]] + [seesaw.test.examples.example :refer [defexample]])) (native!) @@ -72,7 +73,7 @@ :items [(menu :text "File" :items [a-new a-open a-save a-save-as a-exit]) (menu :text "Edit" :items [a-copy a-cut a-paste])]))) -(defexample [] +(defexample run [] (add-watch current-file nil diff --git a/test/seesaw/test/examples/text_ref.clj b/test/seesaw/test/examples/text_ref.clj index 83766cb9..b7c7c87a 100644 --- a/test/seesaw/test/examples/text_ref.clj +++ b/test/seesaw/test/examples/text_ref.clj @@ -9,13 +9,14 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.text-ref - (:use [seesaw.core] - seesaw.test.examples.example) - (:require [seesaw.bind :as bind])) + (:require + [seesaw.bind :as bind] + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]])) ; Very basic example of connecting a text field to an atom. -(defexample [] +(defexample run [] (let [input (text :columns 20) value (atom "") output (text :editable? false)] diff --git a/test/seesaw/test/examples/toggle_listbox.clj b/test/seesaw/test/examples/toggle_listbox.clj index 70730aa2..ff0ee942 100644 --- a/test/seesaw/test/examples/toggle_listbox.clj +++ b/test/seesaw/test/examples/toggle_listbox.clj @@ -9,12 +9,13 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.toggle-listbox - (:import [java.awt Dimension] - [java.awt.image BufferedImage] - [javax.swing ImageIcon]) - (:use seesaw.core - seesaw.test.examples.example) - (:require [seesaw.dnd :as dnd])) + (:require + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]]) + (:import + [java.awt Dimension] + [java.awt.image BufferedImage] + [javax.swing ImageIcon])) ;; I learned about the trick of first calling setSize on a Swing @@ -74,7 +75,7 @@ there purely for display purposes." :renderer render-item))) -(defexample [] +(defexample run [] (frame :title "List with strings shown as toggle buttons" :content diff --git a/test/seesaw/test/examples/tree.clj b/test/seesaw/test/examples/tree.clj index 91fed68c..65990f70 100644 --- a/test/seesaw/test/examples/tree.clj +++ b/test/seesaw/test/examples/tree.clj @@ -9,9 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.tree - (:use [seesaw core tree] - seesaw.test.examples.example) - (:require clojure.xml)) + (:require + [clojure.xml :as xml] + [seesaw.core :refer :all] + [seesaw.test.examples.example :refer [defexample]] + [seesaw.tree :refer [simple-tree-model]])) (def source "http://www.4clojure.com/problems/rss") @@ -21,7 +23,7 @@ (simple-tree-model (complement string?) (comp seq :content) - (clojure.xml/parse source))) + (xml/parse source))) ; A custom renderer so that XML elements are displayed nicely (defn render-fn [renderer info] @@ -41,7 +43,7 @@ :renderer render-fn)) :south (label :id :sel :text "Selection: ")))) -(defexample [] +(defexample run [] (let [f (make-frame)] ; Listen for selection changes and show them in the label (listen (select f [:#tree]) diff --git a/test/seesaw/test/examples/xyz_panel.clj b/test/seesaw/test/examples/xyz_panel.clj index 24bd6ef5..f50323c7 100644 --- a/test/seesaw/test/examples/xyz_panel.clj +++ b/test/seesaw/test/examples/xyz_panel.clj @@ -9,9 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.examples.xyz-panel - (:use [seesaw core border behave graphics] - seesaw.test.examples.example) - (:import [javax.swing SwingUtilities])) + (:require [seesaw.core :refer :all] + [seesaw.behave :refer [when-mouse-dragged]] + [seesaw.graphics :refer [draw rounded-rect style]] + [seesaw.border :refer [line-border]] + [seesaw.test.examples.example :refer [defexample]])) ; Put in some basic support for moving w around using behave/when-mouse-dragged. @@ -73,7 +75,7 @@ (config! :bounds :preferred) movable)))) -(defexample [] +(defexample run [] (frame :title "Seesaw xyz-panel example" :content (border-panel diff --git a/test/seesaw/test/font.clj b/test/seesaw/test/font.clj index 1f7eff17..81880b98 100644 --- a/test/seesaw/test/font.clj +++ b/test/seesaw/test/font.clj @@ -9,22 +9,24 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.font - (:use seesaw.font) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)]) - (:import [java.awt Font])) + (:require + [lazytest.core :refer [defdescribe expect expect-it it]] + [seesaw.core :refer :all] + [seesaw.font :refer [default-font font to-font]]) + (:import + [java.awt Font])) -(describe font +(defdescribe font-test (it "can create a font from a font-spec" (let [f (font "ARIAL-BOLD-18")] (expect (= "ARIAL" (.getName f))) - (expect (= 18 (.getSize f)))) - (expect (= Font/BOLD (.getStyle f)))) + (expect (= 18 (.getSize f))) + (expect (= Font/BOLD (.getStyle f))))) (it "can create a bold font" - (let [f (font :style :bold )] + (let [f (font :style :bold)] (expect (= Font/BOLD (.getStyle f))))) (it "can create a bold & italic font" - (let [f (font :style #{:bold :italic} )] + (let [f (font :style #{:bold :italic})] (expect (= (bit-or Font/BOLD Font/ITALIC) (.getStyle f))))) (it "can create a plain font" (let [f (font)] @@ -56,8 +58,8 @@ (expect (= Font/BOLD (.getStyle f))) (expect (= "Arial" (.getName f)))))) -(describe to-font - (it "returns nil if its input is nil" +(defdescribe to-font-test + (expect-it "returns nil if its input is nil" (nil? (to-font nil))) (it "returns its input if its a font" (let [f (font)] @@ -69,7 +71,7 @@ (let [f (to-font {:style :italic})] (expect (= Font/ITALIC (.getStyle f)))))) -(describe default-font +(defdescribe default-font-test (it "retrieves a named from from the UIManager" (let [f (default-font "Label.font") expected (.getFont (javax.swing.UIManager/getDefaults) "Label.font")] diff --git a/test/seesaw/test/forms.clj b/test/seesaw/test/forms.clj index de7f7c0e..ed9d22ac 100644 --- a/test/seesaw/test/forms.clj +++ b/test/seesaw/test/forms.clj @@ -9,12 +9,12 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.forms - (:use [seesaw [core :exclude (separator)]]) - (:use seesaw.forms) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe expect it]] + [seesaw.core :refer [action text]] + [seesaw.forms :refer [forms-panel next-column next-line separator span title]])) -(describe forms-panel +(defdescribe forms-panel-test (it "Creates a JPanel using a JGoodies form builder" (let [p (forms-panel "pref,4dlu,80dlu,8dlu,pref,4dlu,80dlu" diff --git a/test/seesaw/test/graphics.clj b/test/seesaw/test/graphics.clj index 0fe7bc03..519eaa23 100644 --- a/test/seesaw/test/graphics.clj +++ b/test/seesaw/test/graphics.clj @@ -9,33 +9,33 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.graphics - (:use seesaw.graphics - [seesaw.color :only [to-color]]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)]) - (:import [java.awt RenderingHints] - [java.awt.image BufferedImage])) + (:require + [lazytest.core :refer [defdescribe expect expect-it it]] + [seesaw.color :refer [to-color]] + [seesaw.graphics :refer :all]) + (:import + [java.awt RenderingHints])) -(describe anti-alias +(defdescribe anti-alias-test (it "turns on anti-aliasing on a graphics object" (let [bi (buffered-image 100 100) g2d (.getGraphics bi)] (anti-alias g2d) (expect (= RenderingHints/VALUE_ANTIALIAS_ON (.getRenderingHint g2d RenderingHints/KEY_ANTIALIASING)))))) -(describe to-paint - (it "returns its input if it's a java.awt.Paint" +(defdescribe to-paint-test + (expect-it "returns its input if it's a java.awt.Paint" (= java.awt.Color/BLACK (to-paint java.awt.Color/BLACK))) - (it "falls back to to-color otherwise" + (expect-it "falls back to to-color otherwise" (= (to-color :black) (to-paint :black)))) -(describe line +(defdescribe line-test (it "creates a line shape with given end points" (let [l (line 1 2 3 4)] (expect (= java.awt.geom.Line2D$Double (class l))) (expect (= [1.0 2.0 3.0 4.0] [(.x1 l) (.y1 l) (.x2 l) (.y2 l)]))))) -(describe rect +(defdescribe rect-test (it "creates a rectangle shape with give corner, width and height" (let [r (rect 1 2 3 4)] (expect (= java.awt.geom.Rectangle2D$Double (class r))) @@ -49,7 +49,7 @@ (expect (= java.awt.geom.Rectangle2D$Double (class r))) (expect (= [1.0 2.0 3.0 3.0] [(.x r) (.y r) (.width r) (.height r)]))))) -(describe rounded-rect +(defdescribe rounded-rect-test (it "creates a rounded rectangle shape with give corner, width and height and radii" (let [r (rounded-rect 1 2 3 4 5 6)] (expect (= java.awt.geom.RoundRectangle2D$Double (class r))) @@ -66,7 +66,7 @@ (expect (= [1.0 2.0 3.0 4.0] [(.x r) (.y r) (.width r) (.height r)])) (expect (= [5.0 5.0] [(.arcwidth r) (.archeight r)]))))) -(describe ellipse +(defdescribe ellipse-test (it "creates an elliptical shape with give corner, width and height" (let [r (ellipse 1 2 3 4)] (expect (= java.awt.geom.Ellipse2D$Double (class r))) @@ -80,13 +80,13 @@ (expect (= java.awt.geom.Ellipse2D$Double (class r))) (expect (= [1.0 2.0 3.0 3.0] [(.x r) (.y r) (.width r) (.height r)]))))) -(describe circle +(defdescribe circle-test (it "creates a circle with center and radius" (let [r (circle 4 5 6)] (expect (= java.awt.geom.Ellipse2D$Double (class r))) (expect (= [-2.0 -1.0 12.0 12.0] [(.x r) (.y r) (.width r) (.height r)]))))) -(describe arc +(defdescribe arc-test (it "creates an arc shape with corner, width, height and angle" (let [s (arc 1 2 3 4 0 360)] (expect (= java.awt.geom.Arc2D$Double (class s))) @@ -100,7 +100,7 @@ (expect (= [9.0 18.0 3.0 4.0 0.0 360.0] [(.x s) (.y s) (.width s) (.height s) (.start s) (.extent s)]))))) -(describe chord +(defdescribe chord-test (it "creates an chord shape with corner, width, height and angle" (let [s (chord 1 2 3 4 0 360)] (expect (= java.awt.geom.Arc2D$Double (class s))) @@ -114,7 +114,7 @@ (expect (= [7.0 17.0 3.0 4.0 0.0 360.0] [(.x s) (.y s) (.width s) (.height s) (.start s) (.extent s)]))))) -(describe pie +(defdescribe pie-test (it "creates an pie shape with corner, width, height and angle" (let [s (pie 1 2 3 4 0 360)] (expect (= java.awt.geom.Arc2D$Double (class s))) @@ -128,11 +128,11 @@ (expect (= [8.0 16.0 3.0 4.0 0.0 360.0] [(.x s) (.y s) (.width s) (.height s) (.start s) (.extent s)]))))) -(describe string-shape - (it "creates a string shape" +(defdescribe string-shape-test + (expect-it "creates a string shape" (string-shape 1 2 "HI"))) -(describe stroke +(defdescribe stroke-test (it "creates a default stroke of width 1 with no args" (let [s (stroke)] (expect (= java.awt.BasicStroke (class s))) @@ -149,14 +149,14 @@ (expect (= 2.0 (.getDashPhase s))) (expect (= java.awt.BasicStroke/JOIN_BEVEL (.getLineJoin s)))))) -(describe to-stroke - (it "throws IllegalArgumentException if it doesn't know what to do" +(defdescribe to-stroke-test + (expect-it "throws IllegalArgumentException if it doesn't know what to do" (try - (do (to-stroke #"what?") false) + (to-stroke #"what?") false (catch IllegalArgumentException e true))) - (it "returns nil for nil input" + (expect-it "returns nil for nil input" (nil? (to-stroke nil))) - (it "returns a stroke of a given width if input is a number" + (expect-it "returns a stroke of a given width if input is a number" (= 10.0 (.getLineWidth (to-stroke 10)))) (it "returns input if it's a stroke" (let [s (stroke)] @@ -171,7 +171,7 @@ ; tries to print a cyclical structure when there's a failure. (swap! received-args conj [g2d "this" style]))) -(describe draw +(defdescribe draw-test (it "should call Draw/draw* with graphics, shape and style" (let [args (atom []) ts (TestShape. args) @@ -188,7 +188,7 @@ (expect (= "graphics" result)) (expect (= [["graphics" "this" "style"]["graphics" "this" "style2"]] final-args))))) -(describe style +(defdescribe style-test (it "creates a new style object" (let [strk (stroke :width 5) s (style :foreground :black :background :white :stroke strk :font :monospace)] @@ -197,7 +197,7 @@ (expect (= strk (:stroke s))) (expect (not (nil? (:font s))))))) -(describe update-style +(defdescribe update-style-test (it "constructs a new style with new property values" (let [strk (stroke :width 5) s (update-style (style :foreground :black :stroke strk) :foreground :white :background :black)] @@ -210,7 +210,7 @@ (expect (instance? seesaw.graphics.Style s)) (expect (nil? (:foreground s)))))) -(describe linear-gradient +(defdescribe linear-gradient-test (it "creates a default linear gradient" (let [g (linear-gradient)] (expect (= (java.awt.geom.Point2D$Float. 0.0 0.0) @@ -241,7 +241,7 @@ (expect (= java.awt.MultipleGradientPaint$CycleMethod/REPEAT (.getCycleMethod g)))))) -(describe radial-gradient +(defdescribe radial-gradient-test (it "creates a default radial gradient" (let [g (radial-gradient)] (expect (= (java.awt.geom.Point2D$Float. 0.0 0.0) diff --git a/test/seesaw/test/icon.clj b/test/seesaw/test/icon.clj index 0d391dee..3c62fef9 100644 --- a/test/seesaw/test/icon.clj +++ b/test/seesaw/test/icon.clj @@ -9,14 +9,14 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.icon - (:use seesaw.icon) - (:require [seesaw.graphics :as g] - [clojure.java.io :as jio]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [clojure.java.io :as jio] + [lazytest.core :refer [defdescribe expect expect-it it]] + [seesaw.graphics :as g] + [seesaw.icon :refer [icon]])) -(describe icon - (it "returns nil given nil" +(defdescribe icon-test + (expect-it "returns nil given nil" (nil? (icon nil))) (it "returns its input given an Icon" (let [i (javax.swing.ImageIcon.)] diff --git a/test/seesaw/test/invoke.clj b/test/seesaw/test/invoke.clj index c71aeaa2..02f0a2e6 100644 --- a/test/seesaw/test/invoke.clj +++ b/test/seesaw/test/invoke.clj @@ -9,16 +9,16 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.invoke - (:use seesaw.invoke) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe expect expect-it it]] + [seesaw.invoke :refer :all])) -(describe invoke-now - (it "should execute code on the swing thread, wait, and return the result" +(defdescribe invoke-now-test + (expect-it "should execute code on the swing thread, wait, and return the result" (invoke-now (javax.swing.SwingUtilities/isEventDispatchThread)))) -(describe invoke-soon - (it "should execute code and return the result immediately if executed on the swing thread" +(defdescribe invoke-soon-test + (expect-it "should execute code and return the result immediately if executed on the swing thread" (= {:foo :hi :edt? true} (invoke-now (invoke-soon {:foo :hi :edt? (javax.swing.SwingUtilities/isEventDispatchThread)})))) @@ -30,7 +30,7 @@ (deliver p {:edt? (javax.swing.SwingUtilities/isEventDispatchThread)})))) (expect (= {:edt? true} @p))))) -(describe signaller* +(defdescribe signaller*-test (it "should not invoke a call if one is already in flight" (let [call-count (atom 0) signal (signaller* #(swap! % inc))] diff --git a/test/seesaw/test/keymap.clj b/test/seesaw/test/keymap.clj index 03c3c1d5..1cc9ea17 100644 --- a/test/seesaw/test/keymap.clj +++ b/test/seesaw/test/keymap.clj @@ -9,14 +9,14 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.keymap - (:use [seesaw.keymap] - [seesaw.core :only [button action]] - [seesaw.keystroke :only [keystroke]]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe describe expect it]] + [seesaw.core :refer [action button]] + [seesaw.keymap :refer [map-key]] + [seesaw.keystroke :refer [keystroke]])) -(describe map-key - (testing "a keystroke and action" +(defdescribe map-key-test + (describe "a keystroke and action" (it "maps the key to the action in :descendants scope by default" (let [b (button) k (keystroke "A") @@ -32,7 +32,7 @@ id (.. b (getInputMap javax.swing.JComponent/WHEN_FOCUSED) (get k))] (expect (= a (.. b (getActionMap) (get id))))))) - (testing "a keystroke and a function" + (describe "a keystroke and a function" (it "maps the key to an action that calls the function" (let [b (button) k (keystroke "A") @@ -54,7 +54,7 @@ (remove-fn) (expect (nil? (.. b (getActionMap) (get id)))))) - (testing "a keystroke and a button" + (describe "a keystroke and a button" (it "maps the key to .doClick on the button" (let [k (keystroke "A") called (atom nil) @@ -69,4 +69,3 @@ _ (map-key b k b :id :foo :scope :global) id (.. b (getInputMap javax.swing.JComponent/WHEN_IN_FOCUSED_WINDOW) (get k))] (expect (= id :foo))))) - diff --git a/test/seesaw/test/keystroke.clj b/test/seesaw/test/keystroke.clj index 51f3e140..adb8246f 100644 --- a/test/seesaw/test/keystroke.clj +++ b/test/seesaw/test/keystroke.clj @@ -9,20 +9,21 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.keystroke - (:use seesaw.keystroke) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)]) - (:import [javax.swing KeyStroke] - [java.awt Toolkit])) + (:require + [lazytest.core :refer [defdescribe expect expect-it it]] + [seesaw.keystroke :refer [keystroke]]) + (:import + [java.awt Toolkit] + [javax.swing KeyStroke])) -(describe keystroke +(defdescribe keystroke-test (it "creates a keystroke from a descriptor string" (let [ks (keystroke "ctrl S")] (expect (= KeyStroke (class ks))) (expect (= java.awt.event.KeyEvent/VK_S (.getKeyCode ks)))))) -(describe keystroke - (it "returns nil for nil input" +(defdescribe keystroke-test + (expect-it "returns nil for nil input" (nil? (keystroke nil))) (it "returns input if it's a KeyStroke" (let [ks (KeyStroke/getKeyStroke "alt X")] diff --git a/test/seesaw/test/layout.clj b/test/seesaw/test/layout.clj index 00cbe954..48fcc13c 100644 --- a/test/seesaw/test/layout.clj +++ b/test/seesaw/test/layout.clj @@ -9,15 +9,15 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.layout - (:use [seesaw.layout]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe expect expect-it it]] + [seesaw.layout :refer [handle-structure-change realize-grid-bag-constraints]])) -(describe handle-structure-change - (it "should successfully handle all kinds of components" +(defdescribe handle-structure-change-test + (expect-it "should successfully handle all kinds of components" (handle-structure-change (proxy [java.awt.Component] [])))) -(describe realize-grid-bag-constraints +(defdescribe realize-grid-bag-constraints-test (it "should return a vector of widget/constraint pairs" (let [[[w0 c0] [w1 c1] & more] (realize-grid-bag-constraints [[:first :weightx 99 :weighty 555 :gridx :relative] [:second :weightx 100 :anchor :baseline]])] (expect (nil? more)) diff --git a/test/seesaw/test/make_widget.clj b/test/seesaw/test/make_widget.clj index 25d48687..93637b80 100644 --- a/test/seesaw/test/make_widget.clj +++ b/test/seesaw/test/make_widget.clj @@ -9,7 +9,6 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.make-widget - (:use seesaw.make-widget) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) - + (:require + [lazytest.core] + [seesaw.make-widget])) diff --git a/test/seesaw/test/meta.clj b/test/seesaw/test/meta.clj index 41b4b212..ed56f6b1 100644 --- a/test/seesaw/test/meta.clj +++ b/test/seesaw/test/meta.clj @@ -9,36 +9,36 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.meta - (:use seesaw.meta) - (:use seesaw.action) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe describe expect expect-it it]] + [seesaw.action :refer [action]] + [seesaw.meta :refer [get-meta put-meta!]])) -(describe get-meta - (testing "when called on a JComponent" - (it "returns nil if the key is not found" +(defdescribe get-meta-test + (describe "when called on a JComponent" + (expect-it "returns nil if the key is not found" (nil? (get-meta (javax.swing.JLabel.) :unknown-key)))) - (testing "when called on an Action" - (it "returns nil if the key is not found" + (describe "when called on an Action" + (expect-it "returns nil if the key is not found" (nil? (get-meta (action) :unknown-key)))) - (testing "when called on an arbitrary object" - (it "returns nil if the key is not found" + (describe "when called on an arbitrary object" + (expect-it "returns nil if the key is not found" (nil? (get-meta (javax.swing.JFrame.) :unknown-key))))) -(describe put-meta! - (testing "when called on a JComponent" +(defdescribe put-meta!-test + (describe "when called on a JComponent" (it "stores metadata in the component's client properties" (let [c (javax.swing.JLabel.) result (put-meta! c :some-key 100)] (expect (= c result)) (expect (= 100 (.getClientProperty c :some-key)))))) - (testing "when called on an Action" + (describe "when called on an Action" (it "stores metadata in the actions property map" (let [a (action) result (put-meta! a :some-key 100)] (expect (= a result)) (expect (= 100 (.getValue a (str :some-key))))))) - (testing "when called on Object" + (describe "when called on Object" (it "stores metadata somewhere, retrievable by get-meta" (let [f (javax.swing.JFrame.) result (put-meta! f :some-key 10000)] diff --git a/test/seesaw/test/mig.clj b/test/seesaw/test/mig.clj index 6775f02b..d5dbe4ca 100644 --- a/test/seesaw/test/mig.clj +++ b/test/seesaw/test/mig.clj @@ -9,20 +9,21 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.mig - (:use seesaw.mig seesaw.core) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe describe expect expect-it it]] + [seesaw.core :refer :all] + [seesaw.mig :refer [mig-panel]])) -(describe mig-panel - (it "should create a panel with a MigLayout" - (expect (= net.miginfocom.swing.MigLayout (class (.getLayout (mig-panel)))))) +(defdescribe mig-panel-test + (expect-it "should create a panel with a MigLayout" + (= net.miginfocom.swing.MigLayout (class (.getLayout (mig-panel))))) (it "should set MigLayout layout constraints" (let [p (mig-panel :constraints ["wrap 4", "[fill]", "[nogrid]"]) l (.getLayout p)] (expect (= "wrap 4" (.getLayoutConstraints l))) (expect (= "[fill]" (.getColumnConstraints l))) (expect (= "[nogrid]" (.getRowConstraints l))))) - (it "should support the usual default options" + (expect-it "should support the usual default options" (mig-panel :id :mig :class :classy :opaque? false @@ -33,8 +34,8 @@ (let [p (mig-panel :items [[(styled-text) ""]])] (-> (frame :content (vertical-panel :items [p])) pack!)))) -(describe replace! - (testing "when called on a panel with a mig layout" +(defdescribe replace!-test + (describe "when called on a panel with a mig layout" (it "replaces the given widget with a new widget and maintains constraints" (let [l0 (label "l0") l1 (label "l1") diff --git a/test/seesaw/test/mouse.clj b/test/seesaw/test/mouse.clj index a96b1257..df9e9931 100644 --- a/test/seesaw/test/mouse.clj +++ b/test/seesaw/test/mouse.clj @@ -9,9 +9,9 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.mouse - (:require [seesaw.mouse :as mouse]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe describe expect it]] + [seesaw.mouse :as mouse])) (defn- fake-event [[x y] modex btn] (java.awt.event.MouseEvent. @@ -20,26 +20,26 @@ x, y, 1, false, btn)) -(describe mouse/location - (testing "with no arguments" +(defdescribe location-test + (describe "with no arguments" (it "returns the [x y] mouse location on the whole screen" (let [[x y] (mouse/location) p (.getLocation (java.awt.MouseInfo/getPointerInfo))] (expect (= (.x p) x)) (expect (= (.y p) y))))) - (testing "with a MouseEvent argument" + (describe "with a MouseEvent argument" (it "returns the [x y] of the event" (let [e (fake-event [123 456] 0 0)] (expect (= [123 456] (mouse/location e))))))) -(describe mouse/button-down? - (testing "with a MouseEvent" +(defdescribe button-down?-test + (describe "with a MouseEvent" (it "returns true if the button is down" (let [e (fake-event [0 0] java.awt.event.InputEvent/BUTTON2_DOWN_MASK 0)] (expect (mouse/button-down? e :center)))))) -(describe mouse/button - (testing "with a MouseEvent" +(defdescribe button-test + (describe "with a MouseEvent" (it "returns the button whose state changed" (let [e (fake-event [0 0] 0 java.awt.event.MouseEvent/BUTTON3)] (expect (= :right (mouse/button e))))))) diff --git a/test/seesaw/test/options.clj b/test/seesaw/test/options.clj index 84549d08..569749e5 100644 --- a/test/seesaw/test/options.clj +++ b/test/seesaw/test/options.clj @@ -9,37 +9,36 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.options - (:require [j18n.core :as j18n]) - (:use seesaw.options - [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe expect expect-it it]] + [seesaw.options :refer :all])) -(describe apply-options - (it "throws IllegalArgumentException if properties aren't even" +(defdescribe apply-options-test + (expect-it "throws IllegalArgumentException if properties aren't even" (try - (do (apply-options (javax.swing.JPanel.) [1 2 3]) false) + (apply-options (javax.swing.JPanel.) [1 2 3]) false (catch IllegalArgumentException e true))) - (it "throws IllegalArgumentException for an unknown property" + (expect-it "throws IllegalArgumentException for an unknown property" (try - (do (apply-options (javax.swing.JPanel.) [:unknown "unknown"]) false) + (apply-options (javax.swing.JPanel.) [:unknown "unknown"]) false (catch IllegalArgumentException e true))) - (it "throws IllegalArgumentException for a property with no setter" + (expect-it "throws IllegalArgumentException for a property with no setter" (try - (do - (apply-options (javax.swing.JPanel.) - [:no-setter "no-setter"]) false) + (apply-options (javax.swing.JPanel.) + [:no-setter "no-setter"]) + false (catch IllegalArgumentException e true)))) -(describe get-option-value - (it "throws IllegalArgumentException if target has no handler map" +(defdescribe get-option-value-test + (expect-it "throws IllegalArgumentException if target has no handler map" (try (get-option-value (javax.swing.JPanel.) :text) false (catch IllegalArgumentException e true))) - (it "throws IllegalArgumentException if option doesn't support getter" + (expect-it "throws IllegalArgumentException if option doesn't support getter" (try (get-option-value (javax.swing.JPanel.) :text [{:text (default-option :text nil nil)}]) false (catch IllegalArgumentException e true))) - (it "uses the getter of an option to retrieve a value" + (expect-it "uses the getter of an option to retrieve a value" (= "hi" (get-option-value (javax.swing.JPanel.) :text @@ -55,8 +54,8 @@ ;(expect (= "expected text" (.getText l))) ;(expect (= "expected name" (.getName l)))))) -(describe around-option - (it "calls the provided converter after calling the getter from the wrapped option" +(defdescribe around-option-test + (expect-it "calls the provided converter after calling the getter from the wrapped option" (= 100 (get-option-value nil :foo [{:foo (around-option diff --git a/test/seesaw/test/pref.clj b/test/seesaw/test/pref.clj index 669b3e83..dbbb4fd4 100644 --- a/test/seesaw/test/pref.clj +++ b/test/seesaw/test/pref.clj @@ -9,21 +9,21 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.pref - (:use seesaw.pref) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe expect it]] + [seesaw.pref :refer :all])) -(describe preference-atom +(defdescribe preference-atom-test (it "should return an atom with nil as its default value" - (do (.remove (preferences-node) (pr-str "key")) - (let [atom (preference-atom "key")] - (expect (nil? @atom))))) + (.remove (preferences-node) (pr-str "key")) + (let [atom (preference-atom "key")] + (expect (nil? @atom)))) (it "should return an atom with the specified default value" - (do (.remove (preferences-node) (pr-str "key")) - (let [atom (preference-atom "key" 'some-value)] - (expect (= @atom 'some-value))))) + (.remove (preferences-node) (pr-str "key")) + (let [atom (preference-atom "key" 'some-value)] + (expect (= @atom 'some-value)))) (it "should keep pref in sync with atom" - (do (.remove (preferences-node) (pr-str "key")) - (let [atom (preference-atom "key")] - (reset! atom 'new-value) - (expect (= (read-string (.get (preferences-node) (pr-str "key") "nil")) 'new-value)))))) + (.remove (preferences-node) (pr-str "key")) + (let [atom (preference-atom "key")] + (reset! atom 'new-value) + (expect (= (read-string (.get (preferences-node) (pr-str "key") "nil")) 'new-value))))) diff --git a/test/seesaw/test/rsyntax.clj b/test/seesaw/test/rsyntax.clj index 330a7e06..9cd923a6 100644 --- a/test/seesaw/test/rsyntax.clj +++ b/test/seesaw/test/rsyntax.clj @@ -10,11 +10,10 @@ (ns seesaw.test.rsyntax (:require [seesaw.rsyntax :as rsyntax] - [seesaw.core :as core]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + [lazytest.core :refer [defdescribe expect it]] + [seesaw.core :as core])) -(describe text-area +(defdescribe text-area-test (it "creates a text area" (let [ta (rsyntax/text-area :syntax :clojure)] (expect (instance? org.fife.ui.rsyntaxtextarea.RSyntaxTextArea ta)) diff --git a/test/seesaw/test/scroll.clj b/test/seesaw/test/scroll.clj index 8b9c68aa..d6db5bdb 100644 --- a/test/seesaw/test/scroll.clj +++ b/test/seesaw/test/scroll.clj @@ -9,16 +9,17 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.scroll - (:use seesaw.scroll - seesaw.core) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe describe expect it]] + [seesaw.core :refer :all] + [seesaw.scroll :refer :all])) -(defn make-test-table [] (table :model [:columns [:a :b] :rows [[0 1] [2 3] [3 4] [4 5]]])) +(defn make-test-table [] + (table :model [:columns [:a :b] :rows [[0 1] [2 3] [3 4] [4 5]]])) ; Most of these don't test anything, only exercise the code -(describe scroll!* - (testing "given an arbitrary component" +(defdescribe scroll!*-test + (describe "given an arbitrary component" (it "can scroll to :top" (let [p (canvas) s (scrollable p)] @@ -44,13 +45,13 @@ s (scrollable p)] (scroll!* p :to [:rect 10 10 20 20])))) - (testing "given a listbox (JList)" + (describe "given a listbox (JList)" (it "can scroll to [:row n]" (let [lb (listbox :model [1 2 3 4 5]) s (scrollable lb)] (scroll!* lb :to [:row 3])))) - (testing "given a table (JTable)" + (describe "given a table (JTable)" (it "can scroll to [:row n]" (let [t (make-test-table) s (scrollable t)] @@ -64,7 +65,7 @@ s (scrollable t)] (scroll!* t :to [:cell 3 1])))) - (testing "given a test component" + (describe "given a test component" (it "can scroll to [:line n]" (let [t (text :multi-line? true :text "\n\n\n\n") s (scrollable t)] diff --git a/test/seesaw/test/selection.clj b/test/seesaw/test/selection.clj index e6dbe70a..f4424a9c 100644 --- a/test/seesaw/test/selection.clj +++ b/test/seesaw/test/selection.clj @@ -9,22 +9,22 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.selection - (:require [seesaw.core :as sc]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)] - seesaw.selection - seesaw.action)) - -(describe selection - (testing "when given an Action" - (it "returns nil when the action is not selected" - (nil? (selection (action) ))) - (it "returns a single-element seq with true if the action is selected and multi? is given" + (:require + [lazytest.core :refer [defdescribe describe expect expect-it it]] + [seesaw.core :as sc] + [seesaw.selection :refer :all] + [seesaw.action :refer [action]])) + +(defdescribe selection-test + (describe "when given an Action" + (expect-it "returns nil when the action is not selected" + (nil? (selection (action)))) + (expect-it "returns a single-element seq with true if the action is selected and multi? is given" (= [true] (selection (action :selected? true) {:multi? true}))) - (it "returns a single-element seq with true if the action is selected" + (expect-it "returns a single-element seq with true if the action is selected" (= true (selection (action :selected? true))))) - (testing "when given an AbstractButton (e.g. toggle or checkbox)" - (it "returns false when the button is not selected" + (describe "when given an AbstractButton (e.g. toggle or checkbox)" + (expect-it "returns false when the button is not selected" (false? (selection (javax.swing.JCheckBox. "something" false)))) (it "returns true if it is selected" (let [b (javax.swing.JCheckBox. "something" true)] @@ -33,21 +33,21 @@ (let [b (javax.swing.JCheckBox. "something" true)] (expect (= [true] (selection b {:multi? true})))))) - (testing "when given a ButtonGroup" - (it "returns nil when no button is selected" + (describe "when given a ButtonGroup" + (expect-it "returns nil when no button is selected" (nil? (selection (sc/button-group :buttons [(sc/toggle) (sc/radio)])))) (it "returns the first selected button in the group" (let [b (sc/toggle :selected? true)] (expect (= b (selection (sc/button-group :buttons [(sc/toggle) b (sc/radio)]))))))) - (testing "when given a ComboBox" - (it "returns nil when nothing is selected" + (describe "when given a ComboBox" + (expect-it "returns nil when nothing is selected" (nil? (selection (javax.swing.JComboBox.)))) - (it "returns a single-element seq with the selected value when multi? is true" + (expect-it "returns a single-element seq with the selected value when multi? is true" (= [1] (selection (javax.swing.JComboBox. (to-array [1 2 3 4])) {:multi? true})))) - (testing "when given a JTree" - (it "returns nil when the selection is empty" + (describe "when given a JTree" + (expect-it "returns nil when the selection is empty" (nil? (selection (javax.swing.JTree.)))) (it "returns the selection as a seq of paths when it isn't empty" (let [jtree (javax.swing.JTree. (to-array [1 2 3 4 5]))] @@ -58,8 +58,8 @@ (expect (= [["root" 2] ["root" 3] ["root" 4]] (map (fn [path] (map #(.getUserObject %) path)) (selection jtree {:multi? true}))))))) - (testing "when given a JList" - (it "returns nil when the selection is empty" + (describe "when given a JList" + (expect-it "returns nil when the selection is empty" (nil? (selection (javax.swing.JList.)))) (it "returns the selection when it isn't empty" (let [jlist (javax.swing.JList. (to-array [1 2 3 4 5 6 7]))] @@ -67,24 +67,24 @@ (expect (= 2 (selection jlist))) (expect (= [2 3 4] (selection jlist {:multi? true})))))) - (testing "when given a JSlider" - (it "returns the current value" + (describe "when given a JSlider" + (expect-it "returns the current value" (= 32 (selection (sc/slider :min 0 :max 100 :value 32))))) - (testing "when given a JSpinner" - (it "returns the current value" + (describe "when given a JSpinner" + (expect-it "returns the current value" (= 32 (selection (sc/spinner :model (sc/spinner-model 32 :from 30 :to 35)))))) - (testing "when given a JTextComponent" - (it "returns nil when the selection is empty" + (describe "when given a JTextComponent" + (expect-it "returns nil when the selection is empty" (nil? (selection (javax.swing.JTextField. "HELLO")))) (it "returns a range vector [start end] when the selection is non-empty" (let [t (javax.swing.JTextField. "HELLO")] (.select t 2 4) (expect (= [2 4] (selection t)))))) - (testing "when given a JTabbedPane" - (it "returns nil when there are no tabs" + (describe "when given a JTabbedPane" + (expect-it "returns nil when there are no tabs" (nil? (selection (javax.swing.JTabbedPane.)))) (it "returns {:index i :title \"the title\" :content widget} for the selected tab" (let [a (sc/label :text "A") @@ -101,8 +101,8 @@ (.setSelectedIndex tp 2) (expect (= {:title c-title :content c-content :index 2} (selection tp)))))) - (testing "when given a JTable" - (it "returns nil when no rows are selected" + (describe "when given a JTable" + (expect-it "returns nil when no rows are selected" (nil? (selection (javax.swing.JTable.)))) (it "returns a seq of selected model row indices when selection is non-empty" (let [jtable (javax.swing.JTable. 5 3)] @@ -111,62 +111,57 @@ (expect (= 1 (selection jtable))))))) -(describe selection! - (testing "when given an AbstractButton (e.g. toggle or checkbox) and an argument" +(defdescribe selection!-test + (describe "when given an AbstractButton (e.g. toggle or checkbox) and an argument" (it "deselects the button if the argument is nil" (let [cb (javax.swing.JCheckBox. "something" true)] - (do - (expect (= cb (selection! cb nil))) - (expect (false? (selection cb)))))) + (expect (= cb (selection! cb nil))) + (expect (false? (selection cb))))) (it "selects the button if the argument is truthy" (let [cb (javax.swing.JCheckBox. "something" false)] - (do - (expect (= cb (selection! cb "true"))) - (expect (selection cb)))))) + (expect (= cb (selection! cb "true"))) + (expect (selection cb))))) - (testing "when given a ButtonGroup and an argument" + (describe "when given a ButtonGroup and an argument" (it "deselects the button if the argument is nil" (let [bg (sc/button-group :buttons [(sc/toggle) (sc/radio :selected? true) (sc/radio)])] - (do - (expect (= bg (selection! bg nil))) - (expect (nil? (selection bg)))))) + (expect (= bg (selection! bg nil))) + (expect (nil? (selection bg))))) (it "selects a button if the argument is a button" (let [b (sc/radio) bg (sc/button-group :buttons [(sc/toggle :selected? true) b (sc/radio)])] - (do - (expect (= bg (selection! bg b))) - (expect (= b (selection bg))) - (expect (.isSelected b)))))) + (expect (= bg (selection! bg b))) + (expect (= b (selection bg))) + (expect (.isSelected b))))) - (testing "when given a ComboBox and an argument" + (describe "when given a ComboBox and an argument" (it "sets the selection to that argument" (let [cb (javax.swing.JComboBox. (to-array [1 2 3 4]))] - (do - (expect (= cb (selection! cb 3))) - (expect (= 3 (selection cb))))))) + (expect (= cb (selection! cb 3))) + (expect (= 3 (selection cb)))))) - (testing "when given a JSlider and an argument" + (describe "when given a JSlider and an argument" (it "sets the slider value to that argument" (let [s (sc/slider :min 0 :max 100 :value 0) result (selection! s 32)] (expect (= result s)) (expect (= 32 (.getValue s)))))) - (testing "when given a JSpinner and an argument" + (describe "when given a JSpinner and an argument" (it "sets the spinner value to that argument" (let [s (sc/spinner :model (sc/spinner-model 30 :from 30 :to 35)) result (selection! s 32)] (expect (= result s)) (expect (= 32 (.getValue s)))))) - (testing "when given a JTree and an argument" + (describe "when given a JTree and an argument" (it "Clears the selection when the argument is nil" (let [jtree (javax.swing.JTree. (to-array [1 2 3 4 5]))] (.setSelectionInterval jtree 1 3) (expect (= jtree (selection! jtree nil))) (expect (nil? (selection jtree)))))) - (testing "when given a JList and an argument" + (describe "when given a JList and an argument" (it "Clears the selection when the argument is nil" (let [jlist (javax.swing.JList. (to-array [1 2 3 4 5 6 7]))] (.setSelectionInterval jlist 1 3) @@ -178,7 +173,7 @@ (expect (= ["test" 4 6] (selection jlist {:multi? true}))) (expect (= "test" (selection jlist)))))) - (testing "when given a text component" + (describe "when given a text component" (it "Clears the selection when the argument is nil" (let [t (javax.swing.JTextArea. "This is some text with a selection")] (.select t 5 10) @@ -189,7 +184,7 @@ (selection! t [4 9]) (expect (= [4 9] (selection t)))))) - (testing "when given a JTabbedPane" + (describe "when given a JTabbedPane" (it "selects a tab by title when given a string" (let [tp (sc/tabbed-panel :tabs [{:title "A" :content "A"} {:title "B" :content "B"}])] @@ -221,7 +216,7 @@ (selection! tp {:content b}) (expect (= 1 (.getSelectedIndex tp)))))) - (testing "when given a JTable and an argument" + (describe "when given a JTable and an argument" (it "Clears the row selection when the argument is nil" (let [jtable (javax.swing.JTable. 5 3)] (.setRowSelectionInterval jtable 1 3) diff --git a/test/seesaw/test/selector.clj b/test/seesaw/test/selector.clj index 212f4500..120c0f75 100644 --- a/test/seesaw/test/selector.clj +++ b/test/seesaw/test/selector.clj @@ -9,85 +9,85 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.selector - (:use seesaw.selector) - (:require [seesaw.core :as core]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe expect it]] + [seesaw.core :as sc] + [seesaw.selector :refer :all])) -(describe select +(defdescribe select-test (it "should find a widget by type, loosely allowing for sub-classing" - (let [c (core/label) - d (core/label) - b (core/toggle) - p (core/flow-panel :items [c d b]) - f (core/frame :title "select by type" :content p)] + (let [c (sc/label) + d (sc/label) + b (sc/toggle) + p (sc/flow-panel :items [c d b]) + f (sc/frame :title "select by type" :content p)] (expect (= [c d] (select f [:]))) (expect (= [b] (select f [""]))))) (it "should find a widget by type, strictly" (let [c (proxy [javax.swing.JLabel] []) ; should be ignored d (javax.swing.JLabel.) ; not ignored - b (core/toggle) ; should be ignored - p (core/flow-panel :items [c d b]) - f (core/frame :title "select by type" :content p)] + b (sc/toggle) ; should be ignored + p (sc/flow-panel :items [c d b]) + f (sc/frame :title "select by type" :content p)] (expect (= [d] (select f [:]))) (expect (= nil (seq (select f [""])))))) (it "should find a widget by Java class name" (let [c (proxy [javax.swing.JLabel] []) - d (core/label) - b (core/toggle) - p (core/flow-panel :items [c d b]) - f (core/frame :title "select by type" :content p)] + d (sc/label) + b (sc/toggle) + p (sc/flow-panel :items [c d b]) + f (sc/frame :title "select by type" :content p)] (expect (= [d] (select f [:JLabel]))) (expect (= nil (seq (select f ["JRadioButton"])))))) (it "should find a widget by class name" (let [c (proxy [javax.swing.JLabel] []) - d (core/label :class :foo) - b (core/toggle :class #{:foo :bar}) - p (core/flow-panel :items [c d b]) - f (core/frame :title "select by class" :content p)] + d (sc/label :class :foo) + b (sc/toggle :class #{:foo :bar}) + p (sc/flow-panel :items [c d b]) + f (sc/frame :title "select by class" :content p)] (expect (= [d b] (select f [:.foo]))) (expect (= [b] (seq (select f [".bar"])))))) (it "should find all descendants of a widget" (let [c (proxy [javax.swing.JLabel] []) - d (core/label) - b (core/toggle) - p2 (core/flow-panel :items [c]) - p (core/flow-panel :id :p :items [p2 d b]) - f (core/frame :title "select by type" :content p)] + d (sc/label) + b (sc/toggle) + p2 (sc/flow-panel :items [c]) + p (sc/flow-panel :id :p :items [p2 d b]) + f (sc/frame :title "select by type" :content p)] (expect (= #{c d b p2} (apply hash-set (select f [:#p :*])))))) (it "should find direct children of a widget" (let [c (proxy [javax.swing.JLabel] []) - d (core/label) - b (core/toggle) - p2 (core/flow-panel :items [c]) - p (core/flow-panel :id :p :items [p2 d b]) - f (core/frame :title "select by type" :content p)] + d (sc/label) + b (sc/toggle) + p2 (sc/flow-panel :items [c]) + p (sc/flow-panel :id :p :items [p2 d b]) + f (sc/frame :title "select by type" :content p)] (expect (= #{d b p2} (apply hash-set (select f [:#p :> :*])))))) (it "should find a frame by #id and return it" - (let [f (core/frame :id :my-frame)] + (let [f (sc/frame :id :my-frame)] (expect (= [f] (select f [:#my-frame]))))) (it "should find a widget by #id and returns it" - (let [c (core/label :id "hi") - p (core/flow-panel :id :panel :items [c]) - f (core/frame :title "select by id" :content p)] + (let [c (sc/label :id "hi") + p (sc/flow-panel :id :panel :items [c]) + f (sc/frame :title "select by id" :content p)] (expect (= [c] (select f [:#hi]))) (expect (= [p] (select f ["#panel"]))))) (it "should find menu items by id in a frame's menubar" - (let [m (core/menu-item :id :my-menu :text "my-menu") - f (core/frame :title "select menu item" - :menubar (core/menubar :items [(core/menu :text "File" :items [(core/menu :text "Nested" :items [m])])]))] + (let [m (sc/menu-item :id :my-menu :text "my-menu") + f (sc/frame :title "select menu item" + :menubar (sc/menubar :items [(sc/menu :text "File" :items [(sc/menu :text "Nested" :items [m])])]))] (expect (= [m] (select f [:#my-menu]))))) (it "should select all of the components in a tree with :*" - (let [a (core/label) b (core/text) c (core/label) - p (core/flow-panel :items [a b c])] + (let [a (sc/label) b (sc/text) c (sc/label) + p (sc/flow-panel :items [a b c])] (expect (= [p a b c] (select p [:*])))))) diff --git a/test/seesaw/test/style.clj b/test/seesaw/test/style.clj index bb7f7d7a..dc4169f0 100644 --- a/test/seesaw/test/style.clj +++ b/test/seesaw/test/style.clj @@ -9,13 +9,12 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.style - (:use seesaw.style - [seesaw.core :only [border-panel label button config text]] - [seesaw.color :only [to-color]]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require [seesaw.style :refer :all] + [seesaw.core :refer [border-panel label button config text]] + [lazytest.core :refer [defdescribe expect it]] + [seesaw.color :refer [to-color]])) -(describe apply-stylesheet +(defdescribe apply-stylesheet-test (it "returns its input" (let [lbl (label)] diff --git a/test/seesaw/test/swingx.clj b/test/seesaw/test/swingx.clj index 66dbc1e0..0699618f 100644 --- a/test/seesaw/test/swingx.clj +++ b/test/seesaw/test/swingx.clj @@ -9,18 +9,18 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.swingx - (:require [seesaw.core :as core]) - (:require [seesaw.icon :as icon]) - (:require [seesaw.graphics :as graphics]) - (:use seesaw.swingx) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) - -(describe p-built-in - (it "returns built-in predicates by key" + (:require + [lazytest.core :refer [defdescribe expect expect-it it]] + [seesaw.core :as core] + [seesaw.graphics :as graphics] + [seesaw.icon :as icon] + [seesaw.swingx :refer :all])) + +(defdescribe p-built-in-test + (expect-it "returns built-in predicates by key" (= org.jdesktop.swingx.decorator.HighlightPredicate/ROLLOVER_ROW (p-built-in :rollover-row)))) -(describe p-and +(defdescribe p-and-test (it "creates an AndHighlightPredicate with the given parts" (let [expected-parts [:always :never :even :odd] a (apply p-and expected-parts) @@ -31,42 +31,42 @@ p (p-and pat)] (expect (= pat (.getPattern (first (.getHighlightPredicates p)))))))) -(describe p-or +(defdescribe p-or-test (it "creates an OrHighlightPredicate with the given parts" (let [expected-parts [:rollover-row :always :even :odd] a (apply p-or expected-parts) actual-parts (seq (.getHighlightPredicates a))] (expect (= actual-parts (map p-built-in expected-parts)))))) -(describe p-not - (it "creates a NotHighlightPredicate with the given target" +(defdescribe p-not-test + (expect-it "creates a NotHighlightPredicate with the given target" (= (p-built-in :even) (.getHighlightPredicate (p-not :even))))) -(describe p-type - (it "creates a TypeHighlightPredicate with the given class" +(defdescribe p-type-test + (expect-it "creates a TypeHighlightPredicate with the given class" (= String (.getType (p-type String))))) -(describe p-eq - (it "creates a EqualsHighlightPredicate with the given value" +(defdescribe p-eq-test + (expect-it "creates a EqualsHighlightPredicate with the given value" (= "HOWDY" (.getCompareValue (p-eq "HOWDY"))))) -(describe p-column-names - (it "creates a IdentifierHighlighPredicate with the given column ids" +(defdescribe p-column-names-test + (expect-it "creates a IdentifierHighlighPredicate with the given column ids" (= ["a" :b 3] (->> (p-column-names "a" :b 3) .getIdentifiers seq)))) -(describe p-column-indexes - (it "creates a ColumnHighlighPredicate with the given column indexes" +(defdescribe p-column-indexes-test + (expect-it "creates a ColumnHighlighPredicate with the given column indexes" (= [1 2 4] (->> (p-column-indexes 1 2 4) .getColumns seq)))) -(describe p-row-group - (it "creates a RowGroupHighlightPredicate with the given count" +(defdescribe p-row-group-test + (expect-it "creates a RowGroupHighlightPredicate with the given count" (= 6 (.getLinesPerGroup (p-row-group 6))))) -(describe p-depths - (it "creates a DepthHighlighPredicate with the given depths" +(defdescribe p-depths-test + (expect-it "creates a DepthHighlighPredicate with the given depths" (= [1 2 4] (->> (p-depths 1 2 4) .getDepths seq)))) -(describe p-pattern +(defdescribe p-pattern-test (it "creates a PatternHighlighPredicate with the given pattern" (let [pat #"hi"] (expect (= pat (.getPattern (p-pattern pat)))))) @@ -76,7 +76,7 @@ (expect (= 123 (.getTestColumn pat))) (expect (= 456 (.getHighlightColumn pat)))))) -(describe p-fn +(defdescribe p-fn-test (it "creates a Highlighter that calls a two-arg function" (let [called (atom false) p (p-fn (fn [_ _] (reset! called true)))] @@ -84,7 +84,7 @@ (.isHighlighted p nil nil) (expect @called)))) -(describe hl-color +(defdescribe hl-color-test (it "returns a function that creates a highlighter with always predicate" (let [f (hl-color) h1 (f) ] @@ -107,7 +107,7 @@ (expect (= java.awt.Color/GREEN (.getSelectedBackground h))) (expect (= java.awt.Color/BLUE (.getSelectedForeground h)))))) -(describe hl-icon +(defdescribe hl-icon-test (it "returns a function that creates a highlighter with always predicate" (let [f (hl-icon nil) h1 (f) ] @@ -125,7 +125,7 @@ h (f)] (expect (= i (.getIcon h)))))) -(describe hl-shade +(defdescribe hl-shade-test (it "returns a function that creates a highlighter with always predicate" (let [f (hl-shade) h1 (f) ] @@ -138,7 +138,7 @@ (expect (instance? org.jdesktop.swingx.decorator.ShadingColorHighlighter h1)) (expect (= (p-built-in :never) (.getHighlightPredicate h1)))))) -(describe hl-simple-striping +(defdescribe hl-simple-striping-test (it "returns an simple striping" (let [h (hl-simple-striping)] (expect (instance? org.jdesktop.swingx.decorator.Highlighter h)))) @@ -164,10 +164,10 @@ (expect (= [hl#] (core/config w# :highlighters))) true)) -(describe button-x - (it "creates a JXButton" +(defdescribe button-x-test + (expect-it "creates a JXButton" (instance? org.jdesktop.swingx.JXButton (button-x))) - (it "can set text" + (expect-it "can set text" (= "HI" (core/text (button-x :text "HI")))) (it "can set painters" (let [p (org.jdesktop.swingx.painter.BusyPainter.)] @@ -177,16 +177,16 @@ (expect (= p (core/config (button-x :foreground-painter p) :foreground-painter)))))) -(describe label-x - (it "creates a JXLabel" +(defdescribe label-x-test + (expect-it "creates a JXLabel" (instance? org.jdesktop.swingx.JXLabel (label-x))) - (it "can set text" + (expect-it "can set text" (= "HI" (core/text (label-x :text "HI")))) - (it "does not wrap lines by default" + (expect-it "does not wrap lines by default" (not (core/config (label-x :text "HI") :wrap-lines?))) - (it "can set wrap-lines? option" + (expect-it "can set wrap-lines? option" (core/config (label-x :wrap-lines? true) :wrap-lines?)) - (it "can set rotation option" + (expect-it "can set rotation option" (= (Math/toRadians 60.0) (core/config (label-x :text-rotation (Math/toRadians 60.0)) :text-rotation))) (it "can set painters" (let [p (org.jdesktop.swingx.painter.BusyPainter.)] @@ -197,19 +197,19 @@ (label-x :foreground-painter p) :foreground-painter)))))) -(describe busy-label - (it "creates a JXBusyLabel" +(defdescribe busy-label-test + (expect-it "creates a JXBusyLabel" (instance? org.jdesktop.swingx.JXBusyLabel (busy-label))) - (it ":busy? defaults to false" + (expect-it ":busy? defaults to false" (not (core/config (busy-label) :busy?))) - (it "can set :busy?" + (expect-it "can set :busy?" (core/config (busy-label :busy? true) :busy?)) - (it "can set the text of the label" + (expect-it "can set the text of the label" (= "Processing" (core/text (busy-label :text "Processing"))))) ; hyperlink gets grouchy when run on travis with no desktop. (when (java.awt.Desktop/isDesktopSupported) - (describe hyperlink + (defdescribe hyperlink-test (it "creates a JXHyperlink with a URI" (let [hl (hyperlink :uri (java.net.URI. "http://google.com"))] (expect (instance? org.jdesktop.swingx.JXHyperlink hl)))) @@ -217,7 +217,7 @@ (let [hl (hyperlink :uri "http://google.com")] (expect (instance? org.jdesktop.swingx.JXHyperlink hl)))))) -(describe task-pane +(defdescribe task-pane-test (it "creates a JXTaskPane with a title and icon" (let [i (icon/icon (graphics/buffered-image 16 16)) tp (task-pane :title "HI" :icon i)] @@ -230,23 +230,23 @@ tp (task-pane :actions [a b] )] (expect (= 2 (.getComponentCount (.getContentPane tp))))))) -(describe task-pane-container +(defdescribe task-pane-container-test (it "creates a JXTaskPaneContainer with some items" (let [tpc (task-pane-container)] (expect (instance? org.jdesktop.swingx.JXTaskPaneContainer tpc))))) -(describe color-selection-button - (it "creates a JXColorSelectionButton" +(defdescribe color-selection-button-test + (expect-it "creates a JXColorSelectionButton" (instance? org.jdesktop.swingx.JXColorSelectionButton (color-selection-button))) - (it "can set the initial color" - (expect (= java.awt.Color/RED + (expect-it "can set the initial color" + (= java.awt.Color/RED (core/config (color-selection-button :selection java.awt.Color/RED) - :selection)))) - (it "can retrieve the current selection with (seesaw.core/selection)" - (expect (= java.awt.Color/RED - (core/selection - (color-selection-button :selection java.awt.Color/RED))))) + :selection))) + (expect-it "can retrieve the current selection with (seesaw.core/selection)" + (= java.awt.Color/RED + (core/selection + (color-selection-button :selection java.awt.Color/RED)))) (it "can set the current selection with (seesaw.core/selection!)" (let [csb (color-selection-button)] (core/selection! csb java.awt.Color/BLACK) @@ -265,22 +265,22 @@ (core/selection! csb java.awt.Color/YELLOW) (expect (nil? @called))))) -(describe header - (it "creates a JXHeader" +(defdescribe header-test + (expect-it "creates a JXHeader" (instance? org.jdesktop.swingx.JXHeader (header))) - (it "can set a title" + (expect-it "can set a title" (= "The title" (core/config (header :title "The title") :title))) - (it "can set a description" + (expect-it "can set a description" (= "The description" (core/config (header :description "The description") :description))) (it "can set an icon" (let [i (icon/icon (graphics/buffered-image 16 16)) h (header :icon i)] (expect (= i (core/config h :icon)))))) -(describe listbox-x - (it "creates a JXList" +(defdescribe listbox-x-test + (expect-it "creates a JXList" (instance? org.jdesktop.swingx.JXList (listbox-x))) - (it "creates a JXList with rollover enabled" + (expect-it "creates a JXList with rollover enabled" (.isRolloverEnabled (listbox-x))) (it "creates a JXList with a default model" (let [lb (listbox-x :model [1 2 3])] @@ -300,15 +300,15 @@ (let [lb (listbox-x :sort-with < :model [2 1 3 0])] (core/selection! lb 2) (expect (= 2 (core/selection lb))))) - (it "is a highlighter host" + (expect-it "is a highlighter host" (verify-highlighter-host (listbox-x)))) -(describe titled-panel - (it "creates a JXTitledPanel" +(defdescribe titled-panel-test + (expect-it "creates a JXTitledPanel" (instance? org.jdesktop.swingx.JXTitledPanel (titled-panel))) - (it "sets the :title of the panel" + (expect-it "sets the :title of the panel" (= "HI" (.getTitle (titled-panel :title "HI")))) - (it "sets the :title-color of the panel" + (expect-it "sets the :title-color of the panel" (= java.awt.Color/RED (.getTitleForeground (titled-panel :title-color :red)))) (it "sets the :content of the panel" (let [c (core/label "HI") @@ -324,62 +324,62 @@ (expect (= left (.getLeftDecoration tp))) (expect (= right (.getRightDecoration tp)))))) -(describe tree-x - (it "creates a JXTree" +(defdescribe tree-x-test + (expect-it "creates a JXTree" (instance? org.jdesktop.swingx.JXTree (tree-x))) - (it "creates a JXTree with rollover enabled" + (expect-it "creates a JXTree with rollover enabled" (.isRolloverEnabled (tree-x))) - (it "is a highlighter host" + (expect-it "is a highlighter host" (verify-highlighter-host (tree-x)))) -(describe table-x - (it "creates a JTable" +(defdescribe table-x-test + (expect-it "creates a JTable" (instance? org.jdesktop.swingx.JXTable (table-x))) - (it "creates a JXTable with rollover enabled" + (expect-it "creates a JXTable with rollover enabled" (.isRolloverEnabled (table-x))) - (it "creates a JXTable with column control visible" + (expect-it "creates a JXTable with column control visible" (.isColumnControlVisible (table-x))) - (it "creates a sortable JXTable" + (expect-it "creates a sortable JXTable" (.isSortable (table-x))) - (it "can enable horizontal scrollbar" + (expect-it "can enable horizontal scrollbar" (core/config (table-x :horizontal-scroll-enabled? true) :horizontal-scroll-enabled?)) - (it "can show the column control" + (expect-it "can show the column control" (not (core/config (table-x :column-control-visible? false) :column-control-visible?))) - (it "can set the column margin" + (expect-it "can set the column margin" (= 99 (core/config (table-x :column-margin 99) :column-margin))) - (it "is a highlighter host" + (expect-it "is a highlighter host" (verify-highlighter-host (table-x)))) -(describe border-panel-x - (it "creates a JXPanel with border-panel" - (expect (instance? java.awt.BorderLayout - (.getLayout (border-panel-x :alpha 0.5)))))) - -(describe flow-panel-x - (it "creates a JXPanel with flow-panel" - (expect (instance? java.awt.FlowLayout - (.getLayout (flow-panel-x :alpha 0.5)))))) - -(describe horizontal-panel-x - (it "creates a JXPanel with horizontal-panel" - (expect (instance? javax.swing.BoxLayout - (.getLayout (horizontal-panel-x :alpha 0.5)))))) - -(describe vertical-panel-x - (it "creates a JXPanel with vertical-panel" - (expect (instance? javax.swing.BoxLayout - (.getLayout (vertical-panel-x :alpha 0.5)))))) - -(describe grid-panel-x - (it "creates a JXPanel with grid-panel" - (expect (instance? java.awt.GridLayout - (.getLayout (grid-panel-x :alpha 0.5)))))) - -(describe xyz-panel-x - (it "creates a JXPanel with xyz-panel" - (expect (nil? (.getLayout (xyz-panel-x :alpha 0.5)))))) - -(describe card-panel-x - (it "creates a JXPanel with card-panel" - (expect (instance? java.awt.CardLayout - (.getLayout (card-panel-x :alpha 0.5)))))) +(defdescribe border-panel-x-test + (expect-it "creates a JXPanel with border-panel" + (instance? java.awt.BorderLayout + (.getLayout (border-panel-x :alpha 0.5))))) + +(defdescribe flow-panel-x-test + (expect-it "creates a JXPanel with flow-panel" + (instance? java.awt.FlowLayout + (.getLayout (flow-panel-x :alpha 0.5))))) + +(defdescribe horizontal-panel-x-test + (expect-it "creates a JXPanel with horizontal-panel" + (instance? javax.swing.BoxLayout + (.getLayout (horizontal-panel-x :alpha 0.5))))) + +(defdescribe vertical-panel-x-test + (expect-it "creates a JXPanel with vertical-panel" + (instance? javax.swing.BoxLayout + (.getLayout (vertical-panel-x :alpha 0.5))))) + +(defdescribe grid-panel-x-test + (expect-it "creates a JXPanel with grid-panel" + (instance? java.awt.GridLayout + (.getLayout (grid-panel-x :alpha 0.5))))) + +(defdescribe xyz-panel-x-test + (expect-it "creates a JXPanel with xyz-panel" + (nil? (.getLayout (xyz-panel-x :alpha 0.5))))) + +(defdescribe card-panel-x-test + (expect-it "creates a JXPanel with card-panel" + (instance? java.awt.CardLayout + (.getLayout (card-panel-x :alpha 0.5))))) diff --git a/test/seesaw/test/table.clj b/test/seesaw/test/table.clj index a8ee82bd..2e95218d 100644 --- a/test/seesaw/test/table.clj +++ b/test/seesaw/test/table.clj @@ -9,12 +9,12 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.table - (:use seesaw.table) - (:use [lazytest.describe :only (describe it testing given)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe expect expect-it it]] + [seesaw.table :refer :all])) -(describe table-model - (it "should create a table model" +(defdescribe table-model-test + (expect-it "should create a table model" (instance? javax.swing.table.TableModel (table-model))) (it "should create columns from a list of keys" @@ -53,7 +53,7 @@ (expect (= "a1" (.getValueAt t 1 0))) (expect (= "b1" (.getValueAt t 1 1))))) - (it "should throw IllegalArgumentException if an entry in :rows is not a map or vector" + (expect-it "should throw IllegalArgumentException if an entry in :rows is not a map or vector" (try (table-model :columns [:a] :rows [1 2 3 4]) false (catch IllegalArgumentException e true))) @@ -66,7 +66,7 @@ (let [t (table-model :columns [:a :b] :rows [[0 0]])] (expect (not (.isCellEditable t 0 0)))))) -(describe value-at +(defdescribe value-at-test (it "gets the value of a single row index as a map" (let [t (table-model :columns [:a :b] :rows [["a0" "b0"] ["a1" "b1"]])] (expect (= {:a "a0" :b "b0" } (value-at t 0))))) @@ -74,7 +74,7 @@ (let [t (table-model :columns [:a :b] :rows [{:a 0 :b 1 :c 2} {:a 3 :b 4 :d 5}])] (expect (= {:a 0 :b 1 :c 2} (value-at t 0))) (expect (= {:a 3 :b 4 :d 5} (value-at t 1))))) - (it "gets the value of a row as a map (indexed by column names) if model was not + (expect-it "gets the value of a row as a map (indexed by column names) if model was not created with (table-model)" (let [t (javax.swing.table.DefaultTableModel. 2 3)] (expect (= {"A" nil "B" nil "C" nil } (value-at t 0))))) @@ -96,7 +96,7 @@ (try (value-at t 9) (catch Exception e)) (expect (= {:a "bee" :b "cee"} (value-at t 0)))))) -(describe update-at! +(defdescribe update-at!-test (it "updates a row with the same format as :rows option of (table-model)" (let [t (table-model :columns [:a :b] :rows [["a0" "b0"] ["a1" "b1"]]) r (update-at! t 0 ["A0" "B0"])] @@ -132,7 +132,7 @@ (expect (= {:a true} (value-at t 0))) (expect (= {:a false} (value-at t 1)))))) -(describe insert-at! +(defdescribe insert-at!-test (it "inserts a row with the same format as :rows option of (table-model)" (let [t (table-model :columns [:a :b] :rows [["a0" "b0"] ["a1" "b1"]]) r (insert-at! t 0 ["A0" "B0"])] @@ -154,7 +154,7 @@ (expect (= [{:name "A"} {:name "B"}] (value-at t (range (.getRowCount t)))))))) -(describe setRowCount +(defdescribe setRowCount-test (it "can extend the number of rows in the table with nils" (let [t (table-model :columns [:a])] (.setRowCount t 5) @@ -166,7 +166,7 @@ (.setRowCount t 2) (expect (= 2 (row-count t)))))) -(describe remove-at! +(defdescribe remove-at!-test (it "removes a row" (let [t (table-model :columns [:a] :rows (map vector (range 5))) r (remove-at! t 2)] @@ -185,19 +185,19 @@ (expect (= 2 (.getRowCount t))) (expect (= [{:a 0} {:a 4}] (value-at t [0 1])))))) -(describe clear! +(defdescribe clear!-test (it "removes all rows from a table" (let [t (table-model :columns [:a] :rows (map vector (range 5))) r (clear! t)] (expect (= r t)) (expect (= 0 (.getRowCount t)))))) -(describe row-count +(defdescribe row-count-test (it "retrievies number of rows in a table" (let [t (table-model :columns [:a] :rows (map vector (range 5)))] (expect (= 5 (row-count t)))))) -(describe column-count +(defdescribe column-count-test (it "retrievies number of columns in a table" (let [t (table-model :columns [:a :b :c :d])] (expect (= 4 (column-count t)))))) diff --git a/test/seesaw/test/timer.clj b/test/seesaw/test/timer.clj index 09e582f3..d36a58f6 100644 --- a/test/seesaw/test/timer.clj +++ b/test/seesaw/test/timer.clj @@ -9,12 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.timer - (:use seesaw.timer) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)]) - (:import [javax.swing Action])) + (:require + [lazytest.core :refer [defdescribe expect it]] + [seesaw.timer :refer :all])) -(describe timer +(defdescribe timer-test (it "Creates a timer for a handler function and calls it" (let [called (atom nil) t (timer #(inc (reset! called %)) :start? false :initial-value 99)] diff --git a/test/seesaw/test/to_widget.clj b/test/seesaw/test/to_widget.clj index fc4d7543..d5d33326 100644 --- a/test/seesaw/test/to_widget.clj +++ b/test/seesaw/test/to_widget.clj @@ -9,7 +9,6 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.to-widget - (:use seesaw.to-widget) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) - + (:require + [lazytest.core] + [seesaw.to-widget])) diff --git a/test/seesaw/test/tree.clj b/test/seesaw/test/tree.clj index 7cef0d95..886e5ceb 100644 --- a/test/seesaw/test/tree.clj +++ b/test/seesaw/test/tree.clj @@ -9,10 +9,10 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.tree - (:use seesaw.tree) - (:use [seesaw.core :only [listen]]) - (:use [lazytest.describe :only (describe it testing given)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe expect expect-it given it]] + [seesaw.core :refer [listen]] + [seesaw.tree :refer :all])) (defn- tree-listener "Dummy TreeModelListener that calls handler with the received event." @@ -23,13 +23,13 @@ (treeNodesRemoved [this e] (handler e)) (treeStructureChanged [this e] (handler e)))) -(describe simple-tree-model +(defdescribe simple-tree-model-test (given [branch? (fn [node] (= node "dir")) children (fn [node] (when (= node "dir") [1 2 3])) m (simple-tree-model branch? children "dir")] - (it "should create a read-only tree model from branch? and children functions" + (expect-it "should create a read-only tree model from branch? and children functions" (instance? javax.swing.tree.TreeModel m)) - (it "should return the root" + (expect-it "should return the root" (= "dir" (.getRoot m))) (it "should return isLeaf" (expect (.isLeaf m "file")) @@ -37,9 +37,9 @@ (it "should return the child count" (expect (= 0 (.getChildCount m "file"))) (expect (= 3 (.getChildCount m "dir")))) - (it "should return a child by index" + (expect-it "should return a child by index" (= [1 2 3] (map #(.getChild m "dir" %) (range 3)))) - (it "should retrieve the index of a child" + (expect-it "should retrieve the index of a child" (= [0 1 2] (map #(.getIndexOfChild m "dir" %) [1 2 3]))) (it "should allow a listener to be added" (let [called (atom nil)] @@ -61,7 +61,7 @@ (defn- make-test-model [] (simple-tree-model #(.isDirectory %) #(.listFiles %) (java.io.File. "."))) -(describe fire-event +(defdescribe fire-event-test (it "fires nodes-changed events" (let [m (make-test-model) e (atom nil) diff --git a/test/seesaw/test/util.clj b/test/seesaw/test/util.clj index bb0c4294..d1de926a 100644 --- a/test/seesaw/test/util.clj +++ b/test/seesaw/test/util.clj @@ -9,27 +9,29 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.util - (:use seesaw.util) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) - -(describe illegal-argument - (it "throws a formatted illegal argument exception" + (:require + [lazytest.core :refer [defdescribe expect expect-it it]] + [seesaw.util :refer [atom? camelize check-args cond-doto illegal-argument + resource-key? to-dimension to-insets + to-mnemonic-keycode to-seq to-uri to-url try-cast]])) + +(defdescribe illegal-argument-test + (expect-it "throws a formatted illegal argument exception" (try (illegal-argument "This %s a message with code %d" "is" 99) false (catch IllegalArgumentException e (= "This is a message with code 99" (.getMessage e)))))) -(describe check-args - (it "returns true if the condition is true" +(defdescribe check-args-test + (expect-it "returns true if the condition is true" (check-args true "yes!")) - (it "returns throws IllegalArgumentException if condition is false" + (expect-it "returns throws IllegalArgumentException if condition is false" (try - (do (check-args false "no!") false) + (check-args false "no!") false (catch IllegalArgumentException e true)))) -(describe cond-doto - (it "only executes forms with true conditions" +(defdescribe cond-doto-test + (expect-it "only executes forms with true conditions" (= "firstsecondfifth" (str (cond-doto (StringBuilder.) true (.append "first") (> 2 1) (.append "second") @@ -37,58 +39,58 @@ false (.append "fourth") (= "HI" "HI") (.append "fifth")))))) -(describe to-seq +(defdescribe to-seq-test (it "makes a non-seq into a single-element seq" - (= (seq ["hi"]) (to-seq "hi")) - (= (seq [:k]) (to-seq :k))) - (it "makes a collection into a seq" + (expect (= (seq ["hi"]) (to-seq "hi"))) + (expect (= (seq [:k]) (to-seq :k)))) + (expect-it "makes a collection into a seq" (= (seq #{:a :b}) (to-seq #{:a :b})))) -(describe camelize - (it "turns dashes into camel humps" +(defdescribe camelize-test + (expect-it "turns dashes into camel humps" (= "onMouseClicked" (camelize "on-mouse-clicked")))) -(describe boolean? - (it "returns true for true" +(defdescribe boolean?-test + (expect-it "returns true for true" (boolean? true)) - (it "returns true for false" + (expect-it "returns true for false" (boolean? false)) - (it "returns false for nil" + (expect-it "returns false for nil" (not (boolean? nil))) - (it "returns false for non-boolean" + (expect-it "returns false for non-boolean" (not (boolean? "hi")))) -(describe try-cast - (it "returns its input if cast succeeds" +(defdescribe try-cast-test + (expect-it "returns its input if cast succeeds" (= "TEST" (try-cast java.lang.String "TEST"))) - (it "returns nil if input is nil" + (expect-it "returns nil if input is nil" (nil? (try-cast java.lang.String nil))) - (it "returns nil if cast fails" + (expect-it "returns nil if cast fails" (nil? (try-cast java.lang.String 99)))) -(describe to-url +(defdescribe to-url-test (it "returns its input if it is already a URL object" (let [u (java.net.URL. "http://google.com")] (expect (identical? u (to-url u))))) - (it "returns a URL if (str input) is a valid URL" + (expect-it "returns a URL if (str input) is a valid URL" (= "http://darevay.com" (-> (to-url "http://darevay.com") .toExternalForm ))) - (it "returns nil if (str input) is not a valid URL" + (expect-it "returns nil if (str input) is not a valid URL" (nil? (to-url "not a URL")))) -(describe to-uri +(defdescribe to-uri-test (it "returns its input if it is already a URI object" (let [u (java.net.URI. "http://google.com")] (expect (identical? u (to-uri u))))) - (it "returns a URI if (str input) is a valid URI" + (expect-it "returns a URI if (str input) is a valid URI" (= "http://darevay.com" (-> (to-uri "http://darevay.com") .toString ))) - (it "returns nil if (str input) is not a valid URI" + (expect-it "returns nil if (str input) is not a valid URI" (nil? (to-url "not a URI")))) -(describe to-dimension - (it "should throw an exception if it doesn't know what to do" +(defdescribe to-dimension-test + (expect-it "should throw an exception if it doesn't know what to do" (try - (do (to-dimension {:a :map}) false) + (to-dimension {:a :map}) false (catch IllegalArgumentException e true))) (it "should return its input if its already a Dimension" (let [d (java.awt.Dimension. 10 20)] @@ -99,38 +101,38 @@ (expect (= 1 (.width d))) (expect (= 2 (.height d)))))) -(describe to-insets - (it "should throw an exception if it doesn't know what to do" +(defdescribe to-insets-test + (expect-it "should throw an exception if it doesn't know what to do" (try - (do (to-insets "a random string") false) + (to-insets "a random string") false (catch IllegalArgumentException e true))) (it "should return its input if its already an Insets" (let [i (java.awt.Insets. 1 2 3 4)] (expect (= i (to-insets i))))) - (it "should return uniform insets from a number" + (expect-it "should return uniform insets from a number" (= (java.awt.Insets. 9 9 9 9) (to-insets 9))) - (it "should return insets from a 4-element [top, left, bottom, right] vector" + (expect-it "should return insets from a 4-element [top, left, bottom, right] vector" (= (java.awt.Insets. 1 2 3 4) (to-insets [1 2 3 4]))) - (it "should return insets from a 2-element [top/bottom, left/right] vector" + (expect-it "should return insets from a 2-element [top/bottom, left/right] vector" (= (java.awt.Insets. 5 6 5 6) (to-insets [5 6])))) -(describe atom? - (it "should return true for an atom" +(defdescribe atom?-test + (expect-it "should return true for an atom" (atom? (atom nil))) - (it "should return false for a non-atom" + (expect-it "should return false for a non-atom" (not (atom? (ref nil))))) -(describe to-mnemonic-keycode - (it "should pass through an integer key code" +(defdescribe to-mnemonic-keycode-test + (expect-it "should pass through an integer key code" (= 99 (to-mnemonic-keycode 99))) - (it "should convert a character to an integer key code" + (expect-it "should convert a character to an integer key code" (= (int \T) (to-mnemonic-keycode \T))) - (it "should convert a lower-case character to an integer key code" + (expect-it "should convert a lower-case character to an integer key code" (= (int \X) (to-mnemonic-keycode \x)))) -(describe resource-key? - (it "returns true for resource keywords" +(defdescribe resource-key?-test + (expect-it "returns true for resource keywords" (resource-key? ::hello)) - (it "returns false for non-resource keywords" + (expect-it "returns false for non-resource keywords" (not (resource-key? :hello)))) diff --git a/test/seesaw/test/value.clj b/test/seesaw/test/value.clj index 48e78089..274e69c5 100644 --- a/test/seesaw/test/value.clj +++ b/test/seesaw/test/value.clj @@ -9,12 +9,12 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.value - (:use [seesaw.value] - [seesaw.core]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe expect expect-it it]] + [seesaw.core :refer :all] + [seesaw.value :refer :all])) -(describe value* +(defdescribe value*-test (it "returns a map keyed by id for containers" (let [a (label :id :a :text "A") b (text :id :b :text "B") @@ -24,18 +24,18 @@ (expect (= {:a "A" :b "B"} (value* f))))) - (it "returns the value of a progress bar" + (expect-it "returns the value of a progress bar" (= 99 (value* (progress-bar :min 0 :max 100 :value 99)))) - (it "returns the value of a slider" + (expect-it "returns the value of a slider" (= 99 (value* (slider :min 0 :max 100 :value 99)))) - (it "returns the selection of a spinner" + (expect-it "returns the selection of a spinner" (= 101 (value* (selection! (spinner :model [99 100 101 102]) 101)))) (it "returns the selection of a button-y thing (checkbox, button, menu, etc)" (expect (value* (button :selected? true))) - (expect (nil? (value* (button :selected? false))))) + (expect (not (value* (button :selected? false))))) (it "returns the selection of a listbox" (let [cb (listbox :model ["a" "b" "c"])] @@ -54,22 +54,22 @@ (selection! g b) (expect (= b (value* g))))) - (it "returns the text of a label" + (expect-it "returns the text of a label" (= "bye" (value* (javax.swing.JLabel. "bye")))) - (it "returns the text of an editor pane" + (expect-it "returns the text of an editor pane" (= "bye" (value* (editor-pane :text "bye")))) - (it "returns the text of styled-text" + (expect-it "returns the text of styled-text" (= "bye" (value* (styled-text :text "bye")))) - (it "returns the text of a text area" + (expect-it "returns the text of a text area" (= "bye" (value* (javax.swing.JTextArea. "bye")))) - (it "returns the text of a text field" + (expect-it "returns the text of a text field" (= "hi" (value* (javax.swing.JTextField. "hi"))))) -(describe value!* +(defdescribe value!*-test (it "sets the values of widgets with a map keyed by id for containers" (let [a (label :id :a :text "") b (text :id :b :text "") @@ -81,17 +81,17 @@ (expect (= f (value!* f {:a "A" :b "B" :d nil}))) (expect (= {:a "A" :b "B" :c "unchanged" :d ""} (value* f))))) - (it "sets the value of a progress-bar" + (expect-it "sets the value of a progress-bar" (= 99 (-> (progress-bar :min 0 :max 100 :value 98) (value!* 99) value*))) - (it "sets the value of a slider" + (expect-it "sets the value of a slider" (= 99 (-> (slider :min 0 :max 100 :value 98) (value!* 99) value*))) - (it "sets the selection of a spinner" + (expect-it "sets the selection of a spinner" (= 101 (-> (spinner :model [99 100 101 102]) (value!* 101) value))) @@ -122,16 +122,16 @@ (expect (nil? (selection g))) (value!* g b) (expect (= b (value* g))))) - (it "sets the text of an editor-pane" + (expect-it "sets the text of an editor-pane" (= "bar" (-> (editor-pane) (value!* "bar") text))) - (it "sets the text of a styled-text" + (expect-it "sets the text of a styled-text" (= "bar" (-> (styled-text) (value!* "bar") text))) - (it "sets the text of a text area" + (expect-it "sets the text of a text area" (= "bar" (-> (text :multi-line? true) (value!* "bar") text))) - (it "sets the text of a text field" + (expect-it "sets the text of a text field" (= "bar" (-> (text) (value!* "bar") text))) - (it "sets the text of a text field to \"\" if value is nil" + (expect-it "sets the text of a text field to \"\" if value is nil" (= "" (-> (text "foo") (value!* nil) text))) - (it "sets the text of a label" + (expect-it "sets the text of a label" (= "bar" (-> (label) (value!* "bar") text)))) diff --git a/test/seesaw/test/widgets/log_window.clj b/test/seesaw/test/widgets/log_window.clj index 7519194e..829303ec 100644 --- a/test/seesaw/test/widgets/log_window.clj +++ b/test/seesaw/test/widgets/log_window.clj @@ -9,18 +9,18 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.widgets.log-window - (:use [seesaw.widgets.log-window] - [seesaw.core] - [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require + [lazytest.core :refer [defdescribe expect-it]] + [seesaw.core :refer :all] + [seesaw.widgets.log-window :refer :all])) -(describe log-window - (it "creates a JTextArea" +(defdescribe log-window-test + (expect-it "creates a JTextArea" (instance? javax.swing.JTextArea (log-window))) - (it "has :limit option" + (expect-it "has :limit option" (= 55 (config (log-window :limit 55) :limit))) - (it "has :auto-scroll? option" + (expect-it "has :auto-scroll? option" (not (config (log-window :auto-scroll? false) :auto-scroll?))) - (it "satisfies LogWindow protocol" + (expect-it "satisfies LogWindow protocol" (satisfies? LogWindow (log-window)))) diff --git a/test/seesaw/test/widgets/rounded_label.clj b/test/seesaw/test/widgets/rounded_label.clj index 24c2d1b3..c076669f 100644 --- a/test/seesaw/test/widgets/rounded_label.clj +++ b/test/seesaw/test/widgets/rounded_label.clj @@ -9,12 +9,11 @@ ; You must not remove this notice, or any other, from this software. (ns seesaw.test.widgets.rounded-label - (:use [seesaw.widgets.rounded-label]) - (:use [lazytest.describe :only (describe it testing)] - [lazytest.expect :only (expect)])) + (:require [seesaw.widgets.rounded-label :refer :all] + [lazytest.core :refer [defdescribe expect-it it expect]])) -(describe rounded-label - (it "creates a sub-class of label" +(defdescribe rounded-label-test + (expect-it "creates a sub-class of label" (instance? javax.swing.JLabel (rounded-label))) (it "honors label options" (let [rl (rounded-label :text "hi" :background :blue)]