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