mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 08:46:49 +08:00
remove feature macro from tests
This commit is contained in:
parent
cd28b563fc
commit
43a428d658
@ -4,15 +4,14 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#define FASTFLOAT_ALLOWS_LEADING_PLUS
|
||||
|
||||
#include "fast_float/fast_float.h"
|
||||
|
||||
int main_readme() {
|
||||
const std::string input = "1d+4";
|
||||
double result;
|
||||
fast_float::parse_options options{fast_float::chars_format::fortran};
|
||||
fast_float::parse_options options{
|
||||
fast_float::chars_format::fortran |
|
||||
fast_float::chars_format::allow_leading_plus};
|
||||
auto answer = fast_float::from_chars_advanced(
|
||||
input.data(), input.data() + input.size(), result, options);
|
||||
if ((answer.ec != std::errc()) || ((result != 10000))) {
|
||||
@ -32,7 +31,9 @@ int main() {
|
||||
"1d-1", "1d-2", "1d-3", "1d-4"};
|
||||
const std::vector<std::string> fmt3{"+1+4", "+1+3", "+1+2", "+1+1", "+1+0",
|
||||
"+1-1", "+1-2", "+1-3", "+1-4"};
|
||||
const fast_float::parse_options options{fast_float::chars_format::fortran};
|
||||
const fast_float::parse_options options{
|
||||
fast_float::chars_format::fortran |
|
||||
fast_float::chars_format::allow_leading_plus};
|
||||
|
||||
for (auto const &f : fmt1) {
|
||||
auto d{std::distance(&fmt1[0], &f)};
|
||||
|
||||
@ -2,16 +2,14 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
// test that this option is ignored
|
||||
#define FASTFLOAT_ALLOWS_LEADING_PLUS
|
||||
|
||||
#include "fast_float/fast_float.h"
|
||||
|
||||
int main_readme() {
|
||||
const std::string input = "+.1"; // not valid
|
||||
double result;
|
||||
fast_float::parse_options options{fast_float::chars_format::json};
|
||||
fast_float::parse_options options{
|
||||
fast_float::chars_format::json |
|
||||
fast_float::chars_format::allow_leading_plus}; // should be ignored
|
||||
auto answer = fast_float::from_chars_advanced(
|
||||
input.data(), input.data() + input.size(), result, options);
|
||||
if (answer.ec == std::errc()) {
|
||||
@ -24,7 +22,9 @@ int main_readme() {
|
||||
int main_readme2() {
|
||||
const std::string input = "inf"; // not valid in JSON
|
||||
double result;
|
||||
fast_float::parse_options options{fast_float::chars_format::json};
|
||||
fast_float::parse_options options{
|
||||
fast_float::chars_format::json |
|
||||
fast_float::chars_format::allow_leading_plus}; // should be ignored
|
||||
auto answer = fast_float::from_chars_advanced(
|
||||
input.data(), input.data() + input.size(), result, options);
|
||||
if (answer.ec == std::errc()) {
|
||||
@ -38,7 +38,9 @@ int main_readme3() {
|
||||
const std::string input =
|
||||
"inf"; // not valid in JSON but we allow it with json_or_infnan
|
||||
double result;
|
||||
fast_float::parse_options options{fast_float::chars_format::json_or_infnan};
|
||||
fast_float::parse_options options{
|
||||
fast_float::chars_format::json_or_infnan |
|
||||
fast_float::chars_format::allow_leading_plus}; // should be ignored
|
||||
auto answer = fast_float::from_chars_advanced(
|
||||
input.data(), input.data() + input.size(), result, options);
|
||||
if (answer.ec != std::errc() || (!std::isinf(result))) {
|
||||
@ -129,7 +131,9 @@ int main() {
|
||||
const auto &expected_reason = reject[i].reason;
|
||||
auto answer = fast_float::parse_number_string(
|
||||
f.data(), f.data() + f.size(),
|
||||
fast_float::parse_options(fast_float::chars_format::json));
|
||||
fast_float::parse_options(
|
||||
fast_float::chars_format::json |
|
||||
fast_float::chars_format::allow_leading_plus)); // should be ignored
|
||||
if (answer.valid) {
|
||||
std::cerr << "json parse accepted invalid json " << f << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
* See https://github.com/eddelbuettel/rcppfastfloat/issues/4
|
||||
*/
|
||||
|
||||
#define FASTFLOAT_ALLOWS_LEADING_PLUS 1
|
||||
#define FASTFLOAT_SKIP_WHITE_SPACE 1 // important !
|
||||
#include "fast_float/fast_float.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@ -61,7 +59,10 @@ bool eddelbuettel() {
|
||||
// answer contains a error code and a pointer to the end of the
|
||||
// parsed region (on success).
|
||||
auto const answer = fast_float::from_chars(
|
||||
input.data(), input.data() + input.size(), result);
|
||||
input.data(), input.data() + input.size(), result,
|
||||
fast_float::chars_format::general |
|
||||
fast_float::chars_format::allow_leading_plus |
|
||||
fast_float::chars_format::skip_white_space);
|
||||
if (answer.ec != std::errc()) {
|
||||
std::cout << "could not parse" << std::endl;
|
||||
if (expected_success) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user