Skip to content

Commit

Permalink
U32 to str function (#148)
Browse files Browse the repository at this point in the history
* feat: add uint32 to str function

* chore: bump version
  • Loading branch information
chcmedeiros authored Oct 14, 2024
1 parent 337d761 commit d9ded97
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/zxformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ extern "C" {

NUM_TO_STR(int32)

NUM_TO_STR(uint32)

NUM_TO_STR(int64)

NUM_TO_STR(uint64)
Expand Down
2 changes: 1 addition & 1 deletion include/zxversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
#pragma once

#define ZXLIB_MAJOR 29
#define ZXLIB_MINOR 2
#define ZXLIB_MINOR 3
#define ZXLIB_PATCH 0
34 changes: 34 additions & 0 deletions tests/macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,40 @@ namespace {
EXPECT_EQ(std::string(number), "12.34567");
}

TEST(UINT32_TO_STR, Zero) {
char temp[10];
const char *error = uint32_to_str(temp, sizeof(temp), uint32_t(0));
EXPECT_STREQ(temp, "0");
EXPECT_TRUE(error == nullptr);
}

TEST(UINT32_TO_STR, Positive_1234) {
char temp[10];
const char *error = uint32_to_str(temp, sizeof(temp), uint32_t(1234));
EXPECT_STREQ(temp, "1234");
EXPECT_TRUE(error == nullptr);
}

TEST(UINT32_TO_STR, TooSmall_0) {
char temp[1];
const char *error = uint32_to_str(temp, sizeof(temp), uint32_t(0));
EXPECT_STREQ("Buffer too small", error);
}

TEST(UINT32_TO_STR, FitsJust) {
char temp[4];
const char *error = uint32_to_str(temp, sizeof(temp), uint32_t(999));
EXPECT_STREQ(temp, "999");
EXPECT_TRUE(error == nullptr);
}

TEST(UINT32_TO_STR, Max) {
char temp[20];
const char *error = uint32_to_str(temp, sizeof(temp), std::numeric_limits<uint32_t>::max());
EXPECT_STREQ(temp, "4294967295");
EXPECT_TRUE(error == nullptr);
}

TEST(INT64_TO_STR, Zero) {
char temp[10];
const char *error = int64_to_str(temp, sizeof(temp), int64_t(0));
Expand Down

0 comments on commit d9ded97

Please sign in to comment.