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.data.impl.codec;
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
17 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
19 public class YT1437Test {
21 public void testDecimalFractionDigits() {
22 final var module = YangParserTestUtils.parseYang("""
30 range "20.0..30.01 | 50";
33 }""").findModule("yt1437").orElseThrow();
34 final var foo = module.findDataChildByName(QName.create(module.getQNameModule(), "foo")).orElseThrow();
35 assertThat(foo, instanceOf(LeafSchemaNode.class));
37 final TypeDefinitionAwareCodec<?, ?> codec = TypeDefinitionAwareCodec.from(((LeafSchemaNode) foo).getType());
38 assertThat(codec, instanceOf(DecimalStringCodec.class));
39 final var cast = (DecimalStringCodec) codec;
41 final var one = cast.deserialize("20.0");
42 assertEquals(2, one.scale());
43 assertEquals("20.0", cast.serialize(one));
45 final var two = cast.deserialize("20.00");
46 assertEquals(2, two.scale());
47 assertEquals("20.0", cast.serialize(two));
49 final var three = cast.deserialize("20.000");
50 assertEquals(2, three.scale());
51 assertEquals("20.0", cast.serialize(three));