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