mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
Add PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_Z...
This commit is contained in:
1 parent
4d61a056e0
commit
e82bc8ec7b
5 files changed
+114
-19
No files matched your search
@@ -361,6 +361,41 @@ test_wuffs_strconv_hpd_rounded_integer() {
|
||||
}
|
||||
}
|
||||
|
||||
// Test WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES.
|
||||
{
|
||||
int o;
|
||||
for (o = 0; o < 2; o++) {
|
||||
wuffs_base__private_implementation__high_prec_dec hpd;
|
||||
const char* str = "001.25";
|
||||
wuffs_base__status status =
|
||||
wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
&hpd, wuffs_base__make_slice_u8((void*)str, strlen(str)),
|
||||
(o ? WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES
|
||||
: WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS));
|
||||
|
||||
if (o == 0) {
|
||||
if (status.repr != wuffs_base__error__bad_argument) {
|
||||
RETURN_FAIL(
|
||||
"ALLOW_MULTIPLE_LEADING_ZEROES off: have \"%s\", want \"%s\"",
|
||||
status.repr, wuffs_base__error__bad_argument);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
CHECK_STATUS("ALLOW_MULTIPLE_LEADING_ZEROES on", status);
|
||||
wuffs_base__result_f64 r =
|
||||
wuffs_base__private_implementation__high_prec_dec__to_f64(&hpd, 0);
|
||||
uint64_t have =
|
||||
wuffs_base__ieee_754_bit_representation__from_f64(r.value);
|
||||
uint64_t want = 0x3FF4000000000000;
|
||||
if (have != want) {
|
||||
RETURN_FAIL("ALLOW_MULTIPLE_LEADING_ZEROES on: have 0x%016" PRIX64
|
||||
", want 0x%016" PRIX64,
|
||||
have, want);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test WUFFS_BASE__PARSE_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA.
|
||||
{
|
||||
int o;
|
||||
@@ -913,6 +948,35 @@ test_wuffs_strconv_parse_number_u64() {
|
||||
}
|
||||
}
|
||||
|
||||
// Test WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES.
|
||||
{
|
||||
int o;
|
||||
for (o = 0; o < 2; o++) {
|
||||
const char* str = "007";
|
||||
wuffs_base__result_u64 r = wuffs_base__parse_number_u64(
|
||||
wuffs_base__make_slice_u8((void*)str, strlen(str)),
|
||||
(o ? WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES
|
||||
: WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS));
|
||||
|
||||
if (o == 0) {
|
||||
if (r.status.repr != wuffs_base__error__bad_argument) {
|
||||
RETURN_FAIL(
|
||||
"ALLOW_MULTIPLE_LEADING_ZEROES off: have \"%s\", want \"%s\"",
|
||||
r.status.repr, wuffs_base__error__bad_argument);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
CHECK_STATUS("ALLOW_MULTIPLE_LEADING_ZEROES on", r.status);
|
||||
uint64_t want = 7;
|
||||
if (r.value != want) {
|
||||
RETURN_FAIL("ALLOW_MULTIPLE_LEADING_ZEROES on: have %" PRIu64
|
||||
", want %" PRIu64,
|
||||
r.value, want);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user