Skip to content

Commit 6afe46d

Browse files
authored
Merge pull request funcool#17 from tomerweller/fix-associative-dynamic
Fix associative spec to allow for nested dynamic size specs
2 parents 98f879d + 9c2313e commit 6afe46d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/octet/spec.cljc

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
(size* [_ data]
7474
(reduce (fn [acc [field data]]
7575
(let [type (field dict)]
76-
(if (satisfies? ISpecSize type)
77-
(+ acc (size type))
78-
(+ acc (size* type data)))))
76+
(if (satisfies? ISpecDynamicSize type)
77+
(+ acc (size* type data))
78+
(+ acc (size type)))))
7979
0
8080
(into [] data)))
8181

test/octet/tests/core.cljc

+10
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,16 @@
466466
(t/is (= readed 24))
467467
(t/is (= data [1 2 3 4 5])))))
468468

469+
(t/deftest spec-associative-nested-dynamic
470+
(let [spec (buf/spec :outer (buf/spec :inner (buf/vector* buf/int32)))
471+
buffer (buf/into (buf/spec :outer (buf/spec :inner (buf/vector* buf/int32))) {:outer {:inner [1]}})
472+
written (impl/get-capacity buffer)]
473+
(t/is (= written 8))
474+
475+
(let [[readed data] (buf/read* buffer spec)]
476+
(t/is (= readed 8)
477+
(t/is (= data {:outer {:inner [1]}}))))))
478+
469479
#?(:cljs
470480
(do
471481
(enable-console-print!)

0 commit comments

Comments
 (0)