Skip to content

Commit

Permalink
Add yyjson_version() function
Browse files Browse the repository at this point in the history
  • Loading branch information
ibireme committed Dec 11, 2021
1 parent 7db2b4e commit 537276d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/yyjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
# pragma warning(disable:4706) /* assignment within conditional expression */
#endif

/* version, same as YYJSON_VERSION_HEX */
yyjson_api uint32_t yyjson_version(void) {
return YYJSON_VERSION_HEX;
}



/*==============================================================================
Expand Down
9 changes: 6 additions & 3 deletions src/yyjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
*============================================================================*/

#define YYJSON_VERSION_MAJOR 0
#define YYJSON_VERSION_MINOR 3
#define YYJSON_VERSION_MINOR 4
#define YYJSON_VERSION_PATCH 0
#define YYJSON_VERSION_HEX 0x000300
#define YYJSON_VERSION_STRING "0.3.0"
#define YYJSON_VERSION_HEX 0x000400
#define YYJSON_VERSION_STRING "0.4.0"



Expand Down Expand Up @@ -366,6 +366,9 @@ extern "C" {
# pragma warning(disable:4800) /* 'int': forcing value to 'true' or 'false' */
#endif

/* version, same as YYJSON_VERSION_HEX */
yyjson_api uint32_t yyjson_version(void);



/*==============================================================================
Expand Down
16 changes: 16 additions & 0 deletions test/test_roundtrip.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
#include "yy_test_utils.h"

yy_test_case(test_roundtrip) {

// Check version
yy_assert(yyjson_version() == YYJSON_VERSION_HEX);

uint32_t ver = (YYJSON_VERSION_MAJOR << 16) +
(YYJSON_VERSION_MINOR << 8) +
(YYJSON_VERSION_PATCH);
yy_assert(yyjson_version() == ver);

char buf[16];
snprintf(buf, sizeof(buf), "%d.%d.%d",
YYJSON_VERSION_MAJOR, YYJSON_VERSION_MINOR, YYJSON_VERSION_PATCH);
yy_assert(strcmp(YYJSON_VERSION_STRING, buf) == 0);
ver = YYJSON_VERSION_MAJOR << 16;

// Check JSON file roundtrip
#if !YYJSON_DISABLE_READER && !YYJSON_DISABLE_WRITER

char dir[YY_MAX_PATH];
Expand Down

0 comments on commit 537276d

Please sign in to comment.