aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/json/ut/json_reader_nan_ut.cpp
blob: fdd66249eb25ed375b23128f9bdb3e86eba1c81d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <library/cpp/json/json_reader.h>
#include <library/cpp/testing/unittest/registar.h>

using namespace NJson;

namespace {

constexpr TStringBuf JSON_NAN_TEST = "{ \"Value1\": 0.0, \"Value2\": 1, \"Value3\": NaN }";

}

Y_UNIT_TEST_SUITE(TJsonReaderNanTest) {
    Y_UNIT_TEST(WithoutNanTest) {
        TJsonReaderConfig cfg;
        TJsonValue out;
        // This read will fail
        UNIT_ASSERT(!ReadJsonTree(JSON_NAN_TEST, &cfg, &out, /* throwOnError */ false));

    }
    Y_UNIT_TEST(WithNanTest) {
        TJsonReaderConfig cfg;
        cfg.AllowReadNanInf = true;

        TJsonValue out;
        // This read will ok
        UNIT_ASSERT(ReadJsonTree(JSON_NAN_TEST, &cfg, &out, /* throwOnError */ false));
    }
}