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.SchemaContext;
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.ModuleEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceEffectiveStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.OrganizationEffectiveStatement;
27 import org.opendaylight.yangtools.yang.model.api.stmt.PrefixEffectiveStatement;
28 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
30 public class YT1089Test {
32 public void testPlusLexing() throws Exception {
33 final SchemaContext ctx = StmtTestUtils.parseYangSource("/bugs/YT1089/foo.yang");
34 assertEquals(1, ctx.getModules().size());
36 final Iterator<? extends EffectiveStatement<?, ?>> it =
37 ((ModuleEffectiveStatement)Iterables.getOnlyElement(ctx.getModules()))
38 .effectiveSubstatements().iterator();
40 assertThat(it.next(), instanceOf(NamespaceEffectiveStatement.class));
41 assertThat(it.next(), instanceOf(PrefixEffectiveStatement.class));
43 EffectiveStatement<?, ?> stmt = it.next();
44 assertThat(stmt, instanceOf(DescriptionEffectiveStatement.class));
45 assertEquals("+something", stmt.argument());
48 assertThat(stmt, instanceOf(ContactEffectiveStatement.class));
49 assertEquals("contact++", stmt.argument());
52 assertThat(stmt, instanceOf(OrganizationEffectiveStatement.class));
53 assertEquals("organiza++tion", stmt.argument());
58 assertXyzzy(it.next());
59 assertFalse(it.hasNext());
62 private static void assertFoo(final EffectiveStatement<?, ?> stmt) {
63 assertThat(stmt, instanceOf(LeafEffectiveStatement.class));
64 assertEquals(QName.create("urn:foo", "foo"), stmt.argument());
66 final Iterator<? extends EffectiveStatement<?, ?>> it = stmt.effectiveSubstatements().iterator();
67 assertThat(it.next(), instanceOf(TypeEffectiveStatement.class));
68 assertEquals("+", it.next().argument());
69 assertEquals("squotdquot", it.next().argument());
70 assertEquals("++", it.next().argument());
71 assertFalse(it.hasNext());
74 private static void assertBar(final EffectiveStatement<?, ?> stmt) {
75 assertThat(stmt, instanceOf(LeafEffectiveStatement.class));
76 assertEquals(QName.create("urn:foo", "bar"), stmt.argument());
77 final Iterator<? extends EffectiveStatement<?, ?>> it = stmt.effectiveSubstatements().iterator();
78 assertThat(it.next(), instanceOf(TypeEffectiveStatement.class));
79 assertEquals("++", it.next().argument());
80 assertEquals("+ + ++", it.next().argument());
81 assertEquals("++ + +", it.next().argument());
82 assertFalse(it.hasNext());
85 private static void assertBaz(final EffectiveStatement<?, ?> stmt) {
86 assertThat(stmt, instanceOf(LeafEffectiveStatement.class));
87 assertEquals(QName.create("urn:foo", "baz"), stmt.argument());
88 final Iterator<? extends EffectiveStatement<?, ?>> it = stmt.effectiveSubstatements().iterator();
89 assertThat(it.next(), instanceOf(TypeEffectiveStatement.class));
90 assertEquals("/", it.next().argument());
91 assertEquals(":", it.next().argument());
92 assertEquals("*", it.next().argument());
93 assertFalse(it.hasNext());
96 private static void assertXyzzy(final EffectiveStatement<?, ?> stmt) {
97 assertThat(stmt, instanceOf(LeafEffectiveStatement.class));
98 assertEquals(QName.create("urn:foo", "xyzzy"), stmt.argument());
99 final Iterator<? extends EffectiveStatement<?, ?>> it = stmt.effectiveSubstatements().iterator();
100 assertThat(it.next(), instanceOf(TypeEffectiveStatement.class));
101 assertEquals("a weird concat", it.next().argument());
102 assertEquals("another weird concat", it.next().argument());
103 assertFalse(it.hasNext());