I was writing a serializer/deserializer for goldmark AST and was comparing .Dump's output to quickly check that AST survives the roundtrip encoding intact. But since DumpHelper uses Golang's map for the kv's, the output is not deterministic (kv's are swapped randomly).
This PR solves this (admittedly very niche) issue by sorting the kv's by key before printing them out. I used sort.Slice instead of more modern slices.Sort to preserve the minimal supported go version.
I don't think that this issue is worth the pain of changing DumpHelper's signature to use slices for kv, especially since it is a public func, but perhaps it's worth the tiny inefficiency of sorting the values. What do you think?
I was writing a serializer/deserializer for goldmark AST and was comparing
.Dump
's output to quickly check that AST survives the roundtrip encoding intact. But sinceDumpHelper
uses Golang'smap
for thekv
's, the output is not deterministic (kv's are swapped randomly).This PR solves this (admittedly very niche) issue by sorting the kv's by key before printing them out. I used
sort.Slice
instead of more modernslices.Sort
to preserve the minimal supported go version.I don't think that this issue is worth the pain of changing
DumpHelper
's signature to use slices forkv
, especially since it is a public func, but perhaps it's worth the tiny inefficiency of sorting the values. What do you think?P.S.: thanks for the great library!