Add support for identityref data type

Change-Id: I369150b83d86a4c22fadf383ee011eee619a4c15
diff --git a/tests/yang.cpp b/tests/yang.cpp
index 5846a23..e19f991 100644
--- a/tests/yang.cpp
+++ b/tests/yang.cpp
@@ -18,6 +18,10 @@
         prefix "example";
     }
 
+    identity pineapple {
+        base "example:fruit";
+    }
+
     augment /example:a {
         container augmentedContainer {
         }
@@ -36,6 +40,28 @@
     namespace "http://example.com/example-sports";
     prefix coze;
 
+    identity drink {
+    }
+
+    identity voda {
+        base "drink";
+    }
+
+    identity food {
+    }
+
+    identity fruit {
+        base "food";
+    }
+
+    identity pizza {
+        base "food";
+    }
+
+    identity hawaii {
+        base "pizza";
+    }
+
     container a {
         container a2 {
             container a3 {
@@ -116,6 +142,25 @@
         type enumTypedefRestricted;
     }
 
+    leaf foodIdentLeaf {
+        type identityref {
+            base "food";
+        }
+    }
+
+    leaf pizzaIdentLeaf {
+        type identityref {
+            base "pizza";
+        }
+    }
+
+    leaf foodDrinkIdentLeaf {
+        type identityref {
+            base "food";
+            base "drink";
+        }
+    }
+
     list _list {
         key number;
 
@@ -279,6 +324,110 @@
 
             REQUIRE(ys.leafEnumHasValue(path, node, value));
         }
+        SECTION("leafIdentityIsValid")
+        {
+            ModuleValuePair value;
+
+            SECTION("foodIdentLeaf")
+            {
+                node.first = "example-schema";
+                node.second = "foodIdentLeaf";
+
+                SECTION("food")
+                {
+                    value.second = "food";
+                }
+                SECTION("example-schema:food")
+                {
+                    value.first = "example-schema";
+                    value.second = "food";
+                }
+                SECTION("pizza")
+                {
+                    value.second = "pizza";
+                }
+                SECTION("example-schema:pizza")
+                {
+                    value.first = "example-schema";
+                    value.second = "pizza";
+                }
+                SECTION("hawaii")
+                {
+                    value.second = "hawaii";
+                }
+                SECTION("example-schema:hawaii")
+                {
+                    value.first = "example-schema";
+                    value.second = "hawaii";
+                }
+                SECTION("fruit")
+                {
+                    value.second = "fruit";
+                }
+                SECTION("example-schema:fruit")
+                {
+                    value.first = "example-schema";
+                    value.second = "fruit";
+                }
+                SECTION("second-schema:pineapple")
+                {
+                    value.first = "second-schema";
+                    value.second = "pineapple";
+                }
+            }
+
+            SECTION("pizzaIdentLeaf")
+            {
+                node.first = "example-schema";
+                node.second = "pizzaIdentLeaf";
+
+                SECTION("pizza")
+                {
+                    value.second = "pizza";
+                }
+                SECTION("example-schema:pizza")
+                {
+                    value.first = "example-schema";
+                    value.second = "pizza";
+                }
+                SECTION("hawaii")
+                {
+                    value.second = "hawaii";
+                }
+                SECTION("example-schema:hawaii")
+                {
+                    value.first = "example-schema";
+                    value.second = "hawaii";
+                }
+            }
+
+            SECTION("foodDrinkIdentLeaf")
+            {
+                node.first = "example-schema";
+                node.second = "foodDrinkIdentLeaf";
+
+                SECTION("food")
+                {
+                    value.second = "food";
+                }
+                SECTION("example-schema:food")
+                {
+                    value.first = "example-schema";
+                    value.second = "food";
+                }
+                SECTION("drink")
+                {
+                    value.second = "drink";
+                }
+                SECTION("example-schema:drink")
+                {
+                    value.first = "example-schema";
+                    value.second = "drink";
+                }
+            }
+            REQUIRE(ys.leafIdentityIsValid(path, node, value));
+        }
+
         SECTION("listHasKey")
         {
             std::string key;
@@ -381,6 +530,7 @@
                        "example-schema:leafDecimal", "example-schema:leafBool", "example-schema:leafInt",
                        "example-schema:leafUint", "example-schema:leafEnum", "example-schema:leafEnumTypedef",
                        "example-schema:leafEnumTypedefRestricted", "example-schema:leafEnumTypedefRestricted2",
+                       "example-schema:foodIdentLeaf", "example-schema:pizzaIdentLeaf", "example-schema:foodDrinkIdentLeaf",
                        "example-schema:_list", "example-schema:twoKeyList", "second-schema:bla"};
             }
 
@@ -460,5 +610,43 @@
         {
             REQUIRE(!ys.isModule(path, "notAModule"));
         }
+
+        SECTION("leafIdentityIsValid")
+        {
+            ModuleValuePair value;
+            SECTION("pizzaIdentLeaf")
+            {
+                node.first = "example-schema";
+                node.second = "pizzaIdentLeaf";
+
+                SECTION("wrong base ident")
+                {
+                    SECTION("food")
+                    {
+                        value.second = "food";
+                    }
+                    SECTION("fruit")
+                    {
+                        value.second = "fruit";
+                    }
+                }
+                SECTION("non-existent identity")
+                {
+                    value.second = "nonexistent";
+                }
+                SECTION("weird module")
+                {
+                    value.first = "ahahaha";
+                    value.second = "pizza";
+                }
+            }
+            SECTION("different module identity, but withotu prefix")
+            {
+                node.first = "example-schema";
+                node.second = "foodIdentLeaf";
+                value.second = "pineapple";
+            }
+            REQUIRE_FALSE(ys.leafIdentityIsValid(path, node, value));
+        }
     }
 }