Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure compact printer is emitting in a streaming fashion #627

Draft
wants to merge 1 commit into
base: 1.11.x
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions json/src/test/scala/fs2/data/json/RenderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,37 @@ object RenderSpec extends SimpleIOSuite {

}

pureTest("Compact pipe must emit in a streaming fashion") {
// single chunk as input
val input = Stream.emit("""true {"field1": "test", "field2": [23, [true, null]]}""")

val toks: Stream[Fallible, Token] = input.through(tokens[Fallible, String])

// check that tokens are also emitted as a single chunk
expect(toks.chunks.compile.toList.map((_.size)) == Right(1))

val rendered: Stream[Fallible, String] = toks.through(render.compact)

// still emit as early as possible
expect(
rendered.chunks.compile.toList == Right(List(
Chunk.singleton("true"),
Chunk.singleton("{"),
Chunk.singleton("\"field1\":"),
Chunk.singleton("\"test\""),
Chunk.singleton(","),
Chunk.singleton("\"field2\":"),
Chunk.singleton("["),
Chunk.singleton("23"),
Chunk.singleton(","),
Chunk.singleton("["),
Chunk.singleton("true"),
Chunk.singleton(","),
Chunk.singleton("null"),
Chunk.singleton("]"),
Chunk.singleton("]"),
Chunk.singleton("}")
)))
}

}
Loading