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.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
13 import org.junit.jupiter.api.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
16 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
20 void testDecimalFractionDigits() {
21 final var module = YangParserTestUtils.parseYang("""
29 range "20.0..30.01 | 50";
32 }""").findModule("yt1437").orElseThrow();
33 final var foo = module.findDataChildByName(QName.create(module.getQNameModule(), "foo")).orElseThrow();
35 final var codec = assertInstanceOf(DecimalStringCodec.class,
36 TypeDefinitionAwareCodec.from(assertInstanceOf(LeafSchemaNode.class, foo).getType()));
38 final var one = codec.deserialize("20.0");
39 assertEquals(2, one.scale());
40 assertEquals("20.0", codec.serialize(one));
42 final var two = codec.deserialize("20.00");
43 assertEquals(2, two.scale());
44 assertEquals("20.0", codec.serialize(two));
46 final var three = codec.deserialize("20.000");
47 assertEquals(2, three.scale());
48 assertEquals("20.0", codec.serialize(three));