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