2 * Copyright (c) 2017 Pantheon Technologies, 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.CoreMatchers.startsWith;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertThrows;
14 import static org.junit.Assert.assertTrue;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
20 public class YT838Test {
22 public void testGroupingShadowing() {
23 testGrouping("grouping.yang");
27 public void testGroupingPostShadowing() {
28 testGrouping("grouping-post.yang");
32 public void testTypedefShadowing() {
33 testTypedef("typedef.yang");
37 public void testTypedefPostShadowing() {
38 testTypedef("typedef-post.yang");
41 private static void testGrouping(final String model) {
42 final ReactorException ex = assertThrows(ReactorException.class,
43 () -> StmtTestUtils.parseYangSource("/bugs/YT838/" + model));
45 final Throwable cause = ex.getCause();
46 assertThat(cause, instanceOf(SourceException.class));
47 assertThat(cause.getMessage(),
48 startsWith("Duplicate name for grouping (grouping?revision=2017-12-20)foo [at "));
51 private static void testTypedef(final String model) {
52 final ReactorException ex = assertThrows(ReactorException.class,
53 () -> StmtTestUtils.parseYangSource("/bugs/YT838/" + model));
54 final Throwable cause = ex.getCause();
55 assertTrue(cause instanceof SourceException);
56 assertThat(cause, instanceOf(SourceException.class));
57 assertThat(cause.getMessage(), startsWith("Duplicate name for typedef (typedef?revision=2017-12-20)foo [at "));