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.parseYangResource("/yt1282.yang");
34 void testResolveTypedef() {
35 final TypeEffectiveStatement<?> type = stack.enterTypedef(QName.create("foo", "foo"))
36 .findFirstEffectiveSubstatement(TypeEffectiveStatement.class).orElseThrow();
37 assertFalse(stack.inInstantiatedContext());
38 assertFalse(stack.inGrouping());
40 final var bar = assertInstanceOf(LeafEffectiveStatement.class,
41 stack.resolvePathExpression(
42 type.findFirstEffectiveSubstatementArgument(PathEffectiveStatement.class).orElseThrow()));
43 assertEquals(QName.create("foo", "bar"), bar.argument());