From 6e5e7626a840bb346be173a325e581cf2899b427 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 4 Aug 2024 15:11:20 -0400 Subject: [PATCH] only: new test --- .../test/java/com/rusefi/test/ConfigFieldParserTest.java | 5 +++++ .../src/main/java/com/rusefi/ConfigFieldImpl.java | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java b/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java index 0aabc11a3a..f5ab6c1b33 100644 --- a/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java +++ b/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java @@ -3,6 +3,7 @@ package com.rusefi.test; import com.rusefi.*; import com.rusefi.output.*; import com.rusefi.parse.TypesHelper; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -12,6 +13,10 @@ import static org.junit.jupiter.api.Assertions.*; * 1/15/15 */ public class ConfigFieldParserTest { + @Test + public void testErrorDetection() { + Assertions.assertThrows(IllegalStateException.class, () -> ConfigFieldImpl.getScaleSpec("2.54", "test")); + } @Test public void testByteArray() { diff --git a/java_tools/configuration_definition_base/src/main/java/com/rusefi/ConfigFieldImpl.java b/java_tools/configuration_definition_base/src/main/java/com/rusefi/ConfigFieldImpl.java index d5f00460d0..ef647bbc04 100644 --- a/java_tools/configuration_definition_base/src/main/java/com/rusefi/ConfigFieldImpl.java +++ b/java_tools/configuration_definition_base/src/main/java/com/rusefi/ConfigFieldImpl.java @@ -15,6 +15,7 @@ import static com.devexperts.logging.Logging.getLogging; import static com.rusefi.TokenUtils.tokenizeWithBraces; import com.rusefi.parse.TypesHelper; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -343,6 +344,10 @@ public class ConfigFieldImpl implements ConfigField { throw new IllegalArgumentException("Second comma-separated token expected in [" + tsInfo + "] for " + name); String scale = tokens[1].trim(); + return getScaleSpec(scale, name); + } + + public static @NotNull Pair getScaleSpec(String scale, String name) { double factor; if (scale.startsWith("{") && scale.endsWith("}")) { // Handle just basic division, not a full fledged eval loop @@ -367,7 +372,7 @@ public class ConfigFieldImpl implements ConfigField { double accuracy = Math.abs((factor2 / factor) - 1.); if (accuracy > 0.0000001) { // Don't want to deal with exception propogation; this should adequately not compile - throw new IllegalStateException("$*@#$* Cannot accurately represent autoscale for [" + tokens[1] + "] got " + accuracy); + throw new IllegalStateException("$*@#$* Cannot accurately represent autoscale for [" + scale + "] got " + accuracy); } return new Pair<>(mul, div);