oakmac / standard-clojure-style-js

Standard Clojure Style in JavaScript
ISC License
38 stars 1 forks source link

chessboard2 test cases #41

Open oakmac opened 2 months ago

oakmac commented 2 months ago

I ran across this test case while creating the cli tooling:

(defn js-get-circles
  "Returns the Circle Items on the board as either a JS Array (default), JS Object, or JS Map"
  [board-state return-fmt]
  (map->js-return-format (api/get-items-by-type board-state "CHESSBOARD_CIRCLE")
                         (safe-lower-case return-fmt)))

Is currently formatted to:

(defn js-get-circles
  "Returns the Circle Items on the board as either a JS Array (default), JS Object, or JS Map"
  [board-state return-fmt]
  (map->js-return-format (api/get-items-by-type board-state "CHESSBOARD_CIRCLE")
    (safe-lower-case return-fmt)))

I expect:

(defn js-get-circles
  "Returns the Circle Items on the board as either a JS Array (default), JS Object, or JS Map"
  [board-state return-fmt]
  (map->js-return-format (api/get-items-by-type board-state "CHESSBOARD_CIRCLE")
                         (safe-lower-case return-fmt)))

(ie: no change from the input)

oakmac commented 2 months ago

And this case where the docstring is missing:

chessboard2 test case 2 - missing fn docstring

(defn add-or-replace-circle
  "Adds a Circle to the board. Returns the id of the new Circle.
  If there is already a Circle on the board on that square, it will be replaced."
  [board-state {:keys [square] :as circle-config}]
  (let [square->circles-map (get-circles-by-square board-state)]
    (if-let [current-circle (get square->circles-map square)]
      (do
        (remove-circle-by-id board-state (:id current-circle))
        (add-circle board-state (assoc circle-config :id (:id current-circle))))
      (add-circle board-state circle-config))))
(defn add-or-replace-circle
  "
  "
  [board-state {:keys [square] :as circle-config}]
  (let [square->circles-map (get-circles-by-square board-state)]
    (if-let [current-circle (get square->circles-map square)]
      (do
        (remove-circle-by-id board-state (:id current-circle))
        (add-circle board-state (assoc circle-config :id (:id current-circle))))
      (add-circle board-state circle-config))))
oakmac commented 2 months ago

Fixed with PR #42

oakmac commented 2 months ago

Another test case (view raw as .eno format)

rule 3 - threading macro example

--Input (->> @foo :bar vals (filter my-pred?)) --Input

--Expected (->> @foo :bar vals (filter my-pred?)) --Expected

chessboard2 test case 2 - rule 3 indentation

--Input (defn get-circles-by-square "Returns a Map of Circles with their square as the key." [board-state] (let [circles (->> @board-state :items vals (filter circle-item?))] (zipmap (map :square circles) circles))) --Input

--Expected (defn get-circles-by-square "Returns a Map of Circles with their square as the key." [board-state] (let [circles (->> @board-state :items vals (filter circle-item?))] (zipmap (map :square circles) circles))) --Expected

oakmac commented 2 months ago

Another test case:

chessboard2 test case 3

--Input (js-obj "foo" bar "biz" #() ;; aaa "baz" nil ) --Input

--Expected (js-obj "foo" bar "biz" #() ;; aaa "baz" nil) --Expected

oakmac commented 2 months ago

Another test case:

(ns com.oakmac.chessboard2.util.base58)

(def base58-chars
  "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")

(def default-length 12)

(defn random-base58
  "returns a random base58 string"
  ([]
   (random-base58 default-length))
  ([len]
   (apply str (take len (repeatedly #(rand-nth base58-chars))))))

Fixed with PR #46

oakmac commented 2 months ago
(defn zomg!
  "I am a function docstring."
  [some-map]
  (let [{:keys [x y]} some-map]
    ;; gobble gobble
    (when-not (even? x)
      (let [a "a"]
        ;; banana
        (foo bar :alpha "alpha"
                 :bravo "bravo")))))
        ;; aaa
        ;; bbb

Fixed with PR #47

oakmac commented 2 months ago

The FIXME: add square comment gets adjusted here. I think it should stay aligned with the above form?

(defn on-touch-start
  "This function fires on every 'touchstart' event inside the root DOM element"
  [board-state js-evt]
  (let [;; call their onTouchSquare function if provided
        on-touchsquare-result (when (fn? onTouchSquare)
                                (let [js-board-info (js-obj "orientation" orientation
                                                            "position" (clj->js position))]
                                                            ;; FIXME: add square, piece here
                                                            ;; what else?
                                  (onTouchSquare square piece js-board-info)))]
    ;; begin dragging if configured
    (when (and piece
               (or (true? draggable) (true? touchDraggable)))
      (begin-dragging! board-state square piece clientX clientY))))