2 * Copyright (c) 2019 Ericsson AB. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
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;
15 import java.io.IOException;
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;
32 public class YT971Test {
33 private static final QNameModule NAMESPACE = QNameModule.create(URI.create("test"), Revision.of("2019-03-25"));
36 public void testEscapeLexer() throws URISyntaxException, IOException, YangSyntaxErrorException, ReactorException {
37 final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/bugs/YT971/test.yang");
38 assertNotNull(schemaContext);
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;
45 final DataSchemaNode someLeaf = containerSchemaNode.findDataChildByName(QName.create(NAMESPACE, "some-leaf"))
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));
53 final DataSchemaNode someOtherLeaf = containerSchemaNode.findDataChildByName(
54 QName.create(NAMESPACE, "some-other-leaf")).get();
55 assertThat(someOtherLeaf, instanceOf(LeafSchemaNode.class));
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));