This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-1-2
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 8f2575502309dbb53327f73be421e803c5f42713
Author: Alan M. Carroll <[email protected]>
AuthorDate: Mon Mar 30 08:54:39 2020 -0500

    Some IP testing cleanup and comment spelling fixes.
---
 swoc++/include/swoc/BufferWriter.h  |  2 +-
 unit_tests/ex_ipspace_properties.cc | 34 ++++++++++++------------
 unit_tests/test_bw_format.cc        | 53 +++++++++++++++----------------------
 3 files changed, 39 insertions(+), 50 deletions(-)

diff --git a/swoc++/include/swoc/BufferWriter.h 
b/swoc++/include/swoc/BufferWriter.h
index 3a61884..6880120 100644
--- a/swoc++/include/swoc/BufferWriter.h
+++ b/swoc++/include/swoc/BufferWriter.h
@@ -243,7 +243,7 @@ public:
    * - A conversion to @c bool that indicates if there is data left.
    * - A function of the signature <tt>bool ex(std::string_view& lit, 
bwf::Spec & spec)</tt>
    *
-   * The latter must return whether a specificer was parsed, while filling in 
@a lit and @a spec
+   * The latter must return whether a specifier was parsed, while filling in 
@a lit and @a spec
    * as appropriate for the next chunk of format string. No literal is 
represented by a empty
    * @a lit.
    *
