Skip to content

Commit

Permalink
Refresh Syntax Dictionary for error message misalignment fix
Browse files Browse the repository at this point in the history
  • Loading branch information
terryburton committed Sep 4, 2024
1 parent d14ddf4 commit 93d0b6d
Show file tree
Hide file tree
Showing 11 changed files with 340 additions and 36 deletions.
11 changes: 10 additions & 1 deletion src/c-lib/syntax/gs1syntaxdictionary.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ gs1_linter_t gs1_linter_from_name(const char* const name) {
*/
#ifdef GS1_LINTER_ERR_STR_EN

GS1_SYNTAX_DICTIONARY_API const char *gs1_lint_err_str[__GS1_LINTER_NUM_ERRS] = {
GS1_SYNTAX_DICTIONARY_API const char *gs1_lint_err_str[] = {
"No issues were detected by the linter.",
"A non-digit character was found where a digit is expected.",
"A non-CSET 82 character was found where a CSET 82 character is expected.",
Expand Down Expand Up @@ -140,6 +140,7 @@ GS1_SYNTAX_DICTIONARY_API const char *gs1_lint_err_str[__GS1_LINTER_NUM_ERRS] =
"The date is too long.",
"", // Unused
"", // Unused
"The date with hour is too long for YYMMDDHH format.",
"The hour with minute is too short for HHMM format.",
"The hour with minute is too long for HHMM format.",
"", // Unused
Expand Down Expand Up @@ -256,4 +257,12 @@ void test_gs1_linter_from_name(void)
TEST_CHECK(gs1_linter_from_name("dummy") == NULL);
}


#ifdef GS1_LINTER_ERR_STR_EN
void test_gs1_linter_err_str_en_size(void)
{
TEST_CHECK(sizeof(gs1_lint_err_str)/sizeof(gs1_lint_err_str[0]) == __GS1_LINTER_NUM_ERRS);
}
#endif

#endif /* UNIT_TESTS */
22 changes: 22 additions & 0 deletions src/c-lib/syntax/lint_hh.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,28 @@ void test_lint_hh(void)
{

UNIT_TEST_PASS(gs1_lint_hh, "00");
UNIT_TEST_PASS(gs1_lint_hh, "01");
UNIT_TEST_PASS(gs1_lint_hh, "02");
UNIT_TEST_PASS(gs1_lint_hh, "03");
UNIT_TEST_PASS(gs1_lint_hh, "04");
UNIT_TEST_PASS(gs1_lint_hh, "05");
UNIT_TEST_PASS(gs1_lint_hh, "06");
UNIT_TEST_PASS(gs1_lint_hh, "07");
UNIT_TEST_PASS(gs1_lint_hh, "08");
UNIT_TEST_PASS(gs1_lint_hh, "09");
UNIT_TEST_PASS(gs1_lint_hh, "10");
UNIT_TEST_PASS(gs1_lint_hh, "11");
UNIT_TEST_PASS(gs1_lint_hh, "12");
UNIT_TEST_PASS(gs1_lint_hh, "13");
UNIT_TEST_PASS(gs1_lint_hh, "14");
UNIT_TEST_PASS(gs1_lint_hh, "15");
UNIT_TEST_PASS(gs1_lint_hh, "16");
UNIT_TEST_PASS(gs1_lint_hh, "17");
UNIT_TEST_PASS(gs1_lint_hh, "18");
UNIT_TEST_PASS(gs1_lint_hh, "19");
UNIT_TEST_PASS(gs1_lint_hh, "20");
UNIT_TEST_PASS(gs1_lint_hh, "21");
UNIT_TEST_PASS(gs1_lint_hh, "22");
UNIT_TEST_PASS(gs1_lint_hh, "23");
UNIT_TEST_FAIL(gs1_lint_hh, "24", GS1_LINTER_ILLEGAL_HOUR, "*24*");

Expand Down
83 changes: 83 additions & 0 deletions src/c-lib/syntax/lint_hhmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,91 @@ void test_lint_hhmm(void)
{

UNIT_TEST_PASS(gs1_lint_hhmm, "0000");
UNIT_TEST_PASS(gs1_lint_hhmm, "2359");

UNIT_TEST_PASS(gs1_lint_hhmm, "0100");
UNIT_TEST_PASS(gs1_lint_hhmm, "0200");
UNIT_TEST_PASS(gs1_lint_hhmm, "0300");
UNIT_TEST_PASS(gs1_lint_hhmm, "0400");
UNIT_TEST_PASS(gs1_lint_hhmm, "0500");
UNIT_TEST_PASS(gs1_lint_hhmm, "0600");
UNIT_TEST_PASS(gs1_lint_hhmm, "0700");
UNIT_TEST_PASS(gs1_lint_hhmm, "0800");
UNIT_TEST_PASS(gs1_lint_hhmm, "0900");
UNIT_TEST_PASS(gs1_lint_hhmm, "1000");
UNIT_TEST_PASS(gs1_lint_hhmm, "1100");
UNIT_TEST_PASS(gs1_lint_hhmm, "1200");
UNIT_TEST_PASS(gs1_lint_hhmm, "1300");
UNIT_TEST_PASS(gs1_lint_hhmm, "1400");
UNIT_TEST_PASS(gs1_lint_hhmm, "1500");
UNIT_TEST_PASS(gs1_lint_hhmm, "1600");
UNIT_TEST_PASS(gs1_lint_hhmm, "1700");
UNIT_TEST_PASS(gs1_lint_hhmm, "1800");
UNIT_TEST_PASS(gs1_lint_hhmm, "1900");
UNIT_TEST_PASS(gs1_lint_hhmm, "2000");
UNIT_TEST_PASS(gs1_lint_hhmm, "2100");
UNIT_TEST_PASS(gs1_lint_hhmm, "2200");
UNIT_TEST_PASS(gs1_lint_hhmm, "2300");
UNIT_TEST_FAIL(gs1_lint_hhmm, "2400", GS1_LINTER_ILLEGAL_HOUR, "*24*00");

UNIT_TEST_PASS(gs1_lint_hhmm, "0001");
UNIT_TEST_PASS(gs1_lint_hhmm, "0002");
UNIT_TEST_PASS(gs1_lint_hhmm, "0003");
UNIT_TEST_PASS(gs1_lint_hhmm, "0004");
UNIT_TEST_PASS(gs1_lint_hhmm, "0005");
UNIT_TEST_PASS(gs1_lint_hhmm, "0006");
UNIT_TEST_PASS(gs1_lint_hhmm, "0007");
UNIT_TEST_PASS(gs1_lint_hhmm, "0008");
UNIT_TEST_PASS(gs1_lint_hhmm, "0009");
UNIT_TEST_PASS(gs1_lint_hhmm, "0010");
UNIT_TEST_PASS(gs1_lint_hhmm, "0011");
UNIT_TEST_PASS(gs1_lint_hhmm, "0012");
UNIT_TEST_PASS(gs1_lint_hhmm, "0013");
UNIT_TEST_PASS(gs1_lint_hhmm, "0014");
UNIT_TEST_PASS(gs1_lint_hhmm, "0015");
UNIT_TEST_PASS(gs1_lint_hhmm, "0016");
UNIT_TEST_PASS(gs1_lint_hhmm, "0017");
UNIT_TEST_PASS(gs1_lint_hhmm, "0018");
UNIT_TEST_PASS(gs1_lint_hhmm, "0019");
UNIT_TEST_PASS(gs1_lint_hhmm, "0020");
UNIT_TEST_PASS(gs1_lint_hhmm, "0021");
UNIT_TEST_PASS(gs1_lint_hhmm, "0022");
UNIT_TEST_PASS(gs1_lint_hhmm, "0023");
UNIT_TEST_PASS(gs1_lint_hhmm, "0024");
UNIT_TEST_PASS(gs1_lint_hhmm, "0025");
UNIT_TEST_PASS(gs1_lint_hhmm, "0026");
UNIT_TEST_PASS(gs1_lint_hhmm, "0027");
UNIT_TEST_PASS(gs1_lint_hhmm, "0028");
UNIT_TEST_PASS(gs1_lint_hhmm, "0029");
UNIT_TEST_PASS(gs1_lint_hhmm, "0030");
UNIT_TEST_PASS(gs1_lint_hhmm, "0031");
UNIT_TEST_PASS(gs1_lint_hhmm, "0032");
UNIT_TEST_PASS(gs1_lint_hhmm, "0033");
UNIT_TEST_PASS(gs1_lint_hhmm, "0034");
UNIT_TEST_PASS(gs1_lint_hhmm, "0035");
UNIT_TEST_PASS(gs1_lint_hhmm, "0036");
UNIT_TEST_PASS(gs1_lint_hhmm, "0037");
UNIT_TEST_PASS(gs1_lint_hhmm, "0038");
UNIT_TEST_PASS(gs1_lint_hhmm, "0039");
UNIT_TEST_PASS(gs1_lint_hhmm, "0040");
UNIT_TEST_PASS(gs1_lint_hhmm, "0041");
UNIT_TEST_PASS(gs1_lint_hhmm, "0042");
UNIT_TEST_PASS(gs1_lint_hhmm, "0043");
UNIT_TEST_PASS(gs1_lint_hhmm, "0044");
UNIT_TEST_PASS(gs1_lint_hhmm, "0045");
UNIT_TEST_PASS(gs1_lint_hhmm, "0046");
UNIT_TEST_PASS(gs1_lint_hhmm, "0047");
UNIT_TEST_PASS(gs1_lint_hhmm, "0048");
UNIT_TEST_PASS(gs1_lint_hhmm, "0049");
UNIT_TEST_PASS(gs1_lint_hhmm, "0050");
UNIT_TEST_PASS(gs1_lint_hhmm, "0051");
UNIT_TEST_PASS(gs1_lint_hhmm, "0052");
UNIT_TEST_PASS(gs1_lint_hhmm, "0053");
UNIT_TEST_PASS(gs1_lint_hhmm, "0054");
UNIT_TEST_PASS(gs1_lint_hhmm, "0055");
UNIT_TEST_PASS(gs1_lint_hhmm, "0056");
UNIT_TEST_PASS(gs1_lint_hhmm, "0057");
UNIT_TEST_PASS(gs1_lint_hhmm, "0058");
UNIT_TEST_PASS(gs1_lint_hhmm, "0059");
UNIT_TEST_FAIL(gs1_lint_hhmm, "0060", GS1_LINTER_ILLEGAL_MINUTE, "00*60*");

Expand Down
56 changes: 56 additions & 0 deletions src/c-lib/syntax/lint_importeridx.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,67 @@ void test_lint_importeridx(void)

UNIT_TEST_PASS(gs1_lint_importeridx, "-");
UNIT_TEST_PASS(gs1_lint_importeridx, "0");
UNIT_TEST_PASS(gs1_lint_importeridx, "1");
UNIT_TEST_PASS(gs1_lint_importeridx, "2");
UNIT_TEST_PASS(gs1_lint_importeridx, "3");
UNIT_TEST_PASS(gs1_lint_importeridx, "4");
UNIT_TEST_PASS(gs1_lint_importeridx, "5");
UNIT_TEST_PASS(gs1_lint_importeridx, "6");
UNIT_TEST_PASS(gs1_lint_importeridx, "7");
UNIT_TEST_PASS(gs1_lint_importeridx, "8");
UNIT_TEST_PASS(gs1_lint_importeridx, "9");
UNIT_TEST_PASS(gs1_lint_importeridx, "A");
UNIT_TEST_PASS(gs1_lint_importeridx, "B");
UNIT_TEST_PASS(gs1_lint_importeridx, "C");
UNIT_TEST_PASS(gs1_lint_importeridx, "D");
UNIT_TEST_PASS(gs1_lint_importeridx, "E");
UNIT_TEST_PASS(gs1_lint_importeridx, "F");
UNIT_TEST_PASS(gs1_lint_importeridx, "G");
UNIT_TEST_PASS(gs1_lint_importeridx, "H");
UNIT_TEST_PASS(gs1_lint_importeridx, "I");
UNIT_TEST_PASS(gs1_lint_importeridx, "J");
UNIT_TEST_PASS(gs1_lint_importeridx, "K");
UNIT_TEST_PASS(gs1_lint_importeridx, "L");
UNIT_TEST_PASS(gs1_lint_importeridx, "M");
UNIT_TEST_PASS(gs1_lint_importeridx, "N");
UNIT_TEST_PASS(gs1_lint_importeridx, "O");
UNIT_TEST_PASS(gs1_lint_importeridx, "P");
UNIT_TEST_PASS(gs1_lint_importeridx, "Q");
UNIT_TEST_PASS(gs1_lint_importeridx, "R");
UNIT_TEST_PASS(gs1_lint_importeridx, "S");
UNIT_TEST_PASS(gs1_lint_importeridx, "T");
UNIT_TEST_PASS(gs1_lint_importeridx, "U");
UNIT_TEST_PASS(gs1_lint_importeridx, "V");
UNIT_TEST_PASS(gs1_lint_importeridx, "W");
UNIT_TEST_PASS(gs1_lint_importeridx, "X");
UNIT_TEST_PASS(gs1_lint_importeridx, "Y");
UNIT_TEST_PASS(gs1_lint_importeridx, "Z");
UNIT_TEST_PASS(gs1_lint_importeridx, "_");
UNIT_TEST_PASS(gs1_lint_importeridx, "a");
UNIT_TEST_PASS(gs1_lint_importeridx, "b");
UNIT_TEST_PASS(gs1_lint_importeridx, "c");
UNIT_TEST_PASS(gs1_lint_importeridx, "d");
UNIT_TEST_PASS(gs1_lint_importeridx, "e");
UNIT_TEST_PASS(gs1_lint_importeridx, "f");
UNIT_TEST_PASS(gs1_lint_importeridx, "g");
UNIT_TEST_PASS(gs1_lint_importeridx, "h");
UNIT_TEST_PASS(gs1_lint_importeridx, "i");
UNIT_TEST_PASS(gs1_lint_importeridx, "j");
UNIT_TEST_PASS(gs1_lint_importeridx, "k");
UNIT_TEST_PASS(gs1_lint_importeridx, "l");
UNIT_TEST_PASS(gs1_lint_importeridx, "m");
UNIT_TEST_PASS(gs1_lint_importeridx, "n");
UNIT_TEST_PASS(gs1_lint_importeridx, "o");
UNIT_TEST_PASS(gs1_lint_importeridx, "p");
UNIT_TEST_PASS(gs1_lint_importeridx, "q");
UNIT_TEST_PASS(gs1_lint_importeridx, "r");
UNIT_TEST_PASS(gs1_lint_importeridx, "s");
UNIT_TEST_PASS(gs1_lint_importeridx, "t");
UNIT_TEST_PASS(gs1_lint_importeridx, "u");
UNIT_TEST_PASS(gs1_lint_importeridx, "v");
UNIT_TEST_PASS(gs1_lint_importeridx, "w");
UNIT_TEST_PASS(gs1_lint_importeridx, "x");
UNIT_TEST_PASS(gs1_lint_importeridx, "y");
UNIT_TEST_PASS(gs1_lint_importeridx, "z");

UNIT_TEST_FAIL(gs1_lint_importeridx, " ", GS1_LINTER_INVALID_IMPORT_IDX_CHARACTER, "* *");
Expand Down
3 changes: 3 additions & 0 deletions src/c-lib/syntax/lint_iso3166999.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ void test_lint_iso3166999(void)
UNIT_TEST_PASS(gs1_lint_iso3166999, "004");
UNIT_TEST_PASS(gs1_lint_iso3166999, "894");

UNIT_TEST_FAIL(gs1_lint_iso3166999, "000", GS1_LINTER_NOT_ISO3166_OR_999, "*000*");
UNIT_TEST_FAIL(gs1_lint_iso3166999, "998", GS1_LINTER_NOT_ISO3166_OR_999, "*998*");

UNIT_TEST_FAIL(gs1_lint_iso3166999, "", GS1_LINTER_NOT_ISO3166_OR_999, "**");
UNIT_TEST_FAIL(gs1_lint_iso3166999, "9", GS1_LINTER_NOT_ISO3166_OR_999, "*9*");
UNIT_TEST_FAIL(gs1_lint_iso3166999, "99", GS1_LINTER_NOT_ISO3166_OR_999, "*99*");
Expand Down
8 changes: 6 additions & 2 deletions src/c-lib/syntax/lint_iso5218.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ void test_lint_iso5218(void)
UNIT_TEST_PASS(gs1_lint_iso5218, "0");
UNIT_TEST_PASS(gs1_lint_iso5218, "1");
UNIT_TEST_PASS(gs1_lint_iso5218, "2");
UNIT_TEST_FAIL(gs1_lint_iso5218, "3", GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE, "*3*");
UNIT_TEST_FAIL(gs1_lint_iso5218, "4", GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE, "*4*");
UNIT_TEST_FAIL(gs1_lint_iso5218, "5", GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE, "*5*");
UNIT_TEST_FAIL(gs1_lint_iso5218, "6", GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE, "*6*");
UNIT_TEST_FAIL(gs1_lint_iso5218, "7", GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE, "*7*");
UNIT_TEST_FAIL(gs1_lint_iso5218, "8", GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE, "*8*");
UNIT_TEST_PASS(gs1_lint_iso5218, "9");

UNIT_TEST_FAIL(gs1_lint_iso5218, "", GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE, "**");
UNIT_TEST_FAIL(gs1_lint_iso5218, "/", GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE, "*/*");
UNIT_TEST_FAIL(gs1_lint_iso5218, "3", GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE, "*3*");
UNIT_TEST_FAIL(gs1_lint_iso5218, "8", GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE, "*8*");
UNIT_TEST_FAIL(gs1_lint_iso5218, ":", GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE, "*:*");
UNIT_TEST_FAIL(gs1_lint_iso5218, "01", GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE, "*01*");

Expand Down
62 changes: 32 additions & 30 deletions src/c-lib/syntax/lint_mediatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#include <assert.h>
#include <string.h>
#include <stdint.h>
#include <ctype.h>

#include "gs1syntaxdictionary.h"

Expand All @@ -50,8 +52,6 @@
/**
* Used to validate that an AI component is a valid AIDC media type.
*
* @note The default lookup function provided by this linter is a binary search
* over a static list this is maintained in this file.
* @note To enable this linter to hook into an alternative AIDC media type
* lookup function (provided by the user) the
* GS1_LINTER_CUSTOM_MEDIA_TYPE_LOOKUP_H macro may be set to the name of a
Expand Down Expand Up @@ -93,36 +93,39 @@ GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_mediatype(const char* const da
* Updates to the AIDC media type list shall be announced by GSCN
*
*/
static const char mediatypes[][3] = {
/* 00 Not used */
"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", /* ICCBBA assignments */
/* 11-29 Reserved for future assignment by ICCBBA */
/* 30-59 Reserved for future assignment by GS1 */
/* 60-79 Reserved for future assignment by ICCBBA or GS1 */
"80", "81", "82", "83", "84", "85", "86", "87", "88", "89", /* ICCBBA local / national use */
"90", "91", "92", "93", "94", "95", "96", "97", "98", "99", /* ICCBBA local / national use */
static const uint8_t mediatypes[] = {
#if __STDC_VERSION__ >= 202311L
0b01111111, 0b11100000, // 00-10: ICCBBA assignments
// 11-15: Reserved for future assignment by ICCBBA
0b00000000, 0b00000000, // 16-29: Reserved for future assignment by ICCBBA
// 30-31: Reserved for future assignment by GS1
0b00000000, 0b00000000, // 32-47: Reserved for future assignment by GS1
0b00000000, 0b00000000, // 48-59: Reserved for future assignment by GS1
// 60-63: Reserved for future assignment by ICCBBA or GS1
0b00000000, 0b00000000, // 64-79: Reserved for future assignment by ICCBBA or GS1
0b11111111, 0b11111111, // 80-95: ICCBBA local / national use
0b11110000, // 96-99: ICCBBA local / national use
#else
/*
* Fallback for compilers lacking binary literal support.
*
* Generated from the above data with:
*
* for (size_t i = 0; i < sizeof(mediatypes) / sizeof(mediatypes[0]); i++) { printf("0x%02x, ", mediatypes[i]); };
*
*/
0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf0,
#endif
};

/*
* Binary search over the above list.
*
*/
/// \cond
#define GS1_LINTER_MEDIA_TYPE_LOOKUP(cc) do { \
size_t s = 0; \
size_t e = sizeof(mediatypes) / sizeof(mediatypes[0]); \
while (s < e) { \
const size_t m = s + (e - s) / 2; \
const int cmp = strcmp(mediatypes[m], cc); \
if (cmp < 0) \
s = m + 1; \
else if (cmp > 0) \
e = m; \
else { \
valid = 1; \
break; \
} \
} \
#define GS1_LINTER_MEDIA_TYPE_LOOKUP(cc) do { \
if (strlen(cc) == 2 && isdigit(cc[0]) && isdigit(cc[1])) { \
int v = (cc[0] - '0') * 10 + (cc[1] - '0'); \
assert(v <= 99); /* Satisfy analyzer */ \
if (mediatypes[v/8] & (0x80 >> (v%8))) \
valid = 1; \
} \
} while (0)
/// \endcond

Expand Down Expand Up @@ -160,7 +163,6 @@ void test_lint_mediatype(void)

UNIT_TEST_FAIL(gs1_lint_mediatype, "", GS1_LINTER_INVALID_MEDIA_TYPE, "**");
UNIT_TEST_FAIL(gs1_lint_mediatype, "0", GS1_LINTER_INVALID_MEDIA_TYPE, "*0*");
UNIT_TEST_FAIL(gs1_lint_mediatype, "00", GS1_LINTER_INVALID_MEDIA_TYPE, "*00*");
UNIT_TEST_FAIL(gs1_lint_mediatype, "000", GS1_LINTER_INVALID_MEDIA_TYPE, "*000*");
UNIT_TEST_FAIL(gs1_lint_mediatype, "_01", GS1_LINTER_INVALID_MEDIA_TYPE, "*_01*");
UNIT_TEST_FAIL(gs1_lint_mediatype, "01_", GS1_LINTER_INVALID_MEDIA_TYPE, "*01_*");
Expand Down
Loading

0 comments on commit 93d0b6d

Please sign in to comment.