Skip to main content

asterust_junos/system/
schema.rs

1//! `schema`
2//! `system { schema { ... } }`.
3//!
4//! # See also
5//!
6//! - [schema](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/schema-edit-system.html)
7
8use crate::{child_block, has_leaf};
9use asterust::config::ConfigLine;
10
11/// The `system schema` configuration.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct Schema {
15    /// `openconfig { unhide; }`.
16    pub openconfig_unhide: bool,
17}
18
19pub(super) fn parse_schema(schema: &ConfigLine) -> Schema {
20    Schema {
21        openconfig_unhide: child_block(schema, "openconfig").is_some_and(|openconfig| has_leaf(openconfig, "unhide")),
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use crate::system::system;
28    use asterust::config::juniper;
29
30    // Not from documentation: written from the CLI Reference syntax page. See the README "Sources".
31    #[test]
32    fn extracts_schema_openconfig_unhide() {
33        let schema = system(&juniper::parse_braces(
34            "system {\n    schema {\n        openconfig {\n            unhide;\n        }\n    }\n}\n",
35        ))
36        .unwrap()
37        .schema
38        .unwrap();
39        assert!(schema.openconfig_unhide);
40    }
41
42    #[test]
43    fn schema_without_openconfig_unhide() {
44        let schema = system(&juniper::parse_braces(
45            "system {\n    schema {\n        openconfig;\n    }\n}\n",
46        ))
47        .unwrap()
48        .schema
49        .unwrap();
50        assert!(!schema.openconfig_unhide);
51    }
52
53    #[test]
54    fn no_schema_is_none() {
55        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
56        assert!(system.schema.is_none());
57    }
58}