json_reader_nan_ut.cpp 732 B

1234567891011121314151617181920212223242526272829
  1. #include <library/cpp/json/json_reader.h>
  2. #include <library/cpp/testing/unittest/registar.h>
  3. using namespace NJson;
  4. namespace {
  5. constexpr TStringBuf JSON_NAN_TEST = "{ \"Value1\": 0.0, \"Value2\": 1, \"Value3\": NaN }";
  6. }
  7. Y_UNIT_TEST_SUITE(TJsonReaderNanTest) {
  8. Y_UNIT_TEST(WithoutNanTest) {
  9. TJsonReaderConfig cfg;
  10. TJsonValue out;
  11. // This read will fail
  12. UNIT_ASSERT(!ReadJsonTree(JSON_NAN_TEST, &cfg, &out, /* throwOnError */ false));
  13. }
  14. Y_UNIT_TEST(WithNanTest) {
  15. TJsonReaderConfig cfg;
  16. cfg.AllowReadNanInf = true;
  17. TJsonValue out;
  18. // This read will ok
  19. UNIT_ASSERT(ReadJsonTree(JSON_NAN_TEST, &cfg, &out, /* throwOnError */ false));
  20. }
  21. }