Skip to content

Commit 40ec1c4

Browse files
committed
Test that compact renderer is streaming
1 parent e3e6561 commit 40ec1c4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

json/src/test/scala/fs2/data/json/RenderSpec.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,37 @@ object RenderSpec extends SimpleIOSuite {
108108

109109
}
110110

111+
pureTest("Compact pipe must emit in a streaming fashion") {
112+
// single chunk as input
113+
val input = Stream.emit("""true {"field1": "test", "field2": [23, [true, null]]}""")
114+
115+
val toks: Stream[Fallible, Token] = input.through(tokens[Fallible, String])
116+
117+
// check that tokens are also emitted as a single chunk
118+
expect(toks.chunks.compile.toList.map((_.size)) == Right(1))
119+
120+
val rendered: Stream[Fallible, String] = toks.through(render.compact)
121+
122+
// still emit as early as possible
123+
expect(
124+
rendered.chunks.compile.toList == Right(List(
125+
Chunk.singleton("true"),
126+
Chunk.singleton("{"),
127+
Chunk.singleton("\"field1\":"),
128+
Chunk.singleton("\"test\""),
129+
Chunk.singleton(","),
130+
Chunk.singleton("\"field2\":"),
131+
Chunk.singleton("["),
132+
Chunk.singleton("23"),
133+
Chunk.singleton(","),
134+
Chunk.singleton("["),
135+
Chunk.singleton("true"),
136+
Chunk.singleton(","),
137+
Chunk.singleton("null"),
138+
Chunk.singleton("]"),
139+
Chunk.singleton("]"),
140+
Chunk.singleton("}")
141+
)))
142+
}
143+
111144
}

0 commit comments

Comments
 (0)