Expand tests and fix bugs in packaging.util.resolve_name.

The code is still ugly, but at least it works better now.  Patches to
make it easier to read are welcome, as well as support in #12915.
2 files changed