1010
1111#ifndef JSON_TEST_NUMBERS
1212#define JSON_TEST_NUMBERS
13- #endif
13+ #endif
1414
1515#include " jsonparser/common_defs.h"
1616
1717int parse_error;
1818char *fullpath;
1919enum {PARSE_WARNING, PARSE_ERROR};
2020
21+ size_t float_count;
22+ size_t int_count;
23+ size_t invalid_count;
24+
2125inline void foundInvalidNumber (const u8 * buf) {
26+ invalid_count++;
2227 char * endptr;
2328 double expected = strtod ((char *)buf, &endptr);
2429 if (endptr != (char *)buf) {
@@ -29,6 +34,7 @@ inline void foundInvalidNumber(const u8 * buf) {
2934}
3035
3136inline void foundInteger (int64_t result, const u8 * buf) {
37+ int_count++;
3238 char * endptr;
3339 long long expected = strtoll ((char *)buf, & endptr, 10 );
3440 if ((endptr == (char *)buf) || (expected != result)) {
@@ -40,9 +46,10 @@ inline void foundInteger(int64_t result, const u8 * buf) {
4046
4147inline void foundFloat (double result, const u8 * buf) {
4248 char * endptr;
49+ float_count++;
4350 double expected = strtod ((char *)buf, &endptr);
4451 if (endptr == (char *)buf) {
45- printf (" parsed %f from %.32s whereas strtod refuses to parse a float, " , result, buf);
52+ printf (" parsed %f from %.32s whereas strtod refuses to parse a float, " , result, buf);
4653 printf (" while parsing %s \n " , fullpath);
4754 parse_error |= PARSE_ERROR;
4855 }
@@ -107,11 +114,17 @@ bool validate(const char *dirname) {
107114 std::cerr<< " can't allocate memory" <<std::endl;
108115 return false ;
109116 }
117+ float_count = 0 ;
118+ int_count = 0 ;
119+ invalid_count = 0 ;
110120 ParsedJson &pj (*pj_ptr);
111- // bool isok =
121+ bool isok =
112122 json_parse (p.first , p.second , pj);
113- // printf("File %s %s.\n", name,
114- // isok ? " is valid JSON " : " is not valid JSON");
123+ if (int_count+float_count+invalid_count > 0 ) {
124+ printf (" File %40s %s --- integers: %10zu floats: %10zu invalid: %10zu total numbers: %10zu \n " , name,
125+ isok ? " is valid " :
126+ " is not valid " ,int_count, float_count, invalid_count, int_count+float_count+invalid_count);
127+ }
115128 free (p.first );
116129 free (fullpath);
117130 deallocate_ParsedJson (pj_ptr);
0 commit comments