class Unparser::Writer::DynamicString
def dispatch
TLDR: Good case for a mutant disable.
knew about such a bug: I'd fix it so would be back at the start.
But unless I had such a bug in my test corpus: I cannot enable mutant, and if I
but has to exist as I have to assume unparser still has bugs.
The raise below is not reachable if unparser is correctly implemented
def dispatch if heredoc? write(HEREDOC_HEADER) buffer.push_heredoc(heredoc_body) elsif round_tripping_segmented_source write(round_tripping_segmented_source) else fail UnsupportedNodeError, "Unparser cannot round trip this node: #{node.inspect}" end end
def each_segments(array)
def each_segments(array) yield [array] 1.upto(array.length) do |take| prefix = [array.take(take)] suffix = array.drop(take) each_segments(suffix) do |items| yield(prefix + items) end end end
def heredoc?
def heredoc? if children.length >= HEREDOC_THRESHOLD round_trips_heredoc? else round_tripping_segmented_source.nil? # && round_trips_heredoc? end end
def heredoc_body
def heredoc_body buffer = Buffer.new writer = Heredoc.new( buffer:, comments:, explicit_encoding: nil, local_variable_scope:, node: ) writer.emit buffer.content end
def heredoc_source
def heredoc_source "#{HEREDOC_HEADER}\n#{heredoc_body}" end
def round_tripping_segmented_source
def round_tripping_segmented_source each_segments(children) do |segments| source = segmented_source(segments: segments) return source if round_trips?(source: source) end nil end
def round_trips_heredoc?
def round_trips_heredoc? round_trips?(source: heredoc_source) end
def segmented_source(segments:)
def segmented_source(segments:) buffer = Buffer.new Segmented.new( buffer:, comments:, explicit_encoding: nil, local_variable_scope:, node:, segments: ).dispatch buffer.content end