Fix handling of choice statements in YangSchema
Now that I'm using `libyang::Context::get_node`, the code got a little
less complicated, since it always returns a Schema_Node instead of
a Set.
Change-Id: Iab3734ed4cb5957cb635f268b882963c95d36206
Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/119
diff --git a/tests/yang.cpp b/tests/yang.cpp
index 9c44008..156d94b 100644
--- a/tests/yang.cpp
+++ b/tests/yang.cpp
@@ -230,6 +230,25 @@
}
uses flags;
+
+ choice interface {
+ case caseLoopback {
+ container loopback {
+ leaf ip {
+ type string;
+ }
+ }
+ }
+
+ case caseEthernet {
+ container ethernet {
+ leaf ip {
+ type string;
+ }
+ }
+ }
+ }
+
})";
TEST_CASE("yangschema")
@@ -261,6 +280,18 @@
node.second = "a2";
}
+ SECTION("example-schema:ethernet")
+ {
+ node.first = "example-schema";
+ node.second = "ethernet";
+ }
+
+ SECTION("example-schema:loopback")
+ {
+ node.first = "example-schema";
+ node.second = "loopback";
+ }
+
REQUIRE(ys.isContainer(path, node));
}
SECTION("isLeaf")
@@ -649,7 +680,8 @@
"example-schema:foodIdentLeaf", "example-schema:pizzaIdentLeaf", "example-schema:foodDrinkIdentLeaf",
"example-schema:_list", "example-schema:twoKeyList", "second-schema:bla",
"example-schema:carry", "example-schema:zero", "example-schema:direction",
- "example-schema:interrupt"};
+ "example-schema:interrupt",
+ "example-schema:ethernet", "example-schema:loopback"};
}
SECTION("example-schema:a")
@@ -786,5 +818,39 @@
REQUIRE(!ys.isLeaf(path, node));
REQUIRE(!ys.isContainer(path, node));
}
+
+ SECTION("choice is not a node")
+ {
+ SECTION("example-schema:interface")
+ {
+ node.first = "example-schema";
+ node.second = "interface";
+ }
+
+ REQUIRE(!ys.isPresenceContainer(path, node));
+ REQUIRE(!ys.isList(path, node));
+ REQUIRE(!ys.isLeaf(path, node));
+ REQUIRE(!ys.isContainer(path, node));
+ }
+
+ SECTION("case is not a node")
+ {
+ SECTION("example-schema:caseLoopback")
+ {
+ node.first = "example-schema";
+ node.second = "caseLoopback";
+ }
+
+ SECTION("example-schema:caseEthernet")
+ {
+ node.first = "example-schema";
+ node.second = "caseEthernet";
+ }
+
+ REQUIRE(!ys.isPresenceContainer(path, node));
+ REQUIRE(!ys.isList(path, node));
+ REQUIRE(!ys.isLeaf(path, node));
+ REQUIRE(!ys.isContainer(path, node));
+ }
}
}