elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.65k stars 299 forks source link

`pprint` (and `repr`) now sorts map keys #1695

Closed krader1961 closed 1 year ago

krader1961 commented 1 year ago

This change is more invasive than I expected because the existing Elvish value comparison code was in pkg/eval rather than pkg/eval/vals. This moves the value comparison logic into the vals package so it can be used by packges other than eval. For example, the vals package repr implementation. Not to mention other Elvish modules which may want to compare Elvish values.

I also decided to introduce a strutil.Dedent function to make it easier to write multiline string literals in unit tests while retaining readability.

Related: 1495

krader1961 commented 1 year ago

Closing this PR since I've decided to also include sorting psuedo-map (struct-map) keys and the easiest way to do that is to change the type used to hold the keys for sorting to hold key/value pairs. I'll open a new PR in a couple of hours when I've finished that work.