Add missing tests for session bug fixes and uniform-spread?

Add indexed-access-with-default in fill_test.cljc to cover the two-arity
(nth fills i default) form on both valid and out-of-range indices, directly
exercising the CLJS Fills -nth path fixed in 593cf125.

Add segment-content->selrect-multi-line in path_data_test.cljc to cover
content->selrect on a subpath with multiple consecutive line-to commands
where move-p diverges from from-p, confirming the bounding box matches
both the expected coordinates and the reference implementation; this
guards the calculate-extremities fix in bb5a04c7.

Add types-uniform-spread? in colors_test.cljc to cover
app.common.types.color/uniform-spread?, which had no dedicated tests.
Exercises the uniform case (via uniform-spread), the two-stop edge case,
wrong-offset detection, and wrong-color detection.

Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
Andrey Antukh 2026-04-14 12:48:07 +00:00
parent caac452cd4
commit db7c646568
3 changed files with 61 additions and 0 deletions

View File

@ -426,6 +426,27 @@
{:color "#ffffff" :opacity 1.0 :offset 1.0}]]
(t/is (false? (c/uniform-spread? stops)))))
(t/deftest types-uniform-spread?
(t/testing "uniformly spread stops are detected as uniform"
(let [c1 {:color "#000000" :opacity 0.0 :offset 0.0}
c2 {:color "#ffffff" :opacity 1.0 :offset 1.0}
stops (colors/uniform-spread c1 c2 3)]
(t/is (true? (colors/uniform-spread? stops)))))
(t/testing "two-stop gradient is uniform by definition"
(let [stops [{:color "#ff0000" :opacity 1.0 :offset 0.0}
{:color "#0000ff" :opacity 1.0 :offset 1.0}]]
(t/is (true? (colors/uniform-spread? stops)))))
(t/testing "stops with wrong offset are not uniform"
(let [stops [{:color "#000000" :opacity 0.0 :offset 0.0}
{:color "#888888" :opacity 0.5 :offset 0.3}
{:color "#ffffff" :opacity 1.0 :offset 1.0}]]
(t/is (false? (colors/uniform-spread? stops)))))
(t/testing "stops with correct offset but wrong color are not uniform"
(let [stops [{:color "#000000" :opacity 0.0 :offset 0.0}
{:color "#aaaaaa" :opacity 0.5 :offset 0.5}
{:color "#ffffff" :opacity 1.0 :offset 1.0}]]
(t/is (false? (colors/uniform-spread? stops))))))
(t/deftest ac-interpolate-gradient
(let [stops [{:color "#000000" :opacity 0.0 :offset 0.0}
{:color "#ffffff" :opacity 1.0 :offset 1.0}]]

View File

@ -207,3 +207,18 @@
fill1 (nth fills1 1)]
(t/is (nil? fill1))
(t/is (equivalent-fill? fill0 sample-fill-6))))
(t/deftest indexed-access-with-default
(t/testing "nth with default returns fill for valid index"
;; Regression: CLJS -nth with default had reversed d/in-range? args,
;; so it always fell through to the default even for valid indices.
(let [fills (types.fills/from-plain [sample-fill-6])
sentinel ::not-found
result (nth fills 0 sentinel)]
(t/is (not= sentinel result))
(t/is (equivalent-fill? result sample-fill-6))))
(t/testing "nth with default returns default for out-of-range index"
(let [fills (types.fills/from-plain [sample-fill-6])
sentinel ::not-found]
(t/is (= sentinel (nth fills 1 sentinel)))
(t/is (= sentinel (nth fills -1 sentinel))))))

View File

@ -973,6 +973,31 @@
(t/is (mth/close? 10.0 (:x2 rect) 0.1))
(t/is (mth/close? 10.0 (:y2 rect) 0.1))))
(t/deftest segment-content->selrect-multi-line
;; Regression: calculate-extremities used move-p instead of from-p in
;; the :line-to branch. For a subpath with multiple consecutive line-to
;; commands, the selrect must still match the reference implementation.
(let [;; A subpath that starts away from the origin and has three
;; line-to segments so that move-p diverges from from-p for the
;; later segments.
segments [{:command :move-to :params {:x 5.0 :y 5.0}}
{:command :line-to :params {:x 15.0 :y 0.0}}
{:command :line-to :params {:x 20.0 :y 8.0}}
{:command :line-to :params {:x 10.0 :y 12.0}}]
content (path/content segments)
rect (path.segment/content->selrect content)
ref-pts (calculate-extremities segments)]
;; Bounding box must enclose all four vertices exactly.
(t/is (some? rect))
(t/is (mth/close? 5.0 (:x1 rect) 0.1))
(t/is (mth/close? 0.0 (:y1 rect) 0.1))
(t/is (mth/close? 20.0 (:x2 rect) 0.1))
(t/is (mth/close? 12.0 (:y2 rect) 0.1))
;; Must agree with the reference implementation.
(t/is (= ref-pts (calculate-extremities content)))))
(t/deftest segment-content-center
(let [content (path/content sample-content-square)
center (path.segment/content-center content)]