cargo2ebuild: Fix handling versions with `~`

The previous script behaviour was completely wrong for 2-part and 3-part
version specifiers according to the Cargo reference:
https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#tilde-requirements

Test uses versions from the reference, i.e. `~1`, `~1.2` and `~1.2.3`
with "test" as a package name.

Before these specifiers were returned as equivalent in ebuilds:
=test-1*:=
>=test-1.2.0:= <test-0.3.0
~test-1.2.3:=

Now these specifiers are returned:
=test-1*:=
=test-1.2*:=
>=test-1.2.3:= <test-1.3.0

BUG=None
TEST=python3 -c '
from cargo2ebuild import VersionRange
for version in ["~1", "~1.2", "~1.2.3"]:
  print(VersionRange.from_str(version).to_ebuild_str("test"))
'

Change-Id: I20060fa38db4e5f80ce70356d2ccc2baae509795
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/3087652
Tested-by: Adam Jelinski <ajelinski@antmicro.com>
Reviewed-by: Allen Webb <allenwebb@google.com>
Commit-Queue: Adam Jelinski <ajelinski@antmicro.com>
Commit-Queue: Allen Webb <allenwebb@google.com>
1 file changed