Clean up TreeNode API
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YT971Test.java
1 /*
2  * Copyright (c) 2019 Ericsson AB. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12
13 import java.util.Optional;
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition;
21 import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition;
22
23 class YT971Test extends AbstractYangTest {
24     private static final QNameModule NAMESPACE = QNameModule.of("test", "2019-03-25");
25
26     @Test
27     void testEscapeLexer() {
28         final var context = assertEffectiveModel("/bugs/YT971/test.yang");
29
30         final DataSchemaNode someContainer = context.getDataChildByName(
31             QName.create(NAMESPACE, "some-container"));
32         final ContainerSchemaNode containerSchemaNode = assertInstanceOf(ContainerSchemaNode.class, someContainer);
33         final DataSchemaNode someLeaf = containerSchemaNode.getDataChildByName(QName.create(NAMESPACE, "some-leaf"));
34         final LeafSchemaNode leafSchemaNode = assertInstanceOf(LeafSchemaNode.class, someLeaf);
35         assertEquals(Optional.of("Some string that ends with a backslash (with escape backslash too) \\"),
36             leafSchemaNode.getDescription());
37         assertInstanceOf(Int16TypeDefinition.class, leafSchemaNode.getType());
38
39         final DataSchemaNode someOtherLeaf = containerSchemaNode.getDataChildByName(
40             QName.create(NAMESPACE, "some-other-leaf"));
41
42         final LeafSchemaNode otherLeafSchemaNode = assertInstanceOf(LeafSchemaNode.class, someOtherLeaf);
43         assertEquals(Optional.of("Some string after the double backslash"), otherLeafSchemaNode.getDescription());
44         assertInstanceOf(Int32TypeDefinition.class, otherLeafSchemaNode.getType());
45     }
46 }