File tree Expand file tree Collapse file tree 3 files changed +34
-11
lines changed
Expand file tree Collapse file tree 3 files changed +34
-11
lines changed Original file line number Diff line number Diff line change 77 [clojure.string :as string]
88 [mobdap.adapter :as adapter]
99 [mobdap.debug-server :as debug-server]
10+ [mobdap.utils :refer [float-to-string map-over-map to-int]]
1011 [taoensso.timbre :as log]))
1112
1213(def ^:private go-handler (atom nil ))
2526 :stackframes (atom [])
2627 :var-index (atom {})})
2728
28- (defn- to-int [value]
29- (if (int? value)
30- value
31- (Integer/parseInt value)))
32-
3329(defn- find-source-dir [handler filepath]
3430 (let [file (io/file filepath)]
3531 (cond
156152 (adapter/send-message! (:adapter handler) response)
157153 handler))
158154
159- (defn- map-over-map [fun m]
160- (reduce-kv (fn [m k v] (assoc m k (fun k v))) {} m))
161-
162155(defn- parse-heap-value [ident]
163156 (when-let [[_ type addr] (re-find #"(.+):\s *(0x[A-Za-z0-9]+)" ident)]
164157 {:type (keyword type)
402395 (get-in m [:extras :upvalues ]))))
403396 data))
404397
405- (defn- float-to-string [n]
406- (.replaceAll (format " %.16f" n) " \\ .?0*$" " " ))
407-
408398(defn- var-name [n]
409399 (cond
410400 (keyword? n) (name n)
Original file line number Diff line number Diff line change 1+ (ns mobdap.utils )
2+
3+ (defn to-int [value]
4+ (if (int? value)
5+ value
6+ (Integer/parseInt value)))
7+
8+ (defn map-over-map [fun m]
9+ (reduce-kv (fn [m k v] (assoc m k (fun k v))) {} m))
10+
11+ (defn float-to-string [n]
12+ (.replaceAll (format " %.16f" n) " \\ .?0*$" " " ))
Original file line number Diff line number Diff line change 1+ (ns mobdap.utils-test
2+ (:require
3+ [clojure.test :refer [deftest is testing]]
4+ [mobdap.utils :refer [float-to-string map-over-map to-int]]))
5+
6+ (deftest test-to-int
7+ (testing " int just returns as is"
8+ (is (= 1337 (to-int 1337 ))))
9+ (testing " strings convert properly"
10+ (is (= 42 (to-int " 42" )))))
11+
12+ (deftest test-map-over-map
13+ (testing " square every item"
14+ (is (match? {:a 1 :b 4 :c 9 :d 16 } (map-over-map #(* %2 %2 ) {:a 1 :b 2 :c 3 :d 4 }))))
15+ (testing " turn value to key"
16+ (is (match? {:a :a :b :b :c :c } (map-over-map (fn [k _] k) {:a 1 :b 2 :c 3 })))))
17+
18+ (deftest test-float-to-string
19+ (testing " make nice looking float strings"
20+ (is " 1.337" (float-to-string 1.337 ))))
21+
You can’t perform that action at this time.
0 commit comments