diff options
| author | innokentii <[email protected]> | 2023-05-07 22:49:43 +0300 |
|---|---|---|
| committer | innokentii <[email protected]> | 2023-05-07 22:49:43 +0300 |
| commit | 71fbfcec68afef3f4fbac197ad143759c320f11e (patch) | |
| tree | 0254709c2048dd04d56658d3bd9c826e2e8dc140 /library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp | |
| parent | 86dc8c9ce69c69f2b2fbf8418bea0093cce4a730 (diff) | |
Add utils for token modification in fyaml
add utils for token modification in fyaml
Diffstat (limited to 'library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp')
| -rw-r--r-- | library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp | 362 |
1 files changed, 352 insertions, 10 deletions
diff --git a/library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp b/library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp index 299fe614a2d..2f6e14138cf 100644 --- a/library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp +++ b/library/cpp/yaml/fyamlcpp/fyamlcpp_ut.cpp @@ -164,22 +164,364 @@ x: b UNIT_ASSERT_VALUES_EQUAL(seq[1].Map().at("b").Sequence().at(2).Scalar(), "3"); } - Y_UNIT_TEST(ScalarMark) { - TString str = R"( + 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); + } - auto doc = NFyaml::TDocument::Parse(str); + { + TString str = R"(obj: '123')"; + auto doc = NFyaml::TDocument::Parse(str); + auto node = doc.Root().Map().at("obj"); + check(str, node); + } - auto node = doc.Root().Map().at("test").Sequence().at(0).Map().at("obj"); + { + TString str = R"(obj: '123' # test)"; + auto doc = NFyaml::TDocument::Parse(str); + auto node = doc.Root().Map().at("obj"); + check(str, node); + } - auto pos = str.find("123"); - auto begin = node.ScalarBeginMark().InputPos; - auto end = node.ScalarEndMark().InputPos; + { + TString str = R"( +# test +obj: '123' # test +# test +)"; + auto doc = NFyaml::TDocument::Parse(str); + auto node = doc.Root().Map().at("obj"); + check(str, node); + } - UNIT_ASSERT_VALUES_EQUAL(begin, pos); - UNIT_ASSERT_VALUES_EQUAL(end, pos + strlen("123")); + { + 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); + } + } + } |
