Changeset 17916 in josm


Ignore:
Timestamp:
2021-06-02T20:40:56+02:00 (3 years ago)
Author:
simon04
Message:

fix #20957, see #20744 - Fix MapCSS function round

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r17832 r17916  
    228228        FACTORY_MAP.put("rgba", Factory.of(float.class, float.class, float.class, float.class, Functions::rgba));
    229229        FACTORY_MAP.put("role", Factory.ofEnv(Functions::role));
    230         FACTORY_MAP.put("round", Factory.of(Math::acos));
     230        FACTORY_MAP.put("round", Factory.of(Math::round));
    231231        FACTORY_MAP.put("setting", Factory.ofEnv(String.class, Functions::setting));
    232232        FACTORY_MAP.put("signum", Factory.of(Math::signum));
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r17619 r17916  
    425425
    426426    /**
    427      * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/19053">Bug #19053</a>.
    428      * Mapcss rule with group.
     427     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/19053">Bug #19053</a> and
     428     * <a href="https://josm.openstreetmap.de/ticket/20957">Bug #20957</a>
     429     * - MapCSS rule with group.
     430     * - MapCSS functions round, tag, *, /
    429431     * @throws ParseException if a parsing error occurs
    430432     */
     
    434436                "*[ele][ele =~ /^-?[0-9]+\\.[0-9][0-9][0-9]+$/] {"
    435437                        + "throwWarning: tr(\"{0}\",\"{0.tag}\");"
     438                        + "fixAdd: concat(\"ele=\", round(tag(\"ele\")*100)/100);"
    436439                        + "group: tr(\"Unnecessary amount of decimal places\");" + "}");
    437440        final OsmPrimitive p = OsmUtils.createPrimitive("node ele=12.123456");
     441        new DataSet(p);
    438442        final Collection<TestError> errors = test.getErrorsForPrimitive(p, false);
    439443        assertEquals(1, errors.size());
     
    441445        assertEquals("3000_ele=12.123456", errors.iterator().next().getIgnoreSubGroup());
    442446        assertEquals("3000_Unnecessary amount of decimal places", errors.iterator().next().getIgnoreGroup());
     447        Command fix = errors.iterator().next().getFix();
     448        assertNotNull(fix);
     449        assertEquals("12.123456", p.get("ele"));
     450        fix.executeCommand();
     451        assertEquals("12.12", p.get("ele"));
    443452    }
    444453
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java

    r17832 r17916  
    615615                "null1: tag(x1) + tag(x2);" +
    616616                "null2: 3 + tag(does_not_exist) + 5;" +
     617                "rounding: concat(\"ele=\", round(tag(\"ele\")*100)/100);" +
    617618                "}");
    618619        source.loadStyleSource();
     
    628629        assertNull(mc.getCascade(null).get("null1"));
    629630        assertEquals(8.0, mc.getCascade(null).get("null2"));
     631        assertEquals(8.0, mc.getCascade(null).get("rounding"));
    630632    }
    631633
     
    738740        assertNull(mc.getCascade(null).get("name"));
    739741    }
     742
     743    /**
     744     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/20957">Bug #20957</a>.
     745     */
     746    @Test
     747    void testTicket20957() {
     748        MapCSSStyleSource source = new MapCSSStyleSource("node {fixAdd: concat(\"ele=\", round(tag(\"ele\")*100)/100)}");
     749        source.loadStyleSource();
     750        MultiCascade mc = new MultiCascade();
     751        source.apply(mc, OsmUtils.createPrimitive("node ele=12.123456"), 20, false);
     752        assertEquals("ele=12.12", mc.getCascade(null).get("fixAdd"));
     753    }
    740754}
Note: See TracChangeset for help on using the changeset viewer.