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.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertFalse;
12 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
14 import org.junit.jupiter.api.BeforeAll;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.PathEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
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("""
48 void testResolveTypedef() {
49 final TypeEffectiveStatement<?> type = stack.enterTypedef(QName.create("foo", "foo"))
50 .findFirstEffectiveSubstatement(TypeEffectiveStatement.class).orElseThrow();
51 assertFalse(stack.inInstantiatedContext());
52 assertFalse(stack.inGrouping());
54 final var bar = assertInstanceOf(LeafEffectiveStatement.class,
55 stack.resolvePathExpression(
56 type.findFirstEffectiveSubstatementArgument(PathEffectiveStatement.class).orElseThrow()));
57 assertEquals(QName.create("foo", "bar"), bar.argument());