2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
15 import com.google.common.collect.Iterables;
16 import java.util.Iterator;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.ContactEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.OrganizationEffectiveStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.PrefixEffectiveStatement;
27 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
29 public class YT1089Test {
31 public void testPlusLexing() throws Exception {
32 final EffectiveModelContext ctx = StmtTestUtils.parseYangSource("/bugs/YT1089/foo.yang");
33 assertEquals(1, ctx.getModuleStatements().size());
35 final Iterator<? extends EffectiveStatement<?, ?>> it =
36 Iterables.getOnlyElement(ctx.getModuleStatements().values()).effectiveSubstatements().iterator();
38 assertThat(it.next(), instanceOf(NamespaceEffectiveStatement.class));
39 assertThat(it.next(), instanceOf(PrefixEffectiveStatement.class));
41 EffectiveStatement<?, ?> stmt = it.next();
42 assertThat(stmt, instanceOf(DescriptionEffectiveStatement.class));
43 assertEquals("+something", stmt.argument());
46 assertThat(stmt, instanceOf(ContactEffectiveStatement.class));
47 assertEquals("contact++", stmt.argument());
50 assertThat(stmt, instanceOf(OrganizationEffectiveStatement.class));
51 assertEquals("organiza++tion", stmt.argument());
55 assertFalse(it.hasNext());
58 private static void assertFoo(final EffectiveStatement<?, ?> stmt) {
59 assertThat(stmt, instanceOf(LeafEffectiveStatement.class));
60 assertEquals(QName.create("urn:foo", "foo"), stmt.argument());
62 final Iterator<? extends EffectiveStatement<?, ?>> it = stmt.effectiveSubstatements().iterator();
63 assertThat(it.next(), instanceOf(TypeEffectiveStatement.class));
64 assertEquals("+", it.next().argument());
65 assertEquals("squotdquot", it.next().argument());
66 assertEquals("++", it.next().argument());
67 assertFalse(it.hasNext());
70 private static void assertBar(final EffectiveStatement<?, ?> stmt) {
71 assertThat(stmt, instanceOf(LeafEffectiveStatement.class));
72 assertEquals(QName.create("urn:foo", "bar"), stmt.argument());
73 final Iterator<? extends EffectiveStatement<?, ?>> it = stmt.effectiveSubstatements().iterator();
74 assertThat(it.next(), instanceOf(TypeEffectiveStatement.class));
75 assertEquals("++", it.next().argument());
76 assertEquals("+ + ++", it.next().argument());
77 assertEquals("++ + +", it.next().argument());
78 assertFalse(it.hasNext());