Add parser support for bits

Change-Id: I8f36a2639d3f4911c2fb825dd3bf28956886a9a6
diff --git a/tests/leaf_editing.cpp b/tests/leaf_editing.cpp
index 53194c0..7b203f4 100644
--- a/tests/leaf_editing.cpp
+++ b/tests/leaf_editing.cpp
@@ -71,6 +71,8 @@
     schema->addLeaf("/", "mod:dummy", yang::Empty{});
     schema->addLeaf("/", "mod:readonly", yang::Int32{}, yang::AccessType::ReadOnly);
 
+    schema->addLeaf("/", "mod:flags", yang::Bits{{"carry", "sign"}});
+
     Parser parser(schema);
     std::string input;
     std::ostringstream errorStream;
@@ -457,6 +459,33 @@
                 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("dummy"));
                 expected.m_data = empty_{};
             }
+
+            SECTION("bits")
+            {
+                input = "set mod:flags ";
+                decltype(bits_::m_bits) bits;
+                SECTION("<nothing>") {
+                    bits = {};
+                }
+                SECTION("carry") {
+                    input += "carry";
+                    bits = {"carry"};
+                }
+                SECTION("sign") {
+                    input += "sign";
+                    bits = {"sign"};
+                }
+                SECTION("carry sign") {
+                    input += "carry sign";
+                    bits = {"carry", "sign"};
+                }
+                SECTION("sign carry") {
+                    input += "sign carry";
+                    bits = {"sign", "carry"};
+                }
+                expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("flags"));
+                expected.m_data = bits_{bits};
+            }
         }
 
         command_ command = parser.parseCommand(input, errorStream);
@@ -614,6 +643,16 @@
             input = "set mod:readonly 123";
         }
 
+        SECTION("nonexistent bits")
+        {
+            input = "set mod:flags daw";
+        }
+
+        SECTION("same bit more than once")
+        {
+            input = "set mod:flags carry carry";
+        }
+
         REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException);
         REQUIRE(errorStream.str().find(expectedError) != std::string::npos);
     }
diff --git a/tests/yang.cpp b/tests/yang.cpp
index f226778..93e5925 100644
--- a/tests/yang.cpp
+++ b/tests/yang.cpp
@@ -429,6 +429,14 @@
     leaf-list addresses {
         type string;
     }
+
+    leaf flagBits {
+        type bits {
+            bit carry;
+            bit sign;
+            bit overflow;
+        }
+    }
 })";
 
 TEST_CASE("yangschema")
@@ -720,6 +728,13 @@
                 type.emplace<yang::String>();
             }
 
+            SECTION("flagBits")
+            {
+                node.first = "example-schema";
+                node.second = "flagBits";
+                type = yang::Bits{{"carry", "sign", "overflow"}};
+            }
+
 
             REQUIRE(ys.leafType(path, node) == type);
         }
@@ -764,7 +779,8 @@
                         {"example-schema"s, "systemStats"},
                         {"example-schema"s, "dummyLeaf"},
                         {"example-schema"s, "addresses"},
-                        {"example-schema"s, "subLeaf"}};
+                        {"example-schema"s, "subLeaf"},
+                        {"example-schema"s, "flagBits"}};
                 }
 
                 SECTION("example-schema:a")
@@ -819,6 +835,7 @@
                         {"example-schema"s, "ethernet"},
                         {"example-schema"s, "foodDrinkIdentLeaf"},
                         {"example-schema"s, "foodIdentLeaf"},
+                        {"example-schema"s, "flagBits"},
                         {"example-schema"s, "interrupt"},
                         {"example-schema"s, "leafBool"},
                         {"example-schema"s, "leafDecimal"},
@@ -875,6 +892,8 @@
                         {boost::none, "/example-schema:direction"},
                         {boost::none, "/example-schema:duration"},
                         {boost::none, "/example-schema:dummyLeaf"},
+                        {boost::none, "/example-schema:flagBits"},
+                        {boost::none, "/example-schema:foodDrinkIdentLeaf"},
                         {boost::none, "/example-schema:foodDrinkIdentLeaf"},
                         {boost::none, "/example-schema:foodIdentLeaf"},
                         {boost::none, "/example-schema:interface/caseEthernet/ethernet"},