diff --git a/unit_tests/ex_ipspace_properties.cc 
b/unit_tests/ex_ipspace_properties.cc
index 9cad01a..196b61a 100644
--- a/unit_tests/ex_ipspace_properties.cc
+++ b/unit_tests/ex_ipspace_properties.cc
@@ -51,7 +51,7 @@ TEST_CASE("IPSpace bitset blending", 
"[libswoc][ipspace][bitset][blending]") {
   // Declare the IPSpace.
   using Space = swoc::IPSpace<PAYLOAD>;
   // Example data type.
-  using Data = std::tuple<TextView, std::initializer_list<unsigned>>;
+  using Data = std::tuple<TextView, PAYLOAD>;
 
   // Dump the ranges to stdout.
   auto dump = [](Space&space) -> void {
@@ -64,10 +64,10 @@ TEST_CASE("IPSpace bitset blending", 
"[libswoc][ipspace][bitset][blending]") {
   };
 
   // Convert a list of bit indices into a bitset.
-  auto make_bits = [](std::initializer_list<unsigned> idx) -> PAYLOAD {
+  auto make_bits = [](std::initializer_list<unsigned> indices) -> PAYLOAD {
     PAYLOAD bits;
-    for (auto bit : idx) {
-      bits[bit] = true;
+    for (auto idx : indices) {
+      bits[idx] = true;
     }
     return bits;
   };
@@ -81,8 +81,8 @@ TEST_CASE("IPSpace bitset blending", 
"[libswoc][ipspace][bitset][blending]") {
   // Example marking functor.
   auto marker = [&](Space & space, swoc::MemSpan<Data> ranges) -> void {
     // For each test range, compute the bitset from the list of bit indices.
-    for (auto &&[text, bit_list] : ranges) {
-      space.blend(IPRange{text}, make_bits(bit_list), blender);
+    for (auto &&[text, bits] : ranges) {
+      space.blend(IPRange{text}, bits, blender);
     }
   };
 
@@ -91,13 +91,13 @@ TEST_CASE("IPSpace bitset blending", 
"[libswoc][ipspace][bitset][blending]") {
 
   // test ranges 1
   std::array<Data, 7> ranges_1 = {{
-        { "100.0.0.0-100.0.0.255", { 0 } }
-      , { "100.0.1.0-100.0.1.255", { 1 } }
-      , { "100.0.2.0-100.0.2.255", { 2 } }
-      , { "100.0.3.0-100.0.3.255", { 3 } }
-      , { "100.0.4.0-100.0.4.255", { 4 } }
-      , { "100.0.5.0-100.0.5.255", { 5 } }
-      , { "100.0.6.0-100.0.6.255", { 6 } }
+        { "100.0.0.0-100.0.0.255", make_bits({ 0 }) }
+      , { "100.0.1.0-100.0.1.255", make_bits({ 1 }) }
+      , { "100.0.2.0-100.0.2.255", make_bits({ 2 }) }
+      , { "100.0.3.0-100.0.3.255", make_bits({ 3 }) }
+      , { "100.0.4.0-100.0.4.255", make_bits({ 4 }) }
+      , { "100.0.5.0-100.0.5.255", make_bits({ 5 }) }
+      , { "100.0.6.0-100.0.6.255", make_bits({ 6 }) }
   }};
 
   marker(space, MemSpan<Data>{ranges_1.data(), ranges_1.size()});
@@ -105,9 +105,9 @@ TEST_CASE("IPSpace bitset blending", 
"[libswoc][ipspace][bitset][blending]") {
 
   // test ranges 2
   std::array<Data, 3> ranges_2 = {{
-      { "100.0.0.0-100.0.0.255", { 31 } }
-    , { "100.0.1.0-100.0.1.255", { 30 } }
-    , { "100.0.2.128-100.0.3.127", { 29 }}
+      { "100.0.0.0-100.0.0.255", make_bits({ 31 }) }
+    , { "100.0.1.0-100.0.1.255", make_bits({ 30 }) }
+    , { "100.0.2.128-100.0.3.127", make_bits({ 29 }) }
   }};
 
   marker(space, MemSpan<Data>{ranges_2.data(), ranges_2.size()});
@@ -115,7 +115,7 @@ TEST_CASE("IPSpace bitset blending", 
"[libswoc][ipspace][bitset][blending]") {
 
   // test ranges 3
   std::array<Data, 1> ranges_3 = {{
-      { "100.0.2.0-100.0.4.255", { 2, 3, 29 }}
+      { "100.0.2.0-100.0.4.255", make_bits({ 2, 3, 29 })}
   }};
 
   marker(space, MemSpan<Data>{ranges_3.data(), ranges_3.size()});
diff --git a/unit_tests/test_bw_format.cc b/unit_tests/test_bw_format.cc
index 8d485fe..f6f0aeb 100644
--- a/unit_tests/test_bw_format.cc
+++ b/unit_tests/test_bw_format.cc
@@ -32,6 +32,7 @@
 #include "catch.hpp"
 
 using namespace std::literals;
+using namespace swoc::literals;
 using swoc::TextView;
 using swoc::bwprint;
 
@@ -58,56 +59,44 @@ TEST_CASE("bwprint basics", "[bwprint]")
 
   bw.print(fmt1);
   REQUIRE(bw.view() == fmt1);
-  bw.clear();
-  bw.print("Arg {}", 1);
+  bw.clear().print("Some text"); // check that a literal string works as 
expected.
+  REQUIRE(bw.view() == fmt1);
+  bw.clear().print("Some text"_tv); // check that a literal TextView works.
+  REQUIRE(bw.view() == fmt1);
+  bw.clear().print("Arg {}", 1);
   REQUIRE(bw.view() == "Arg 1");
-  bw.clear();
-  bw.print("arg 1 {1} and 2 {2} and 0 {0}", "zero", "one", "two");
+  bw.clear().print("arg 1 {1} and 2 {2} and 0 {0}", "zero", "one", "two");
   REQUIRE(bw.view() == "arg 1 one and 2 two and 0 zero");
-  bw.clear();
-  bw.print("args {2}{0}{1}", "zero", "one", "two");
+  bw.clear().print("args {2}{0}{1}", "zero", "one", "two");
   REQUIRE(bw.view() == "args twozeroone");
-  bw.clear();
-  bw.print("left |{:<10}|", "text");
+  bw.clear().print("left |{:<10}|", "text");
   REQUIRE(bw.view() == "left |text      |");
-  bw.clear();
-  bw.print("right |{:>10}|", "text");
+  bw.clear().print("right |{:>10}|", "text");
   REQUIRE(bw.view() == "right |      text|");
-  bw.clear();
-  bw.print("right |{:.>10}|", "text");
+  bw.clear().print("right |{:.>10}|", "text");
   REQUIRE(bw.view() == "right |......text|");
-  bw.clear();
-  bw.print("center |{:.^10}|", "text");
+  bw.clear().print("center |{:.^10}|", "text");
   REQUIRE(bw.view() == "center |...text...|");
-  bw.clear();
-  bw.print("center |{:.^11}|", "text");
+  bw.clear().print("center |{:.^11}|", "text");
   REQUIRE(bw.view() == "center |...text....|");
-  bw.clear();
-  bw.print("center |{:^^10}|", "text");
+  bw.clear().print("center |{:^^10}|", "text");
   REQUIRE(bw.view() == "center |^^^text^^^|");
-  bw.clear();
-  bw.print("center |{:%3A^10}|", "text");
+  bw.clear().print("center |{:%3A^10}|", "text");
   REQUIRE(bw.view() == "center |:::text:::|");
-  bw.clear();
-  bw.print("left >{0:<9}< right >{0:>9}< center >{0:^9}<", 956);
+  bw.clear().print("left >{0:<9}< right >{0:>9}< center >{0:^9}<", 956);
   REQUIRE(bw.view() == "left >956      < right >      956< center >   956   
<");
 
-  bw.clear();
-  bw.print("Format |{:>#010x}|", -956);
+  bw.clear().print("Format |{:>#010x}|", -956);
   REQUIRE(bw.view() == "Format |0000-0x3bc|");
-  bw.clear();
-  bw.print("Format |{:<#010x}|", -956);
+  bw.clear().print("Format |{:<#010x}|", -956);
   REQUIRE(bw.view() == "Format |-0x3bc0000|");
-  bw.clear();
-  bw.print("Format |{:#010x}|", -956);
+  bw.clear().print("Format |{:#010x}|", -956);
   REQUIRE(bw.view() == "Format |-0x00003bc|");
 
-  bw.clear();
-  bw.print("{{BAD_ARG_INDEX:{} of {}}}", 17, 23);
+  bw.clear().print("{{BAD_ARG_INDEX:{} of {}}}", 17, 23);
   REQUIRE(bw.view() == "{BAD_ARG_INDEX:17 of 23}");
 
-  bw.clear();
-  bw.print("Arg {0} Arg {3}", 0, 1);
+  bw.clear().print("Arg {0} Arg {3}", 0, 1);
   REQUIRE(bw.view() == "Arg 0 Arg {BAD_ARG_INDEX:3 of 2}");
 
   bw.clear().print("{{stuff}} Arg {0} Arg {}", 0, 1, 2);

Reply via email to