Fix groupings not being properly resolved
Change-Id: I878ea328acd4e01ec5ea2a7d5a28b22350bb11bd
Bug: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/116
Bug: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/95
diff --git a/example-schema.yang b/example-schema.yang
index 4074172..172f78a 100644
--- a/example-schema.yang
+++ b/example-schema.yang
@@ -28,4 +28,18 @@
presence true;
}
+ grouping upAndDown {
+ leaf up {
+ type boolean;
+ }
+ leaf down {
+ type boolean;
+ }
+ }
+
+ uses upAndDown;
+
+ container lol {
+ uses upAndDown;
+ }
}
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index bab4715..3512baf 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -284,9 +284,7 @@
const auto absolutePath = "/" + pathToAbsoluteSchemaString(path);
const auto set = m_context->find_path(absolutePath.c_str());
const auto schemaSet = set->schema();
- for (auto it = (*schemaSet.begin())->child(); it; it = it->next()) {
- nodes.push_back(it);
- }
+ nodes = (*schemaSet.begin())->child_instantiables(0);
}
for (const auto node : nodes) {
diff --git a/tests/yang.cpp b/tests/yang.cpp
index f22bbbe..6793250 100644
--- a/tests/yang.cpp
+++ b/tests/yang.cpp
@@ -184,6 +184,28 @@
type string;
}
}
+
+ grouping arithmeticFlags {
+ leaf carry {
+ type boolean;
+ }
+ leaf zero {
+ type boolean;
+ }
+ }
+
+ grouping flags {
+ leaf direction {
+ type boolean;
+ }
+ leaf interrupt {
+ type boolean;
+ }
+
+ uses arithmeticFlags;
+ }
+
+ uses flags;
})";
TEST_CASE("yangschema")
@@ -232,6 +254,30 @@
node.second = "leafa";
}
+ SECTION("example-schema:carry")
+ {
+ node.first = "example-schema";
+ node.second = "carry";
+ }
+
+ SECTION("example-schema:zero")
+ {
+ node.first = "example-schema";
+ node.second = "zero";
+ }
+
+ SECTION("example-schema:direction")
+ {
+ node.first = "example-schema";
+ node.second = "direction";
+ }
+
+ SECTION("example-schema:interrupt")
+ {
+ node.first = "example-schema";
+ node.second = "interrupt";
+ }
+
REQUIRE(ys.isLeaf(path, node));
}
SECTION("isModule")
@@ -531,7 +577,9 @@
"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"};
+ "example-schema:_list", "example-schema:twoKeyList", "second-schema:bla",
+ "example-schema:carry", "example-schema:zero", "example-schema:direction",
+ "example-schema:interrupt"};
}
SECTION("example-schema:a")
@@ -648,5 +696,25 @@
}
REQUIRE_FALSE(ys.leafIdentityIsValid(path, node, value));
}
+
+ SECTION("grouping is not a node")
+ {
+ SECTION("example-schema:arithmeticFlags")
+ {
+ node.first = "example-schema";
+ node.second = "arithmeticFlags";
+ }
+
+ SECTION("example-schema:flags")
+ {
+ node.first = "example-schema";
+ node.second = "startAndStop";
+ }
+
+ REQUIRE(!ys.isPresenceContainer(path, node));
+ REQUIRE(!ys.isList(path, node));
+ REQUIRE(!ys.isLeaf(path, node));
+ REQUIRE(!ys.isContainer(path, node));
+ }
}
}