Skip to content

Commit 2b6c0cb

Browse files
committed
test: fix integration tests
1 parent c183ac6 commit 2b6c0cb

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

deps.edn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
org.jline/jline-terminal-ffm {:mvn/version "3.30.6"
55
:exclusions [org.jline/jline-native]}
66
org.jline/jline-reader {:mvn/version "3.30.6"}}
7+
78
:aliases
9+
810
{:test {:extra-paths ["test"]
911
:extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
1012
:main-opts ["-m" "cognitect.test-runner"]

src/charm/input/mouse.clj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,13 @@
186186
"Check if a mouse event is a middle click."
187187
[event]
188188
(and (click? event) (= (:button event) button-middle)))
189+
190+
(defn wheel-up?
191+
"Check if a mouse event is a wheel up."
192+
[event]
193+
(and (wheel? event) (= (:button event) button-wheel-up)))
194+
195+
(defn wheel-down?
196+
"Check if a mouse event is a wheel down."
197+
[event]
198+
(and (wheel? event) (= (:button event) button-wheel-down)))

test/charm/integration/input_test.clj

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
user input and verify the full input → parse → event pipeline."
66
(:require
77
[clojure.test :refer [deftest is testing]]
8-
[charm.input.handler :as input])
8+
[charm.input.handler :as input]
9+
[charm.input.mouse :as mouse])
910
(:import
1011
[java.io ByteArrayInputStream ByteArrayOutputStream]
1112
[org.jline.terminal TerminalBuilder]))
@@ -79,19 +80,19 @@
7980
(is (= {:type :backspace}
8081
(input/read-event terminal)))))
8182

82-
(testing "ctrl+c"
83+
(testing "ctrl+c is intercepted by jline"
8384
(with-test-terminal [terminal "\u0003"]
84-
(is (= {:type :ctrl+c}
85+
(is (= nil
8586
(input/read-event terminal)))))
8687

87-
(testing "ctrl+d"
88+
(testing "ctrl+d is intercepted by jline"
8889
(with-test-terminal [terminal "\u0004"]
89-
(is (= {:type :ctrl+d}
90+
(is (= {:type :runes :runes "d" :ctrl true}
9091
(input/read-event terminal)))))
9192

92-
(testing "ctrl+z"
93+
(testing "ctrl+z is intercepted by jline"
9394
(with-test-terminal [terminal "\u001a"]
94-
(is (= {:type :ctrl+z}
95+
(is (= nil
9596
(input/read-event terminal))))))
9697

9798
;; ---------------------------------------------------------------------------
@@ -279,43 +280,45 @@
279280
(testing "mouse click at position"
280281
(with-test-terminal [terminal "\u001b[<0;10;5M"]
281282
(let [event (input/read-event terminal)]
282-
(is (= :mouse (:type event)))
283+
(is (mouse/mouse-event? event))
283284
(is (= 10 (:x event)))
284285
(is (= 5 (:y event)))
285286
(is (= :press (:action event)))
286-
(is (= :left (:button event))))))
287+
(is (mouse/left-click? event)))))
287288

288289
(testing "mouse release"
289290
(with-test-terminal [terminal "\u001b[<0;10;5m"]
290291
(let [event (input/read-event terminal)]
291-
(is (= :mouse (:type event)))
292+
(is (mouse/mouse-event? event))
292293
(is (= :release (:action event))))))
293294

294295
(testing "right mouse button"
295296
(with-test-terminal [terminal "\u001b[<2;15;20M"]
296297
(let [event (input/read-event terminal)]
297-
(is (= :mouse (:type event)))
298-
(is (= :right (:button event)))
298+
(is (mouse/mouse-event? event))
299+
(is (mouse/right-click? event))
299300
(is (= 15 (:x event)))
300301
(is (= 20 (:y event))))))
301302

302303
(testing "middle mouse button"
303304
(with-test-terminal [terminal "\u001b[<1;5;10M"]
304305
(let [event (input/read-event terminal)]
305-
(is (= :mouse (:type event)))
306-
(is (= :middle (:button event))))))
306+
(is (mouse/mouse-event? event))
307+
(is (mouse/middle-click? event)))))
307308

308309
(testing "mouse scroll up"
309310
(with-test-terminal [terminal "\u001b[<64;10;10M"]
310311
(let [event (input/read-event terminal)]
311-
(is (= :mouse (:type event)))
312-
(is (= :scroll-up (:button event))))))
312+
(is (mouse/mouse-event? event))
313+
(is (mouse/wheel? event))
314+
(is (mouse/wheel-up? event)))))
313315

314316
(testing "mouse scroll down"
315317
(with-test-terminal [terminal "\u001b[<65;10;10M"]
316318
(let [event (input/read-event terminal)]
317-
(is (= :mouse (:type event)))
318-
(is (= :scroll-down (:button event)))))))
319+
(is (mouse/mouse-event? event))
320+
(is (mouse/wheel? event))
321+
(is (mouse/wheel-down? event))))))
319322

320323
;; ---------------------------------------------------------------------------
321324
;; Multiple Sequential Events

user/dev.clj

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
(ns dev
2-
(:require [clojure.test :refer [run-all-tests]]))
1+
(ns dev)
32

4-
(run-all-tests #"charm.*-test")
3+
(comment
4+
(require '[clojure.test :refer [run-all-tests]])
5+
(run-all-tests #"charm.*-test"))
6+
7+
(comment
8+
(require '[portal.api :as p])
9+
(def p (p/open))
10+
(add-tap #'p/submit))

0 commit comments

Comments
 (0)