Ticket #17995: 17995.patch

File 17995.patch, 2.4 KB (added by taylor.smock, 2 years ago)

Add mapcss sort method and test

  • src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java

     
    494494    }
    495495
    496496    /**
     497     * Sort an array of strings
     498     * @param sortables The array to sort
     499     * @return The sorted array
     500     */
     501    public static List<String> sort(String... sortables) {
     502        Arrays.parallelSort(sortables);
     503        return Arrays.asList(sortables);
     504    }
     505
     506    /**
    497507     * Returns the role of current object in parent relation, or role of child if current object is a relation.
    498508     * @param env the environment
    499509     * @return role of current object in parent relation, or role of child if current object is a relation
  • test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java

    (this hunk was shorter than expected) 
    99
    1010import java.awt.Color;
    1111import java.io.StringReader;
     12import java.util.Arrays;
    1213import java.util.List;
    1314
    1415import org.junit.Rule;
     
    407409    }
    408410
    409411    @Test
     412    public void testSort() throws Exception {
     413        assertEquals(Arrays.asList(new String[] {"alpha", "beta"}), Functions.sort("beta", "alpha"));
     414        Way way1 = TestUtils.newWay("highway=residential name=Alpha alt_name=Beta", new Node(new LatLon(0.001, 0.001)),
     415                new Node(new LatLon(0.002, 0.002)));
     416
     417        MapCSSStyleSource source = new MapCSSStyleSource("way[highway] {sorted: join_list(\",\", sort(tag(\"alt_name\"), tag(\"name\")));}");
     418        source.loadStyleSource();
     419        assertEquals(1, source.rules.size());
     420        Environment e = new Environment(way1, new MultiCascade(), Environment.DEFAULT_LAYER, null);
     421        assertTrue(source.rules.get(0).selector.matches(e));
     422        source.rules.get(0).declaration.execute(e);
     423        assertEquals(Functions.join(",", "Alpha", "Beta"), e.getCascade(Environment.DEFAULT_LAYER).get("sorted", null, String.class));
     424    }
     425
     426    @Test
    410427    public void testCountRoles() throws Exception {
    411428        DataSet ds = new DataSet();
    412429        Way way1 = TestUtils.newWay("highway=residential name=1",