Permalink
Browse files

possible fix for open-list + footer bug

  • Loading branch information...
stuarthalloway committed Mar 17, 2015
1 parent df59566 commit 07f9443771aa2f74c41fdd4878c45f280f282c2b
Showing with 34 additions and 2 deletions.
  1. +0 −1 src/org/fressian/FressianWriter.java
  2. +34 −1 test/org/fressian/fressian_test.clj
@@ -494,7 +494,6 @@ public Writer beginOpenList() throws IOException {
if (0 != rawOut.getBytesWritten())
throw new IllegalStateException("openList must be called from the top level, outside any footer context.");
writeCode(Codes.BEGIN_OPEN_LIST);
rawOut.reset();
return this;
}
}
@@ -6,7 +6,9 @@
[org.fressian.test-helpers :only (assert=)])
(:require [org.fressian.generators :as gen]
[org.fressian.api :as fressian])
(:import [org.fressian.impl BytesOutputStream]))
(:import
[org.fressian StreamingWriter]
[org.fressian.impl BytesOutputStream]))
(set! *warn-on-reflection* true)
@@ -19,6 +21,27 @@
(fressian/byte-buf :handlers write-handlers)
(fressian/defressian :handlers read-handlers))))
(defn roundtrip-footer
"Fressian and defressian o with footer"
([o]
(-> o (fressian/byte-buf :footer true) fressian/defressian))
([o write-handlers read-handlers]
(-> o
(fressian/byte-buf :handlers write-handlers :footer true)
(fressian/defressian :handlers read-handlers))))
(defn roundtrip-open-list-footer
"Fressian and defressian o inside an open list with footer"
[o]
(let [baos (BytesOutputStream.)
fw (fressian/create-writer baos)]
(.beginOpenList ^StreamingWriter fw)
(.writeObject fw o)
(.endList ^StreamingWriter fw)
(.writeFooter fw)
(first (fressian/defressian (fressian/bytestream->buf baos)
:footer true))))
(defspec fressian-character-encoding
roundtrip
[^{:tag `gen/single-char-string} s]
@@ -36,6 +59,16 @@
[^{:tag `gen/fressian-builtin} s]
(assert= s %))
(defspec fressian-builtins-with-footer
roundtrip-footer
[^{:tag `gen/fressian-builtin} s]
(assert= s %))
(defspec fressian-open-list-with-footer
roundtrip-open-list-footer
[^{:tag `gen/fressian-builtin} s]
(assert= s %))
(defspec fressian-int-packing
roundtrip
[^{:tag `gen/long-near-power-of-2} input]

0 comments on commit 07f9443

Please sign in to comment.