diff --git a/src/main/java/build/buf/protovalidate/internal/celext/Format.java b/src/main/java/build/buf/protovalidate/internal/celext/Format.java index 81a86aec..0aee9c13 100644 --- a/src/main/java/build/buf/protovalidate/internal/celext/Format.java +++ b/src/main/java/build/buf/protovalidate/internal/celext/Format.java @@ -157,7 +157,7 @@ private static void formatStringSafe(StringBuilder builder, Val val, boolean lis if (type == TypeEnum.Bool) { builder.append(val.booleanValue()); } else if (type == TypeEnum.Int || type == TypeEnum.Uint) { - formatInteger(builder, Long.valueOf(val.intValue()).intValue()); + formatDecimal(builder, val); } else if (type == TypeEnum.Double) { DecimalFormat format = new DecimalFormat("0.#"); builder.append(format.format(val.value())); @@ -247,20 +247,6 @@ private static void formatBytes(StringBuilder builder, Val val) { .append("\""); } - /** - * Formats an integer value. - * - * @param builder the StringBuilder to append the formatted integer value to. - * @param value the value to format. - */ - private static void formatInteger(StringBuilder builder, int value) { - if (value < 0) { - builder.append("-"); - value = -value; - } - builder.append(value); - } - /** * Formats a hexadecimal value. * diff --git a/src/test/java/build/buf/protovalidate/internal/celext/FormatTest.java b/src/test/java/build/buf/protovalidate/internal/celext/FormatTest.java new file mode 100644 index 00000000..63ca34a2 --- /dev/null +++ b/src/test/java/build/buf/protovalidate/internal/celext/FormatTest.java @@ -0,0 +1,33 @@ +// Copyright 2023 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package build.buf.protovalidate.internal.celext; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.projectnessie.cel.common.types.ListT; +import org.projectnessie.cel.common.types.UintT; +import org.projectnessie.cel.common.types.ref.Val; + +class FormatTest { + @Test + void largeDecimalValuesAreProperlyFormatted() { + UintT largeDecimal = UintT.uintOf(999999999999L); + ListT val = (ListT) ListT.newValArrayList(null, new Val[] {largeDecimal}); + String formatted = Format.format("%s", val); + assertThat(formatted).isEqualTo("999999999999"); + } +}