Ticket #19508: 19508v1.patch

File 19508v1.patch, 2.8 KB (added by gaben, 9 months ago)

The patch is based on the modified regex, plus added some test cases. The test cases were swapped I fixed that as well.

  • src/org/openstreetmap/josm/actions/corrector/ReverseWayTagCorrector.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    206206     * @return opposite numeric value
    207207     */
    208208    public static String invertNumber(String value) {
    209         Pattern pattern = Pattern.compile("^([+-]?)(\\d.*)$", Pattern.CASE_INSENSITIVE);
     209        Pattern pattern = Pattern.compile("^([+-]?)(\\d*[,.]?\\d*)(.*)$", Pattern.CASE_INSENSITIVE);
    210210        Matcher matcher = pattern.matcher(value);
    211211        if (!matcher.matches()) return value;
    212212        String sign = matcher.group(1);
    213         String rest = matcher.group(2);
     213        String number = matcher.group(2);
     214        String symbol = matcher.group(3);
    214215        sign = "-".equals(sign) ? "" : "-";
    215         return sign + rest;
     216
     217        if (!number.isEmpty()) {
     218            String fixedNum = number.replace(",", ".");
     219            double parsed = Double.parseDouble(sign + fixedNum);
     220            if (parsed > 0 || parsed < 0) {
     221                return sign + number + symbol;
     222            }
     223        }
     224
     225        return value;
    216226    }
    217227
    218228    static List<TagCorrection> getTagCorrections(Tagged way) {
  • test/unit/org/openstreetmap/josm/actions/corrector/ReverseWayTagCorrectorTest.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    9696        assertSwitch(new Tag("something", "prefix_down_suffix"), new Tag("something", "prefix_up_suffix"));
    9797        // #8499
    9898        assertSwitch(new Tag("type", "drawdown"), new Tag("type", "drawdown"));
     99        // #19508
     100        assertSwitch(new Tag("incline", "0%"), new Tag("incline", "0%"));
     101        assertSwitch(new Tag("incline", "-10%"), new Tag("incline", "10%"));
     102        assertSwitch(new Tag("incline", "0.6°"), new Tag("incline", "-0.6°"));
     103        assertSwitch(new Tag("incline", "-10,33°"), new Tag("incline", "10,33°"));
    99104    }
    100105
    101106    private void assertSwitch(Tag oldTag, Tag newTag) {
    102         Assert.assertEquals(ReverseWayTagCorrector.TagSwitcher.apply(oldTag), newTag);
     107        Assert.assertEquals(newTag, ReverseWayTagCorrector.TagSwitcher.apply(oldTag));
    103108    }
    104109
    105110    private Map<OsmPrimitive, List<TagCorrection>> getTagCorrectionsForWay(String middleNodeTags) {