aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2023-06-15 18:24:59 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2023-06-15 18:26:33 +0300
commit068d4453cf9fc68c875eee73f5c637bb076f6a71 (patch)
treeda3e83fdb9488ea08faa39d8b41916744f9acad7 /library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp
parent7e7de263d4acbc6eacf92b618bcb5f9049bccc9b (diff)
downloadydb-068d4453cf9fc68c875eee73f5c637bb076f6a71.tar.gz
Create stable-23-2 branch
x-stable-origin-commit: 3fd4d58117c143ed9e6b21813ccd9e507d2cd4d3
Diffstat (limited to 'library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp')
-rw-r--r--library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp371
1 files changed, 371 insertions, 0 deletions
diff --git a/library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp b/library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp
index ffe1d4368c..2f6e14138c 100644
--- a/library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp
+++ b/library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp
@@ -11,6 +11,16 @@ Y_UNIT_TEST_SUITE(FYamlCpp) {
UNIT_ASSERT_EQUAL((int)NFyaml::ENodeType::Scalar, FYNT_SCALAR);
UNIT_ASSERT_EQUAL((int)NFyaml::ENodeType::Sequence, FYNT_SEQUENCE);
UNIT_ASSERT_EQUAL((int)NFyaml::ENodeType::Mapping, FYNT_MAPPING);
+
+ UNIT_ASSERT_EQUAL((int)NFyaml::ENodeStyle::Any, FYNS_ANY);
+ UNIT_ASSERT_EQUAL((int)NFyaml::ENodeStyle::Flow, FYNS_FLOW);
+ UNIT_ASSERT_EQUAL((int)NFyaml::ENodeStyle::Block, FYNS_BLOCK);
+ UNIT_ASSERT_EQUAL((int)NFyaml::ENodeStyle::Plain, FYNS_PLAIN);
+ UNIT_ASSERT_EQUAL((int)NFyaml::ENodeStyle::SingleQuoted, FYNS_SINGLE_QUOTED);
+ UNIT_ASSERT_EQUAL((int)NFyaml::ENodeStyle::DoubleQuoted, FYNS_DOUBLE_QUOTED);
+ UNIT_ASSERT_EQUAL((int)NFyaml::ENodeStyle::Literal, FYNS_LITERAL);
+ UNIT_ASSERT_EQUAL((int)NFyaml::ENodeStyle::Folded, FYNS_FOLDED);
+ UNIT_ASSERT_EQUAL((int)NFyaml::ENodeStyle::Alias, FYNS_ALIAS);
}
Y_UNIT_TEST(ErrorHandling) {
@@ -153,4 +163,365 @@ x: b
UNIT_ASSERT_VALUES_EQUAL(seq[1].Map().at("b").Sequence().at(1).Scalar(), "2");
UNIT_ASSERT_VALUES_EQUAL(seq[1].Map().at("b").Sequence().at(2).Scalar(), "3");
}
+
+ Y_UNIT_TEST(SimpleScalarMark) {
+ auto check = [](const TString& str, const NFyaml::TNodeRef& node) {
+ auto pos = str.find("123");
+ auto endPos = pos + strlen("123");
+ auto begin = node.BeginMark().InputPos;
+ auto end = node.EndMark().InputPos;
+ UNIT_ASSERT_VALUES_EQUAL(begin, pos);
+ UNIT_ASSERT_VALUES_EQUAL(end, endPos);
+ };
+
+ {
+ TString str = R"(obj: 123)";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(obj: 123 # test)";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(
+# test
+obj: 123 # test
+# test
+)";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(
+---
+obj: 123
+...
+)";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(
+a: foo
+test: [{obj: 123}]
+b: bar
+ )";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("test").Sequence().at(0).Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(obj: '123')";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(obj: '123' # test)";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(
+# test
+obj: '123' # test
+# test
+)";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(
+---
+obj: '123'
+...
+)";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(
+a: foo
+test: [{obj: "123"}]
+b: bar
+ )";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("test").Sequence().at(0).Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(obj: "123")";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(obj: "123" # test)";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(
+# test
+obj: "123" # test
+# test
+)";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(
+---
+obj: "123"
+...
+)";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(
+a: foo
+test: [{obj: "123"}]
+b: bar
+ )";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("test").Sequence().at(0).Map().at("obj");
+ check(str, node);
+ }
+
+ {
+ TString str = R"(
+a: foo
+test: [{obj: !!int "123"}]
+b: bar
+ )";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("test").Sequence().at(0).Map().at("obj");
+ check(str, node);
+ }
+
+ }
+
+ Y_UNIT_TEST(MultilineScalarMark) {
+ {
+ TString str = R"(obj: >+2
+ some
+ multiline
+
+ scalar with couple words)";
+ auto doc = NFyaml::TDocument::Parse(str);
+ auto node = doc.Root().Map().at("obj");
+ auto begin = node.BeginMark().InputPos;
+ auto end = node.EndMark().InputPos;
+ UNIT_ASSERT_VALUES_EQUAL(begin, 9);
+ UNIT_ASSERT_VALUES_EQUAL(end, 55);
+ }
+ }
+
+ Y_UNIT_TEST(MapMark) {
+ {
+ TString str = R"(
+a: foo
+map: !!map
+ internal_map1: {}
+ internal_map2:
+ internal_map3:
+ internal_map4:
+ value: 1
+ internal_map5: {
+ internal_map6: {test1: 1, test2: 2},
+ internal_map7: {
+ value: 1
+ }
+ }
+# comment
+c: bar
+ )";
+
+ auto doc = NFyaml::TDocument::Parse(str);
+
+ auto node = doc.Root().Map().at("map");
+
+ auto begin = node.BeginMark().InputPos;
+ auto end = node.EndMark().InputPos;
+
+ UNIT_ASSERT_VALUES_EQUAL(begin, 21);
+ UNIT_ASSERT_VALUES_EQUAL(end, 246);
+ }
+
+ {
+ TString str = R"(
+a: foo
+map: !!map # comment
+# comment
+c: bar
+ )";
+
+ auto doc = NFyaml::TDocument::Parse(str);
+
+ auto node = doc.Root().Map().at("map");
+
+ auto begin = node.BeginMark().InputPos;
+ auto end = node.EndMark().InputPos;
+
+ UNIT_ASSERT_VALUES_EQUAL(begin, 11);
+ UNIT_ASSERT_VALUES_EQUAL(end, 11);
+ }
+
+ {
+ TString str = R"(
+a: foo
+map: {} # comment
+# comment
+c: bar
+ )";
+
+ auto doc = NFyaml::TDocument::Parse(str);
+
+ auto node = doc.Root().Map().at("map");
+
+ auto begin = node.BeginMark().InputPos;
+ auto end = node.EndMark().InputPos;
+
+ UNIT_ASSERT_VALUES_EQUAL(begin, 13);
+ UNIT_ASSERT_VALUES_EQUAL(end, 15);
+ }
+
+ {
+ TString str = R"(
+a: foo
+map:
+ value: 1
+# comment
+c: bar
+ )";
+
+ auto doc = NFyaml::TDocument::Parse(str);
+
+ auto node = doc.Root().Map().at("map");
+
+ auto begin = node.BeginMark().InputPos;
+ auto end = node.EndMark().InputPos;
+
+ UNIT_ASSERT_VALUES_EQUAL(begin, 15);
+ UNIT_ASSERT_VALUES_EQUAL(end, 23);
+ }
+ }
+
+ Y_UNIT_TEST(SequenceMark) {
+ {
+ TString str = R"(
+a: foo
+seq: !!seq
+- internal_map1: {}
+- internal_seq2:
+ - internal_seq3:
+ - internal_seq4:
+ value: 1
+ - internal_seq5: [
+ internal_seq6: [{test1: 1}, {test2: 2}],
+ internal_seq7: [
+ {value: 1}
+ ]
+ ]
+# comment
+c: bar
+ )";
+
+ auto doc = NFyaml::TDocument::Parse(str);
+
+ auto node = doc.Root().Map().at("seq");
+
+ auto begin = node.BeginMark().InputPos;
+ auto end = node.EndMark().InputPos;
+
+ UNIT_ASSERT_VALUES_EQUAL(begin, 19);
+ UNIT_ASSERT_VALUES_EQUAL(end, 252);
+ }
+
+ {
+ TString str = R"(
+a: foo
+seq: !!seq # comment
+# comment
+c: bar
+ )";
+
+ auto doc = NFyaml::TDocument::Parse(str);
+
+ auto node = doc.Root().Map().at("seq");
+
+ auto begin = node.BeginMark().InputPos;
+ auto end = node.EndMark().InputPos;
+
+ UNIT_ASSERT_VALUES_EQUAL(begin, 11);
+ UNIT_ASSERT_VALUES_EQUAL(end, 11);
+ }
+
+ {
+ TString str = R"(
+a: foo
+seq: [] # comment
+# comment
+c: bar
+ )";
+
+ auto doc = NFyaml::TDocument::Parse(str);
+
+ auto node = doc.Root().Map().at("seq");
+
+ auto begin = node.BeginMark().InputPos;
+ auto end = node.EndMark().InputPos;
+
+ UNIT_ASSERT_VALUES_EQUAL(begin, 13);
+ UNIT_ASSERT_VALUES_EQUAL(end, 15);
+ }
+
+ {
+ TString str = R"(
+a: foo
+seq:
+- value: 1
+# comment
+c: bar
+ )";
+
+ auto doc = NFyaml::TDocument::Parse(str);
+
+ auto node = doc.Root().Map().at("seq");
+
+ auto begin = node.BeginMark().InputPos;
+ auto end = node.EndMark().InputPos;
+
+ UNIT_ASSERT_VALUES_EQUAL(begin, 13);
+ UNIT_ASSERT_VALUES_EQUAL(end, 23);
+ }
+ }
+
}