3644bd3daaab9cb7cd1f3afc5f4066c4be59f996
[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.hamcrest.MatcherAssert.assertThat;
11 import static org.hamcrest.core.IsInstanceOf.instanceOf;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
14
15 import java.util.Optional;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.QNameModule;
19 import org.opendaylight.yangtools.yang.common.Revision;
20 import org.opendaylight.yangtools.yang.common.XMLNamespace;
21 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition;
26 import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition;
27
28 public class YT971Test {
29     private static final QNameModule NAMESPACE = QNameModule.create(XMLNamespace.of("test"), Revision.of("2019-03-25"));
30
31     @Test
32     public void testEscapeLexer() throws Exception {
33         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/bugs/YT971/test.yang");
34         assertNotNull(schemaContext);
35
36         final DataSchemaNode someContainer = schemaContext.getDataChildByName(
37             QName.create(NAMESPACE, "some-container"));
38         assertThat(someContainer, instanceOf(ContainerSchemaNode.class));
39         final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) someContainer;
40
41         final DataSchemaNode someLeaf = containerSchemaNode.getDataChildByName(QName.create(NAMESPACE, "some-leaf"));
42         assertThat(someLeaf, instanceOf(LeafSchemaNode.class));
43         final LeafSchemaNode leafSchemaNode = (LeafSchemaNode) someLeaf;
44         assertEquals(Optional.of("Some string that ends with a backslash (with escape backslash too) \\"),
45                      leafSchemaNode.getDescription());
46         assertThat(leafSchemaNode.getType(), instanceOf(Int16TypeDefinition.class));
47
48         final DataSchemaNode someOtherLeaf = containerSchemaNode.getDataChildByName(
49             QName.create(NAMESPACE, "some-other-leaf"));
50         assertThat(someOtherLeaf, instanceOf(LeafSchemaNode.class));
51
52         final LeafSchemaNode otherLeafSchemaNode = (LeafSchemaNode) someOtherLeaf;
53         assertEquals(Optional.of("Some string after the double backslash"), otherLeafSchemaNode.getDescription());
54         assertThat(otherLeafSchemaNode.getType(), instanceOf(Int32TypeDefinition.class));
55     }
56 }