File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ class LIBYANG_CPP_EXPORT Type {
6666 InstanceIdentifier asInstanceIdentifier () const ;
6767
6868 std::string name () const ;
69+ std::optional<std::string> typedefName () const ;
6970 std::optional<std::string> description () const ;
7071
7172 std::string internalPluginId () const ;
Original file line number Diff line number Diff line change @@ -196,6 +196,20 @@ std::string Type::name() const
196196 return m_typeParsed->name ;
197197}
198198
199+ /* *
200+ * @brief Name of the typedef, if avaialable
201+ *
202+ * Wraps `lysc_type::name`.
203+ */
204+ std::optional<std::string> Type::typedefName () const
205+ {
206+ if (!m_type->name ) {
207+ return std::nullopt ;
208+ }
209+
210+ return m_type->name ;
211+ }
212+
199213/* *
200214 * @brief Returns the description of the type.
201215 *
Original file line number Diff line number Diff line change @@ -2226,7 +2226,7 @@ TEST_CASE("union data types")
22262226 std::optional<libyang::Context> ctxWithParsed{std::in_place, std::nullopt ,
22272227 libyang::ContextOptions::SetPrivParsed | libyang::ContextOptions::NoYangLibrary | libyang::ContextOptions::DisableSearchCwd};
22282228 ctxWithParsed->parseModule (with_inet_types_module, libyang::SchemaFormat::YANG);
2229- std::string input, expectedPlugin;
2229+ std::string input, expectedPlugin, expectedTypedef ;
22302230
22312231 DOCTEST_SUBCASE (" IPv6" )
22322232 {
@@ -2243,21 +2243,25 @@ TEST_CASE("union data types")
22432243 input = " ::ffff:192.0.2.1" ;
22442244 }
22452245 expectedPlugin = " ipv6" ;
2246+ expectedTypedef = " ipv6-address" ;
22462247 }
22472248
22482249 DOCTEST_SUBCASE (" IPv4" )
22492250 {
22502251 input = " 127.0.0.1" ;
22512252 expectedPlugin = " ipv4" ;
2253+ expectedTypedef = " ipv4-address" ;
22522254 }
22532255
22542256 DOCTEST_SUBCASE (" string" )
22552257 {
22562258 input = " foo-bar.example.org" ;
22572259 expectedPlugin = " string" ;
2260+ expectedTypedef = " domain-name" ;
22582261 }
22592262
22602263 auto node = ctxWithParsed->newPath (" /with-inet-types:hostname" , input);
22612264 REQUIRE (node.asTerm ().valueType ().internalPluginId ().find (expectedPlugin) != std::string::npos);
22622265 REQUIRE_THROWS_AS (node.asTerm ().valueType ().name (), libyang::ParsedInfoUnavailable);
2266+ REQUIRE (node.asTerm ().valueType ().typedefName () == expectedTypedef);
22632267}
You can’t perform that action at this time.
0 commit comments