Ticket #20933: 20933.patch
File 20933.patch, 7.4 KB (added by , 4 years ago) |
---|
-
src/org/openstreetmap/josm/data/imagery/vectortile/mapbox/Feature.java
From e784efd4e5d988ba95f0fff14c5178d7cdb67c66 Mon Sep 17 00:00:00 2001 From: Taylor Smock <tsmock@fb.com> Date: Wed, 26 May 2021 13:07:16 -0600 Subject: [PATCH 1/2] VectorTile: Feature: Always use root locale (stable numbers) This fixes #20933. Signed-off-by: Taylor Smock <tsmock@fb.com> --- .../josm/data/imagery/vectortile/mapbox/Feature.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/org/openstreetmap/josm/data/imagery/vectortile/mapbox/Feature.java b/src/org/openstreetmap/josm/data/imagery/vectortile/mapbox/Feature.java index 7f4fa1023..9dc07ce73 100644
a b import java.io.IOException; 5 5 import java.text.NumberFormat; 6 6 import java.util.ArrayList; 7 7 import java.util.List; 8 import java.util.Locale; 8 9 9 10 import org.openstreetmap.josm.data.osm.TagMap; 10 11 import org.openstreetmap.josm.data.protobuf.ProtobufPacked; … … public class Feature { 110 111 Object value = layer.getValue(number.intValue()); 111 112 if (value instanceof Double || value instanceof Float) { 112 113 // reset grouping if the instance is a singleton 113 final NumberFormat numberFormat = NumberFormat.getNumberInstance( );114 final NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.ROOT); 114 115 final boolean grouping = numberFormat.isGroupingUsed(); 115 116 try { 116 117 numberFormat.setGroupingUsed(false); -
test/unit/org/openstreetmap/josm/data/imagery/vectortile/mapbox/FeatureTest.java
-- GitLab From bd8b2251deec9d5d335f7b6ab12abb796d3ee68b Mon Sep 17 00:00:00 2001 From: Taylor Smock <tsmock@fb.com> Date: Wed, 26 May 2021 14:40:50 -0600 Subject: [PATCH 2/2] FeatureTest: Add non-regression test for #20933. Signed-off-by: Taylor Smock <tsmock@fb.com> --- .../vectortile/mapbox/FeatureTest.java | 44 +++++++++++++- .../josm/testutils/annotations/I18n.java | 59 +++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java diff --git a/test/unit/org/openstreetmap/josm/data/imagery/vectortile/mapbox/FeatureTest.java b/test/unit/org/openstreetmap/josm/data/imagery/vectortile/mapbox/FeatureTest.java index 5468fe649..fcc71345b 100644
a b import static org.openstreetmap.josm.data.imagery.vectortile.mapbox.LayerTest.ge 12 12 import static org.openstreetmap.josm.data.imagery.vectortile.mapbox.LayerTest.getLayer; 13 13 14 14 import java.text.NumberFormat; 15 import java.util.ArrayList; 15 16 import java.util.Arrays; 17 import java.util.List; 16 18 17 19 import org.junit.jupiter.api.Test; 20 import org.openstreetmap.josm.testutils.annotations.I18n; 18 21 19 22 /** 20 23 * Test class for {@link Feature} … … class FeatureTest { 50 53 // This is the float we are adding 51 54 // 49 74 24 00 == 1_000_000f 52 55 // 3f 80 00 00 == 1f 53 byte[] newBytes = new byte[] {0x22, 0x0 9, 0x15, 0x00, 0x24, 0x74, 0x49};56 byte[] newBytes = new byte[] {0x22, 0x05, 0x15, 0x00, 0x24, 0x74, 0x49}; 54 57 byte[] copyBytes = Arrays.copyOf(getSimpleFeatureLayerBytes(), getSimpleFeatureLayerBytes().length + newBytes.length - 4); 55 58 // Change last few bytes 56 59 System.arraycopy(newBytes, 0, copyBytes, 25, newBytes.length); … … class FeatureTest { 79 82 assertEquals("1000000", feature.getTags().get("a")); 80 83 } 81 84 85 /** 86 * Non-regression test for #20933 (Russian) 87 * @see #testNumberGroupingDecimalEn() 88 */ 89 @I18n("ru") 90 @Test 91 void testNumberGroupingDecimalRu() { 92 testNumberGroupingDecimal(); 93 } 94 95 /** 96 * Non-regression test for #20933 (English) 97 * @see #testNumberGroupingDecimalRu() 98 */ 99 @I18n("en") 100 @Test 101 void testNumberGroupingDecimalEn() { 102 testNumberGroupingDecimal(); 103 } 104 105 /** 106 * Common parts for non-regression tests for #20933 107 * @see #testNumberGroupingDecimalEn() 108 * @see #testNumberGroupingDecimalRu() 109 */ 110 private void testNumberGroupingDecimal() { 111 byte[] newBytes = new byte[] {0x22, 0x09, 0x19, -45, 0x4D, 0x62, 0x10, 0x58, -71, 0x67, 0x40}; 112 byte[] copyBytes = Arrays.copyOf(getSimpleFeatureLayerBytes(), getSimpleFeatureLayerBytes().length + newBytes.length - 4); 113 // Change last few bytes 114 System.arraycopy(newBytes, 0, copyBytes, 25, newBytes.length); 115 // Update the length of the record 116 copyBytes[1] = (byte) (copyBytes[1] + newBytes.length - 4); 117 Layer layer = assertDoesNotThrow(() -> getLayer(copyBytes)); 118 layer.getKey(0); 119 List<Feature> features = new ArrayList<>(layer.getFeatures()); 120 assertEquals(1, features.size()); 121 assertEquals("189.792", features.get(0).getTags().get("a")); 122 } 123 82 124 private void testCreation(byte[] bytes) { 83 125 Layer layer = assertDoesNotThrow(() -> getLayer(bytes)); 84 126 // Sanity check the layer -
new file test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java
diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java b/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java new file mode 100644 index 000000000..0375427f2
- + 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.testutils.annotations; 3 4 import org.junit.jupiter.api.extension.AfterEachCallback; 5 import org.junit.jupiter.api.extension.BeforeEachCallback; 6 import org.junit.jupiter.api.extension.ExtendWith; 7 import org.junit.jupiter.api.extension.ExtensionContext; 8 import org.junit.platform.commons.support.AnnotationSupport; 9 10 import java.lang.annotation.Documented; 11 import java.lang.annotation.ElementType; 12 import java.lang.annotation.Retention; 13 import java.lang.annotation.RetentionPolicy; 14 import java.lang.annotation.Target; 15 import java.util.Optional; 16 17 import static java.util.Collections.emptyList; 18 19 /** 20 * Enables the i18n module for this test. 21 * @author Taylor Smock 22 * @see JOSMTestRules#i18n(String) 23 * 24 */ 25 @Documented 26 @Retention(RetentionPolicy.RUNTIME) 27 @Target({ElementType.TYPE, ElementType.METHOD}) 28 @ExtendWith(I18n.I18nExtension.class) 29 public @interface I18n { 30 /** 31 * Get the language to use for i18n 32 * @return The language (default "en"). 33 */ 34 String value() default "en"; 35 36 /** 37 * Enables the i18n module for this test. 38 * @author Taylor Smock 39 * @see JOSMTestRules#i18n(String) 40 * 41 */ 42 class I18nExtension implements AfterEachCallback, BeforeEachCallback { 43 @Override 44 public void afterEach(ExtensionContext context) throws Exception { 45 org.openstreetmap.josm.tools.I18n.set("en"); 46 org.openstreetmap.josm.tools.I18n.set(org.openstreetmap.josm.tools.I18n.getOriginalLocale().getLanguage()); 47 } 48 49 @Override 50 public void beforeEach(ExtensionContext context) throws Exception { 51 Optional<I18n> annotation = AnnotationSupport.findAnnotation(context.getElement(), I18n.class); 52 String language = "en"; 53 if (annotation.isPresent()) { 54 language = annotation.get().value(); 55 } 56 org.openstreetmap.josm.tools.I18n.set(language); 57 } 58 } 59 }