Closed krader1961 closed 1 year ago
Closing in light of my recent thoughts regarding a total ordering of all Elvish value types (see https://github.com/elves/elvish/issues/1599). I'm going to rework these two changes to make the ordering of different types well defined. Thus making the implicit sorting of map keys by pprint
and repr
well defined rather than ill-defined.
This change is more invasive than I expected because the existing Elvish value comparison code was in
pkg/eval
rather thanpkg/eval/vals
. This moves the value comparison logic into thevals
package so it can be used by packges other thaneval
. For example, the vals packagerepr
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 to improve readability of the expected value.This also sorts the keys of pseudo (struct) maps for consistency with mutable maps. This arguably makes the output of pretty-printing pseudo maps less friendly since a struct map definition typically orders its members in a deliberate fashion (unlike a regular map). However, it is more important that the output of printing the output of regular and pseudo maps (via
repr
orpprint
) be consistent with regard to the order of their keys.Related: 1495