Fix expected value assertion (fix #3430, ref #3393) (#3431)

This commit is contained in:
itchyny authored and GitHub committed 2025-11-04 21:21:21 +09:00
1 parent cff4e00982
commit 33b3a68f9c
1 file changed
+9 -7
+9 -7
View File
@@ -2,7 +2,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#ifdef HAVE_PTHREAD
#include <pthread.h>
#endif
@@ -200,13 +199,16 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
pass = 0;
}
#ifdef USE_DECNUM
if (!(jv_get_kind(expected) == JV_KIND_NUMBER && isnan(jv_number_value(expected)))) {
jv as_string = jv_dump_string(jv_copy(expected), rand() & ~(JV_PRINT_COLOR|JV_PRINT_REFCOUNT));
jv reparsed = jv_parse_sized(jv_string_value(as_string), jv_string_length_bytes(jv_copy(as_string)));
assert(jv_equal(jv_copy(expected), jv_copy(reparsed)));
jv_free(as_string);
jv_free(reparsed);
jv as_string = jv_dump_string(jv_copy(expected), 0);
jv reparsed = jv_parse_sized(jv_string_value(as_string), jv_string_length_bytes(jv_copy(as_string)));
if (!jv_equal(jv_copy(expected), jv_copy(reparsed))) {
printf("*** Expected result should be equal after reparsing, but got ");
jv_dump(jv_copy(reparsed), 0);
printf(" for test at line %u: %s\n", lineno, buf);
pass = 0;
}
jv_free(as_string);
jv_free(reparsed);
#endif
jv_free(expected);
jv_free(actual);