This is an archive of the discontinued LLVM Phabricator instance.

[unittest, ADT] Add unit tests for itostr & utostr
ClosedPublic

Authored by thopre on Jun 22 2020, 7:15 AM.

Diff Detail

Event Timeline

thopre created this revision.Jun 22 2020, 7:15 AM
thopre marked an inline comment as done.Jun 22 2020, 7:16 AM
thopre added inline comments.
llvm/unittests/ADT/StringExtrasTest.cpp
198

Since there's no comment, I'm not sure whether it is supported by the API or not. I'd be tempted to add an assert and a comment not to support it.

jhenderson added inline comments.Jun 23 2020, 1:01 AM
llvm/unittests/ADT/StringExtrasTest.cpp
195–196

Here, and in the below cases using the max/min values, I wonder whether it would be more robust to write something like:

EXPECT_EQ(std::to_string(MaxUint64), utostr(MaxUint64));
EXPECT_EQ("-" + std::to_string(MaxUint64), utostr(MaxUint64, /*isNeg=*/true);

etc.

I'd expect them to produce identical output, but it also is easier to confirm the expected number. It also removes any concerns about numeric representation (2's complement etc).

198

I'm inclined to leave it as-is. It's possible it was a simple oversight by the original developer, but I think it's okay to permit it for consistency. People could be using it in the sense of "subtract 0" rather than "negative 0" in theory, apart from anything else.

thopre marked an inline comment as done.Jun 23 2020, 5:58 AM
thopre added inline comments.
llvm/unittests/ADT/StringExtrasTest.cpp
195–196

It's what I did originally but I was not sure if it was fine to rely on std::to_string being correct.

thopre updated this revision to Diff 272702.Jun 23 2020, 6:12 AM
thopre marked 2 inline comments as done.

Use std::to_string to test API for big values

jhenderson accepted this revision.Jun 23 2020, 6:30 AM

LGTM.

llvm/unittests/ADT/StringExtrasTest.cpp
195–196

I think if we can't rely on standard library functions doing the right thing, we're in trouble...

This revision is now accepted and ready to land.Jun 23 2020, 6:30 AM
This revision was automatically updated to reflect the committed changes.