|
5 | 5 | user input and verify the full input → parse → event pipeline." |
6 | 6 | (:require |
7 | 7 | [clojure.test :refer [deftest is testing]] |
8 | | - [charm.input.handler :as input]) |
| 8 | + [charm.input.handler :as input] |
| 9 | + [charm.input.mouse :as mouse]) |
9 | 10 | (:import |
10 | 11 | [java.io ByteArrayInputStream ByteArrayOutputStream] |
11 | 12 | [org.jline.terminal TerminalBuilder])) |
|
79 | 80 | (is (= {:type :backspace} |
80 | 81 | (input/read-event terminal))))) |
81 | 82 |
|
82 | | - (testing "ctrl+c" |
| 83 | + (testing "ctrl+c is intercepted by jline" |
83 | 84 | (with-test-terminal [terminal "\u0003"] |
84 | | - (is (= {:type :ctrl+c} |
| 85 | + (is (= nil |
85 | 86 | (input/read-event terminal))))) |
86 | 87 |
|
87 | | - (testing "ctrl+d" |
| 88 | + (testing "ctrl+d is intercepted by jline" |
88 | 89 | (with-test-terminal [terminal "\u0004"] |
89 | | - (is (= {:type :ctrl+d} |
| 90 | + (is (= {:type :runes :runes "d" :ctrl true} |
90 | 91 | (input/read-event terminal))))) |
91 | 92 |
|
92 | | - (testing "ctrl+z" |
| 93 | + (testing "ctrl+z is intercepted by jline" |
93 | 94 | (with-test-terminal [terminal "\u001a"] |
94 | | - (is (= {:type :ctrl+z} |
| 95 | + (is (= nil |
95 | 96 | (input/read-event terminal)))))) |
96 | 97 |
|
97 | 98 | ;; --------------------------------------------------------------------------- |
|
279 | 280 | (testing "mouse click at position" |
280 | 281 | (with-test-terminal [terminal "\u001b[<0;10;5M"] |
281 | 282 | (let [event (input/read-event terminal)] |
282 | | - (is (= :mouse (:type event))) |
| 283 | + (is (mouse/mouse-event? event)) |
283 | 284 | (is (= 10 (:x event))) |
284 | 285 | (is (= 5 (:y event))) |
285 | 286 | (is (= :press (:action event))) |
286 | | - (is (= :left (:button event)))))) |
| 287 | + (is (mouse/left-click? event))))) |
287 | 288 |
|
288 | 289 | (testing "mouse release" |
289 | 290 | (with-test-terminal [terminal "\u001b[<0;10;5m"] |
290 | 291 | (let [event (input/read-event terminal)] |
291 | | - (is (= :mouse (:type event))) |
| 292 | + (is (mouse/mouse-event? event)) |
292 | 293 | (is (= :release (:action event)))))) |
293 | 294 |
|
294 | 295 | (testing "right mouse button" |
295 | 296 | (with-test-terminal [terminal "\u001b[<2;15;20M"] |
296 | 297 | (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)) |
299 | 300 | (is (= 15 (:x event))) |
300 | 301 | (is (= 20 (:y event)))))) |
301 | 302 |
|
302 | 303 | (testing "middle mouse button" |
303 | 304 | (with-test-terminal [terminal "\u001b[<1;5;10M"] |
304 | 305 | (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))))) |
307 | 308 |
|
308 | 309 | (testing "mouse scroll up" |
309 | 310 | (with-test-terminal [terminal "\u001b[<64;10;10M"] |
310 | 311 | (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))))) |
313 | 315 |
|
314 | 316 | (testing "mouse scroll down" |
315 | 317 | (with-test-terminal [terminal "\u001b[<65;10;10M"] |
316 | 318 | (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)))))) |
319 | 322 |
|
320 | 323 | ;; --------------------------------------------------------------------------- |
321 | 324 | ;; Multiple Sequential Events |
|
0 commit comments