Fix bits completion
Completion iterator wasn't saved in bits completion. Ideally I would use
createSetSuggestions for bit completion, but unfortunately, yang::Enum
and yang::IdentityRef have a container with values that have a
".m_value" member and yang::Bits directly has a container of std::string
(which doesn't have .m_value). So Bits and the other two aren't
compatible.
Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/204
Change-Id: Ib2d1162270917d9c4d05e55fbb62c285c1a46aa2
diff --git a/src/leaf_data.hpp b/src/leaf_data.hpp
index 7bab723..df0f9b3 100644
--- a/src/leaf_data.hpp
+++ b/src/leaf_data.hpp
@@ -162,6 +162,7 @@
parser.add(bit, bit);
parserContext.m_suggestions.insert(Completion{bit});
}
+ parserContext.m_completionIterator = first;
std::vector<std::string> bitsRes;
diff --git a/tests/set_value_completion.cpp b/tests/set_value_completion.cpp
index dd36e34..f4d8124 100644
--- a/tests/set_value_completion.cpp
+++ b/tests/set_value_completion.cpp
@@ -29,6 +29,7 @@
schema->addIdentity(identityRef_{"mod", "food"}, identityRef_{"mod", "spaghetti"});
schema->addIdentity(identityRef_{"mod", "pizza"}, identityRef_{"pizza-module", "hawaii"});
schema->addLeaf("/", "mod:foodIdentRef", yang::IdentityRef{schema->validIdentities("mod", "food")});
+ schema->addLeaf("/", "mod:flags", yang::Bits{{"parity", "zero", "carry", "sign"}});
auto mockDatastore = std::make_shared<MockDatastoreAccess>();
// The parser will use DataQuery for key value completion, but I'm not testing that here, so I don't return anything.
ALLOW_CALL(*mockDatastore, listInstances("/mod:list"))
@@ -88,5 +89,19 @@
expectedContextLength = 0;
}
+ SECTION("set mod:flags ")
+ {
+ input = "set mod:flags ";
+ expectedCompletions = {"carry", "sign", "parity", "zero"};
+ expectedContextLength = 0;
+ }
+
+ SECTION("set mod:flags ze")
+ {
+ input = "set mod:flags ze";
+ expectedCompletions = {"zero"};
+ expectedContextLength = 2;
+ }
+
REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength}));
}