Changeset 17758 in josm for trunk/test


Ignore:
Timestamp:
2021-04-12T21:20:31+02:00 (3 years ago)
Author:
simon04
Message:

fix #20744 - Evaluate MapCSS expression without array creation

Location:
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactoryTest.java

    r17275 r17758  
    88import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    99import net.trajano.commons.testing.UtilityClassTestUtil;
     10
     11import java.lang.reflect.Method;
     12import java.lang.reflect.Modifier;
    1013
    1114/**
     
    2932        UtilityClassTestUtil.assertUtilityClassWellDefined(Functions.class);
    3033    }
     34
     35    /**
     36     * Tests that all functions have been registered to {@link ExpressionFactory#FACTORY_MAP}
     37     *
     38     * For instance to register {@link Functions#osm_id}, {@code FACTORY_MAP.put("osm_id", Factory.ofEnv(Functions::osm_id))}
     39     */
     40    @Test
     41    void testNoUnregisteredFunctions() {
     42        for (Method m : Functions.class.getDeclaredMethods()) {
     43            if (!Modifier.isPrivate(m.getModifiers()) && !ExpressionFactory.FACTORY_MAP.containsKey(m.getName())) {
     44                throw new AssertionError(m + " has not registered in ExpressionFactory.FACTORY_MAP");
     45            }
     46        }
     47    }
    3148}
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java

    r17745 r17758  
    368368        MultiCascade mc = new MultiCascade();
    369369        sheet.apply(mc, OsmUtils.createPrimitive("way foo=bar"), 20, false);
    370         assertEquals(Float.valueOf(5f), mc.getCascade(null).get("width"));
     370        assertEquals(5.0f, mc.getCascade(null).get("width"));
    371371        sheet.apply(mc, OsmUtils.createPrimitive("way keyA=true"), 20, false);
    372         assertEquals(Float.valueOf(15f), mc.getCascade(null).get("width"));
     372        assertEquals(15.0, mc.getCascade(null).get("width"));
    373373        sheet.apply(mc, OsmUtils.createPrimitive("way keyB=true"), 20, false);
    374         assertEquals(Float.valueOf(15f), mc.getCascade(null).get("width"));
     374        assertEquals(15.0, mc.getCascade(null).get("width"));
    375375        sheet.apply(mc, OsmUtils.createPrimitive("way keyA=true keyB=true"), 20, false);
    376         assertEquals(Float.valueOf(15f), mc.getCascade(null).get("width"));
     376        assertEquals(15.0, mc.getCascade(null).get("width"));
    377377    }
    378378
     
    480480    @Test
    481481    void testSort() throws Exception {
    482         assertEquals(Arrays.asList(new String[] {"alpha", "beta"}), Functions.sort("beta", "alpha"));
     482        assertEquals(Arrays.asList(new String[] {"alpha", "beta"}), Functions.sort(null, "beta", "alpha"));
    483483        Way way1 = TestUtils.newWay("highway=residential name=Alpha alt_name=Beta ref=\"A9;A8\"", new Node(new LatLon(0.001, 0.001)),
    484484                new Node(new LatLon(0.002, 0.002)));
     
    490490        assertTrue(source.rules.get(0).matches(e));
    491491        source.rules.get(0).declaration.execute(e);
    492         assertEquals(Functions.join(",", "Alpha", "Beta"), e.getCascade(null).get("sorted", null, String.class));
     492        assertEquals(Functions.join(null, ",", "Alpha", "Beta"), e.getCascade(null).get("sorted", null, String.class));
    493493
    494494        source = new MapCSSStyleSource("way[ref] {sorted: join_list(\",\", sort_list(split(\";\", tag(\"ref\"))));}");
     
    497497        assertTrue(source.rules.get(0).matches(e));
    498498        source.rules.get(0).declaration.execute(e);
    499         assertEquals(Functions.join(",", "A8", "A9"), e.getCascade(null).get("sorted", null, String.class));
     499        assertEquals(Functions.join(null, ",", "A8", "A9"), e.getCascade(null).get("sorted", null, String.class));
    500500    }
    501501
     
    503503    void testUniqueValues() throws Exception {
    504504        assertEquals(Arrays.asList(new String[] {"alpha", "beta"}),
    505                 Functions.uniq("alpha", "alpha", "alpha", "beta"));
     505                Functions.uniq(null, "alpha", "alpha", "alpha", "beta"));
    506506        assertEquals(Arrays.asList(new String[] {"one", "two", "three"}),
    507507                Functions.uniq_list(Arrays.asList(new String[] {"one", "one", "two", "two", "two", "three"})));
     
    597597
    598598    @Test
     599    void testMath() {
     600        MapCSSStyleSource source = new MapCSSStyleSource("node { add: 1 + 2 + 3 + 4; mul: 2 * 3 * 5 * 7; sub: 0 - 1 - 2 - 3; div: 360 / 15; }");
     601        source.loadStyleSource();
     602        MultiCascade mc = new MultiCascade();
     603        source.apply(mc, OsmUtils.createPrimitive("node"), 20, false);
     604        assertEquals(10.0, mc.getCascade(null).get("add"));
     605        assertEquals(210.0, mc.getCascade(null).get("mul"));
     606        assertEquals(-6.0, mc.getCascade(null).get("sub"));
     607        assertEquals(24.0, mc.getCascade(null).get("div"));
     608    }
     609
     610    @Test
    599611    void testMinMaxFunctions() throws Exception {
    600612        MapCSSStyleSource sheet = new MapCSSStyleSource("* {" +
Note: See TracChangeset for help on using the changeset viewer.