2 * Copyright (c) 2021 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.model.util;
10 import static org.hamcrest.CoreMatchers.startsWith;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.jupiter.api.Assertions.assertSame;
13 import static org.junit.jupiter.api.Assertions.assertThrows;
14 import static org.junit.jupiter.api.Assertions.assertTrue;
16 import java.util.NoSuchElementException;
17 import org.junit.jupiter.api.BeforeAll;
18 import org.junit.jupiter.api.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
24 private static EffectiveModelContext context;
26 private final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
29 static void beforeClass() {
30 context = YangParserTestUtils.parseYang("""
46 void testExitToDataTree() {
47 final var foo = stack.enterDataTree(QName.create("foo", "foo"));
48 assertSame(foo, stack.exitToDataTree());
49 assertTrue(stack.isEmpty());
50 assertSame(foo, stack.enterDataTree(foo.argument()));
54 void testExitToGrouping() {
55 final var baz = stack.enterGrouping(QName.create("foo", "baz"));
56 assertTrue(stack.inGrouping());
57 final var xyzzy = stack.enterDataTree(QName.create("foo", "xyzzy"));
58 assertSame(xyzzy, stack.exitToDataTree());
59 assertSame(baz, stack.currentStatement());
60 assertSame(xyzzy, stack.enterDataTree(xyzzy.argument()));
64 void testEmptyExitToDataTree() {
65 assertThrows(NoSuchElementException.class, stack::exitToDataTree);
69 void testSchemaExitToDataTree() {
70 stack.enterSchemaTree(QName.create("foo", "bar"));
71 final var ex = assertThrows(IllegalStateException.class, stack::exitToDataTree);
72 assertThat(ex.getMessage(), startsWith("Unexpected current "));