diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-07-05 22:00:57 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-07-31 14:37:41 +0300 |
commit | 064536ef079051dd0af53b7f311bef4aa4670ccb (patch) | |
tree | 741e629ab6644e853c92e254702b269bf771fee7 | |
parent | dfc1d78fd95694b65ce80be90970be9ef305f973 (diff) |
Serialize manifest using new-fashioned multi-line mode introducer (as in 'foo:<newline>\<newline>')
-rw-r--r-- | libbutl/manifest-serializer.cxx | 5 | ||||
-rw-r--r-- | libbutl/manifest-serializer.hxx | 9 | ||||
-rw-r--r-- | tests/manifest-rewriter/driver.cxx | 12 | ||||
-rw-r--r-- | tests/manifest-roundtrip/driver.cxx | 13 | ||||
-rw-r--r-- | tests/manifest-roundtrip/testscript | 26 | ||||
-rw-r--r-- | tests/manifest-serializer/driver.cxx | 38 |
6 files changed, 49 insertions, 54 deletions
diff --git a/libbutl/manifest-serializer.cxx b/libbutl/manifest-serializer.cxx index 26699e0..ca6aefe 100644 --- a/libbutl/manifest-serializer.cxx +++ b/libbutl/manifest-serializer.cxx @@ -364,10 +364,7 @@ namespace butl v.back () == ' ' || v.back () == '\t') { - if (multiline_v2_) - os_ << endl; - - os_ << "\\" << endl; // Multi-line mode introducer. + os_ << endl << "\\" << endl; // Multi-line mode introducer. // Chunk the value into fragments separated by newlines. // diff --git a/libbutl/manifest-serializer.hxx b/libbutl/manifest-serializer.hxx index 2159901..ad81ad2 100644 --- a/libbutl/manifest-serializer.hxx +++ b/libbutl/manifest-serializer.hxx @@ -45,19 +45,14 @@ namespace butl // Unless long_lines is true, break lines in values (including multi-line) // so that their length does not exceed 78 codepoints (including '\n'). // - // Note that the multiline_v2 flag is temporary and should not be used - // except by the implementation for testing. - // manifest_serializer (std::ostream& os, const std::string& name, bool long_lines = false, - std::function<filter_function> filter = {}, - bool multiline_v2 = false) + std::function<filter_function> filter = {}) : os_ (os), name_ (name), long_lines_ (long_lines), - filter_ (std::move (filter)), - multiline_v2_ (multiline_v2) + filter_ (std::move (filter)) { } diff --git a/tests/manifest-rewriter/driver.cxx b/tests/manifest-rewriter/driver.cxx index 3b1dfe9..3a6c19f 100644 --- a/tests/manifest-rewriter/driver.cxx +++ b/tests/manifest-rewriter/driver.cxx @@ -67,26 +67,26 @@ namespace butl {{"a", "xyz"}, edit_cmd {"x", "y", "c"}, {"e", "123"}}) == ":1\na: xyz\nc:d\nx: y\ne: 123"); - assert (edit (":1\na: b", {{"a", "xy\nz"}}) == ":1\na:\\\nxy\nz\n\\"); + assert (edit (":1\na: b", {{"a", "xy\nz"}}) == ":1\na:\n\\\nxy\nz\n\\"); assert (edit (":1\na:\\\nxy\nz\n\\\nb: c", {{"a", "ab\ncd\ne"}}) == - ":1\na:\\\nab\ncd\ne\n\\\nb: c"); + ":1\na:\n\\\nab\ncd\ne\n\\\nb: c"); assert (edit (":1\na: \\\nxy\nz\n\\\nb: c", {{"a", "ab\ncd\ne"}}) == - ":1\na:\\\nab\ncd\ne\n\\\nb: c"); + ":1\na:\n\\\nab\ncd\ne\n\\\nb: c"); assert (edit (":1\na:\n\\\nxy\nz\n\\\nb: c", {{"a", "ab\ncd\ne"}}) == - ":1\na:\\\nab\ncd\ne\n\\\nb: c"); + ":1\na:\n\\\nab\ncd\ne\n\\\nb: c"); assert (edit (":1\n", {{"a", "b", ""}}) == ":1\na: b\n"); assert (edit (":1\n abc: b", {{"abc", "xyz"}}) == - ":1\n abc:\\\nxyz\n\\"); + ":1\n abc:\n\\\nxyz\n\\"); assert (edit (":1\n a\xD0\xB0g : b", {{"a\xD0\xB0g", "xyz"}}) == - ":1\n a\xD0\xB0g :\\\nxyz\n\\"); + ":1\n a\xD0\xB0g :\n\\\nxyz\n\\"); // Test editing of manifests that contains CR characters. // diff --git a/tests/manifest-roundtrip/driver.cxx b/tests/manifest-roundtrip/driver.cxx index c63a729..2aa4120 100644 --- a/tests/manifest-roundtrip/driver.cxx +++ b/tests/manifest-roundtrip/driver.cxx @@ -19,9 +19,6 @@ using namespace butl; // // Round-trip a manifest reading it from stdin and printing to stdout. // -// -m -// Serialize multi-line manifest values using the v2 form. -// // -s // Split values into the value/comment pairs and merge them back before // printing. @@ -30,17 +27,16 @@ int main (int argc, const char* argv[]) try { - bool multiline_v2 (false); bool split (false); for (int i (1); i != argc; ++i) { string v (argv[i]); - if (v == "-m") - multiline_v2 = true; - else if (v == "-s") + if (v == "-s") split = true; + else + assert (false); } // Read/write in binary mode. @@ -53,8 +49,7 @@ try manifest_serializer s (cout, "stdout", false /* long_lines */, - {} /* filter */, - multiline_v2); + {} /* filter */); for (bool eom (true), eos (false); !eos; ) { diff --git a/tests/manifest-roundtrip/testscript b/tests/manifest-roundtrip/testscript index a228b0f..4373fa1 100644 --- a/tests/manifest-roundtrip/testscript +++ b/tests/manifest-roundtrip/testscript @@ -13,7 +13,8 @@ $* <<EOF >>EOF description: A very very very very very very very very very very very very\ very very very very very very very very very very very very very very very\ very very long description. - changes:\ + changes: + \ 1.0.1 - Fixed a very very very very very very very very very very very very very\ very annoying bug. @@ -32,7 +33,8 @@ $* <<EOF >>EOF requires: c++11 : path: c:\windows\\ - path:\ + path: + \ c:\windows\\ \ @@ -40,7 +42,7 @@ $* <<EOF >>EOF : multiline-v2 : -$* -m <<EOF >>EOF +$* <<EOF >>EOF : 1 name: libbpkg version: 1.0.1 @@ -81,35 +83,41 @@ $* -m <<EOF >>EOF : $* -s <<EOF >>EOF : 1 - info:\ + info: + \ value text \ - info:\ + info: + \ value text ; comment \ - info:\ + info: + \ ; comment text \ - info:\ + info: + \ value \; \\ ; comment \ - info:\ + info: + \ value \\; ; comment \ - info:\ + info: + \ value \\\\; ; diff --git a/tests/manifest-serializer/driver.cxx b/tests/manifest-serializer/driver.cxx index a003fa4..2233592 100644 --- a/tests/manifest-serializer/driver.cxx +++ b/tests/manifest-serializer/driver.cxx @@ -189,21 +189,21 @@ main () // string n ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); assert (test ({{"","1"},{n,"x"},{"",""},{"",""}}, - ": 1\n" + n + ":\\\nx\n\\\n")); + ": 1\n" + n + ":\n\\\nx\n\\\n")); assert (test ({{"","1"},{"a","\n"},{"",""},{"",""}}, - ": 1\na:\\\n\n\n\\\n")); + ": 1\na:\n\\\n\n\n\\\n")); assert (test ({{"","1"},{"a","\n\n"},{"",""},{"",""}}, - ": 1\na:\\\n\n\n\n\\\n")); + ": 1\na:\n\\\n\n\n\n\\\n")); assert (test ({{"","1"},{"a","\nx\n"},{"",""},{"",""}}, - ": 1\na:\\\n\nx\n\n\\\n")); + ": 1\na:\n\\\n\nx\n\n\\\n")); assert (test ({{"","1"},{"a","x\ny\nz"},{"",""},{"",""}}, - ": 1\na:\\\nx\ny\nz\n\\\n")); + ": 1\na:\n\\\nx\ny\nz\n\\\n")); assert (test ({{"","1"},{"a"," x"},{"",""},{"",""}}, - ": 1\na:\\\n x\n\\\n")); + ": 1\na:\n\\\n x\n\\\n")); assert (test ({{"","1"},{"a","x "},{"",""},{"",""}}, - ": 1\na:\\\nx \n\\\n")); + ": 1\na:\n\\\nx \n\\\n")); assert (test ({{"","1"},{"a"," x "},{"",""},{"",""}}, - ": 1\na:\\\n x \n\\\n")); + ": 1\na:\n\\\n x \n\\\n")); // The long lines mode. // @@ -212,42 +212,42 @@ main () true /* long_lines */)); assert (test ({{"","1"},{"a", " abc\n" + l1 + "\ndef"},{"",""},{"",""}}, - ": 1\na:\\\n abc\n" + l1 + "\ndef\n\\\n", + ": 1\na:\n\\\n abc\n" + l1 + "\ndef\n\\\n", true /* long_lines */)); assert (test ({{"","1"},{n,l1},{"",""},{"",""}}, - ": 1\n" + n + ":\\\n" + l1 + "\n\\\n", + ": 1\n" + n + ":\n\\\n" + l1 + "\n\\\n", true /* long_lines */)); // Carriage return character. // assert (test ({{"","1"},{"a","x\ry"},{"",""},{"",""}}, - ": 1\na:\\\nx\ny\n\\\n")); + ": 1\na:\n\\\nx\ny\n\\\n")); assert (test ({{"","1"},{"a","x\r"},{"",""},{"",""}}, - ": 1\na:\\\nx\n\n\\\n")); + ": 1\na:\n\\\nx\n\n\\\n")); assert (test ({{"","1"},{"a","x\r\ny"},{"",""},{"",""}}, - ": 1\na:\\\nx\ny\n\\\n")); + ": 1\na:\n\\\nx\ny\n\\\n")); assert (test ({{"","1"},{"a","x\r\n"},{"",""},{"",""}}, - ": 1\na:\\\nx\n\n\\\n")); + ": 1\na:\n\\\nx\n\n\\\n")); // Extra three x's are for the leading name part ("a: ") that we // don't have. // assert (test ({{"","1"},{"a","\nxxx" + l1},{"",""},{"",""}}, - ": 1\na:\\\n\nxxx" + e1 + "\n\\\n")); + ": 1\na:\n\\\n\nxxx" + e1 + "\n\\\n")); assert (test ({{"","1"},{"a","\nxxx" + l2},{"",""},{"",""}}, - ": 1\na:\\\n\nxxx" + e2 + "\n\\\n")); + ": 1\na:\n\\\n\nxxx" + e2 + "\n\\\n")); assert (test ({{"","1"},{"a","\nxxx" + l3},{"",""},{"",""}}, - ": 1\na:\\\n\nxxx" + e3 + "\n\\\n")); + ": 1\na:\n\\\n\nxxx" + e3 + "\n\\\n")); assert (test ({{"","1"},{"a","\nxxx" + l4},{"",""},{"",""}}, - ": 1\na:\\\n\nxxx" + e4 + "\n\\\n")); + ": 1\na:\n\\\n\nxxx" + e4 + "\n\\\n")); // Backslash escaping (simple and multi-line). // assert (test ({{"","1"},{"a","c:\\"},{"",""},{"",""}}, ": 1\na: c:\\\\\n")); assert (test ({{"","1"},{"a","c:\\\nd:\\"},{"",""},{"",""}}, - ": 1\na:\\\nc:\\\\\nd:\\\\\n\\\n")); + ": 1\na:\n\\\nc:\\\\\nd:\\\\\n\\\n")); // Manifest value/comment merging. // |