aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson_pull/ut/reader_ut.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/yson_pull/ut/reader_ut.cpp
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yson_pull/ut/reader_ut.cpp')
-rw-r--r--library/cpp/yson_pull/ut/reader_ut.cpp264
1 files changed, 132 insertions, 132 deletions
diff --git a/library/cpp/yson_pull/ut/reader_ut.cpp b/library/cpp/yson_pull/ut/reader_ut.cpp
index 1184265ddb..f208a94be1 100644
--- a/library/cpp/yson_pull/ut/reader_ut.cpp
+++ b/library/cpp/yson_pull/ut/reader_ut.cpp
@@ -7,19 +7,19 @@
#include <library/cpp/testing/unittest/registar.h>
namespace {
- NYsonPull::TReader memory_reader(TStringBuf data, NYsonPull::EStreamType mode) {
- return NYsonPull::TReader(
- NYsonPull::NInput::FromMemory(data),
- mode);
- }
-
- template <typename T>
- void expect_scalar(const NYsonPull::TScalar& scalar, T value) {
- UNIT_ASSERT_VALUES_EQUAL(NYsonPull::TScalar{value}, scalar);
- }
-
- template <>
- void expect_scalar(const NYsonPull::TScalar& scalar, double value) {
+ NYsonPull::TReader memory_reader(TStringBuf data, NYsonPull::EStreamType mode) {
+ return NYsonPull::TReader(
+ NYsonPull::NInput::FromMemory(data),
+ mode);
+ }
+
+ template <typename T>
+ void expect_scalar(const NYsonPull::TScalar& scalar, T value) {
+ UNIT_ASSERT_VALUES_EQUAL(NYsonPull::TScalar{value}, scalar);
+ }
+
+ template <>
+ void expect_scalar(const NYsonPull::TScalar& scalar, double value) {
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EScalarType::Float64, scalar.Type());
auto scalarValue = scalar.AsFloat64();
@@ -35,34 +35,34 @@ namespace {
} else {
UNIT_ASSERT_C(std::isinf(scalarValue) && (scalarValue < 0), message);
}
- }
+ }
- template <typename T>
- void test_scalar(TStringBuf data, T value) {
- // SCOPED_TRACE(NYsonPull::detail::cescape::quote(data));
- auto reader = memory_reader(data, NYsonPull::EStreamType::Node);
+ template <typename T>
+ void test_scalar(TStringBuf data, T value) {
+ // SCOPED_TRACE(NYsonPull::detail::cescape::quote(data));
+ auto reader = memory_reader(data, NYsonPull::EStreamType::Node);
- try {
+ try {
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::BeginStream, reader.NextEvent().Type());
- {
+ {
auto& event = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Scalar, event.Type());
expect_scalar(event.AsScalar(), value);
- }
+ }
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::EndStream, reader.NextEvent().Type());
- } catch (const std::exception& err) {
- UNIT_FAIL(err.what());
+ } catch (const std::exception& err) {
+ UNIT_FAIL(err.what());
}
}
- void consume(TStringBuf data, NYsonPull::EStreamType mode = NYsonPull::EStreamType::Node) {
- // SCOPED_TRACE(NYsonPull::detail::cescape::quote(data));
+ void consume(TStringBuf data, NYsonPull::EStreamType mode = NYsonPull::EStreamType::Node) {
+ // SCOPED_TRACE(NYsonPull::detail::cescape::quote(data));
auto input_range = NYsonPull::TStreamEventsRange(
- NYsonPull::NInput::FromMemory(data),
- mode);
- for (auto& event : input_range) {
- Y_UNUSED(event);
- }
+ NYsonPull::NInput::FromMemory(data),
+ mode);
+ for (auto& event : input_range) {
+ Y_UNUSED(event);
+ }
}
#define ACCEPT(data) UNIT_ASSERT_NO_EXCEPTION(consume(data))
@@ -76,7 +76,7 @@ namespace {
Y_UNIT_TEST_SUITE(Reader) {
Y_UNIT_TEST(ScalarEntity) {
test_scalar(TStringBuf("#"), NYsonPull::TScalar{});
- }
+ }
Y_UNIT_TEST(ScalarBoolean) {
test_scalar(TStringBuf("%true"), true);
@@ -85,13 +85,13 @@ Y_UNIT_TEST_SUITE(Reader) {
test_scalar(TStringBuf("\x05"sv), true);
test_scalar(TStringBuf("\x04"sv), false);
- REJECT("%");
- REJECT("%trueth");
- REJECT("%tru");
- REJECT("%falseth");
- REJECT("%fals");
- REJECT("%hithere");
- }
+ REJECT("%");
+ REJECT("%trueth");
+ REJECT("%tru");
+ REJECT("%falseth");
+ REJECT("%fals");
+ REJECT("%hithere");
+ }
Y_UNIT_TEST(ScalarInt64) {
test_scalar(TStringBuf("1"), i64{1});
@@ -107,10 +107,10 @@ Y_UNIT_TEST_SUITE(Reader) {
test_scalar(TStringBuf("\x02\xbf\x9a\x0c"sv), i64{-100000});
test_scalar(TStringBuf("\x02\xfe\xff\xff\xff\xff\xff\xff\xff\xff\x01"sv), i64{9223372036854775807});
- REJECT("1a2");
- REJECT("1-1-1-1");
- REJECT("1+0");
- }
+ REJECT("1a2");
+ REJECT("1-1-1-1");
+ REJECT("1+0");
+ }
Y_UNIT_TEST(SclarUInt64) {
test_scalar(TStringBuf("1u"), ui64{1});
@@ -122,12 +122,12 @@ Y_UNIT_TEST_SUITE(Reader) {
test_scalar(TStringBuf("18446744073709551615u"), ui64{18446744073709551615u});
test_scalar(TStringBuf("+18446744073709551615u"), ui64{18446744073709551615u});
- REJECT("1a2u");
- REJECT("1-1-1-1u");
- REJECT("1+0u");
+ REJECT("1a2u");
+ REJECT("1-1-1-1u");
+ REJECT("1+0u");
- // TODO: binary
- }
+ // TODO: binary
+ }
Y_UNIT_TEST(ScalarFloat64) {
test_scalar(TStringBuf("0.0"), double{0.0});
@@ -171,19 +171,19 @@ Y_UNIT_TEST_SUITE(Reader) {
TStringBuf("%-inf"),
double{-std::numeric_limits<double>::infinity()});
- REJECT("++0.0");
- REJECT("++1.0");
- REJECT("++.1");
- REJECT("1.0.0");
- //REJECT("1e+10000");
+ REJECT("++0.0");
+ REJECT("++1.0");
+ REJECT("++.1");
+ REJECT("1.0.0");
+ //REJECT("1e+10000");
REJECT(TStringBuf("\x03\x00\x00\x00\x00\x00\x00\x00"sv));
- // XXX: Questionable behaviour?
- ACCEPT("+.0");
- ACCEPT("-.0");
- // XXX: Rejected on Mac OS, accepted on Linux (?!)
- //REJECT(".0");
- //REJECT(".5");
+ // XXX: Questionable behaviour?
+ ACCEPT("+.0");
+ ACCEPT("-.0");
+ // XXX: Rejected on Mac OS, accepted on Linux (?!)
+ //REJECT(".0");
+ //REJECT(".5");
REJECT("%NaN");
REJECT("%+inf");
@@ -191,118 +191,118 @@ Y_UNIT_TEST_SUITE(Reader) {
REJECT("%na");
REJECT("%in");
REJECT("%-in");
- }
+ }
Y_UNIT_TEST(ScalarString) {
test_scalar(TStringBuf(R"(foobar)"), TStringBuf("foobar"));
test_scalar(TStringBuf(R"(foobar11)"), TStringBuf("foobar11"));
test_scalar(TStringBuf(R"("foobar")"), TStringBuf("foobar"));
- // wat? "\x0cf" parsed as a single char? no way!
+ // wat? "\x0cf" parsed as a single char? no way!
test_scalar("\x01\x0c" "foobar"sv,
TStringBuf("foobar"));
- REJECT(R"("foobar)");
+ REJECT(R"("foobar)");
REJECT("\x01\x0c" "fooba"sv);
REJECT("\x01\x0d" "foobar"sv); // negative length
- }
+ }
Y_UNIT_TEST(EmptyList) {
- auto reader = memory_reader("[]", NYsonPull::EStreamType::Node);
+ auto reader = memory_reader("[]", NYsonPull::EStreamType::Node);
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::BeginStream, reader.NextEvent().Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::BeginList, reader.NextEvent().Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::EndList, reader.NextEvent().Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::EndStream, reader.NextEvent().Type());
- REJECT("[");
- REJECT("]");
- }
+ REJECT("[");
+ REJECT("]");
+ }
Y_UNIT_TEST(EmptyMap) {
- auto reader = memory_reader("{}", NYsonPull::EStreamType::Node);
+ auto reader = memory_reader("{}", NYsonPull::EStreamType::Node);
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::BeginStream, reader.NextEvent().Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::BeginMap, reader.NextEvent().Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::EndMap, reader.NextEvent().Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::EndStream, reader.NextEvent().Type());
- REJECT("{");
- REJECT("}");
- }
+ REJECT("{");
+ REJECT("}");
+ }
Y_UNIT_TEST(Sample) {
- auto reader = memory_reader(
- R"({"11"=11;"nothing"=#;"zero"=0.;"foo"="bar";"list"=[1;2;3]})",
- NYsonPull::EStreamType::Node);
+ auto reader = memory_reader(
+ R"({"11"=11;"nothing"=#;"zero"=0.;"foo"="bar";"list"=[1;2;3]})",
+ NYsonPull::EStreamType::Node);
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::BeginStream, reader.NextEvent().Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::BeginMap, reader.NextEvent().Type());
- {
+ {
auto& e = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Key, e.Type());
UNIT_ASSERT_VALUES_EQUAL(TStringBuf("11"), e.AsString());
- }
- {
+ }
+ {
auto& e = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Scalar, e.Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::TScalar{i64{11}}, e.AsScalar());
- }
+ }
- {
+ {
auto& e = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Key, e.Type());
UNIT_ASSERT_VALUES_EQUAL(TStringBuf("nothing"), e.AsString());
- }
- {
+ }
+ {
auto& e = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Scalar, e.Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::TScalar{}, e.AsScalar());
- }
+ }
- {
+ {
auto& e = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Key, e.Type());
UNIT_ASSERT_VALUES_EQUAL(TStringBuf("zero"), e.AsString());
- }
- {
+ }
+ {
auto& e = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Scalar, e.Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::TScalar{0.0}, e.AsScalar());
- }
+ }
- {
+ {
auto& e = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Key, e.Type());
UNIT_ASSERT_VALUES_EQUAL(TStringBuf("foo"), e.AsString());
- }
- {
+ }
+ {
auto& e = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Scalar, e.Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::TScalar{TStringBuf("bar")}, e.AsScalar());
- }
+ }
- {
+ {
auto& e = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Key, e.Type());
UNIT_ASSERT_VALUES_EQUAL(TStringBuf("list"), e.AsString());
- }
+ }
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::BeginList, reader.NextEvent().Type());
- {
+ {
auto& e = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Scalar, e.Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::TScalar{i64{1}}, e.AsScalar());
- }
- {
+ }
+ {
auto& e = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Scalar, e.Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::TScalar{i64{2}}, e.AsScalar());
- }
- {
+ }
+ {
auto& e = reader.NextEvent();
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Scalar, e.Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::TScalar{i64{3}}, e.AsScalar());
- }
+ }
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::EndList, reader.NextEvent().Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::EndMap, reader.NextEvent().Type());
@@ -310,55 +310,55 @@ Y_UNIT_TEST_SUITE(Reader) {
}
Y_UNIT_TEST(Accept) {
- ACCEPT("[]");
- ACCEPT("{}");
- ACCEPT("<>[]");
- ACCEPT("<>{}");
- ACCEPT("[{};{};{}]");
- ACCEPT("[{};{};{};]");
- ACCEPT("[<>{};<>{};<>{}]");
- ACCEPT("[<>{};<>{};<>{};]");
-
- ACCEPT("foo");
- ACCEPT("[foo]");
- ACCEPT("[foo;]");
- ACCEPT("{foo=foo}");
- ACCEPT("{foo=foo;}");
- ACCEPT("<>{foo=foo}");
- ACCEPT("{foo=<foo=foo>foo}");
- ACCEPT("{foo=<foo=foo;>foo}");
- ACCEPT("{foo=<foo=foo>[foo;foo]}");
+ ACCEPT("[]");
+ ACCEPT("{}");
+ ACCEPT("<>[]");
+ ACCEPT("<>{}");
+ ACCEPT("[{};{};{}]");
+ ACCEPT("[{};{};{};]");
+ ACCEPT("[<>{};<>{};<>{}]");
+ ACCEPT("[<>{};<>{};<>{};]");
+
+ ACCEPT("foo");
+ ACCEPT("[foo]");
+ ACCEPT("[foo;]");
+ ACCEPT("{foo=foo}");
+ ACCEPT("{foo=foo;}");
+ ACCEPT("<>{foo=foo}");
+ ACCEPT("{foo=<foo=foo>foo}");
+ ACCEPT("{foo=<foo=foo;>foo}");
+ ACCEPT("{foo=<foo=foo>[foo;foo]}");
}
Y_UNIT_TEST(Reject) {
- REJECT("[");
- REJECT("{");
- REJECT("<");
+ REJECT("[");
+ REJECT("{");
+ REJECT("<");
- REJECT("[[}]");
- REJECT("<>{]");
- REJECT("[>]");
+ REJECT("[[}]");
+ REJECT("<>{]");
+ REJECT("[>]");
- REJECT("<><>[]");
- REJECT("[<>;<>]");
+ REJECT("<><>[]");
+ REJECT("[<>;<>]");
- REJECT("{<>foo=foo}");
- REJECT("{foo=<>}");
- REJECT("{foo}");
+ REJECT("{<>foo=foo}");
+ REJECT("{foo=<>}");
+ REJECT("{foo}");
- REJECT("<a=b>");
- REJECT("<>");
+ REJECT("<a=b>");
+ REJECT("<>");
REJECT("@");
- }
+ }
Y_UNIT_TEST(ReadPastEnd) {
- auto reader = memory_reader("#", NYsonPull::EStreamType::Node);
+ auto reader = memory_reader("#", NYsonPull::EStreamType::Node);
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::BeginStream, reader.NextEvent().Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::Scalar, reader.NextEvent().Type());
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EEventType::EndStream, reader.NextEvent().Type());
UNIT_ASSERT_EXCEPTION(reader.NextEvent(), NYsonPull::NException::TBadInput);
- }
+ }
Y_UNIT_TEST(BadInput) {
// max_size<ui32> < varint size < max_size<ui64>
@@ -405,6 +405,6 @@ Y_UNIT_TEST_SUITE(Reader) {
REJECT2("a=[1]; b=foobar", NYsonPull::EStreamType::Node);
REJECT2("a=[1]; b=foobar", NYsonPull::EStreamType::ListFragment);
ACCEPT2("a=[1]; b=foobar", NYsonPull::EStreamType::MapFragment);
- }
+ }
} // Y_UNIT_TEST_SUITE(Reader)