validateJsonSink function
Wraps a JsonSink in a validating layer.
A JsonSink is an API which requires methods to be called in a specific order, but implementations are allowed to not check this. Calling methods in an incorrect order may throw, or it may return spurious values.
The returned sink wraps sink
and intercepts all method calls.
It throws immediately if the calls are not in a proper order.
This function is mainly intended for testing code which writes to sinks, to ensure that they make calls in the
If allowReuse
is set to true, the sink is assumed to be reusable,
meaning that after completely writing a JSON structure, it resets
and accepts following JSON structures. If not, then no method
may be called after completing a single JSON structure.
Implementation
JsonSink validateJsonSink(JsonSink sink, {bool allowReuse = false}) {
return ValidatingJsonSink(sink, allowReuse);
}