Filter disabled enums in YangSchema::enumValues

Change-Id: I04a645fb5e0cccdc1a2766802cfd74c6676fb6c5
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index 4c55b27..549393a 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -135,8 +135,14 @@
         enm = type->info()->enums()->enm();
     }
 
+    std::vector<libyang::S_Type_Enum> enabled;
+    std::copy_if(enm.begin(), enm.end(), std::back_inserter(enabled), [] (const libyang::S_Type_Enum& it) {
+        auto iffeatures = it->iffeature();
+        return std::all_of(iffeatures.begin(), iffeatures.end(), [] (auto it) {return it->value();});
+    });
+
     std::set<std::string> enumSet;
-    std::transform(enm.begin(), enm.end(), std::inserter(enumSet, enumSet.end()), [](auto it) { return it->name(); });
+    std::transform(enabled.begin(), enabled.end(), std::inserter(enumSet, enumSet.end()), [](auto it) { return it->name(); });
     return enumSet;
 }
 
diff --git a/tests/yang.cpp b/tests/yang.cpp
index d9c2a89..2ca1704 100644
--- a/tests/yang.cpp
+++ b/tests/yang.cpp
@@ -250,6 +250,18 @@
         }
     }
 
+    feature bigPizzas;
+
+    leaf pizzaSize {
+        type enumeration {
+            enum large {
+                if-feature "bigPizzas";
+            }
+            enum medium;
+            enum small;
+        }
+    }
+
 })";
 
 namespace std {
@@ -434,6 +446,28 @@
                     value = "data";
             }
 
+            SECTION("pizzaSize")
+            {
+                node.first = "example-schema";
+                node.second = "pizzaSize";
+
+                SECTION("small")
+                {
+                    value = "small";
+
+                }
+                SECTION("medium")
+                {
+                    value = "medium";
+                }
+
+                SECTION("large")
+                {
+                    ys.enableFeature("example-schema", "bigPizzas");
+                    value = "large";
+                }
+            }
+
             REQUIRE(ys.leafEnumHasValue(path, node, value));
         }
         SECTION("leafIdentityIsValid")
@@ -692,7 +726,8 @@
                        "example-schema:_list", "example-schema:twoKeyList", "second-schema:bla",
                        "example-schema:carry", "example-schema:zero", "example-schema:direction",
                        "example-schema:interrupt",
-                       "example-schema:ethernet", "example-schema:loopback"};
+                       "example-schema:ethernet", "example-schema:loopback",
+                       "example-schema:pizzaSize"};
             }
 
             SECTION("example-schema:a")
@@ -869,5 +904,15 @@
             REQUIRE(!ys.isLeaf(path, node));
             REQUIRE(!ys.isContainer(path, node));
         }
+
+        SECTION("enum is disabled by if-feature if feature is not enabled")
+        {
+            node.first = "example-schema";
+            node.second = "pizzaSize";
+
+            std::string value = "large";
+
+            REQUIRE(!ys.leafEnumHasValue(path, node, value));
+        }
     }
 }