Ignore:
Timestamp:
2015-10-01T21:06:10+02:00 (9 years ago)
Author:
simon04
Message:

see #11916 - Refactoring of SearchAction/SearchCompiler

Location:
trunk/test/unit/org/openstreetmap/josm/actions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.groovy

    r7938 r8811  
    55import org.openstreetmap.josm.JOSMFixture
    66import org.openstreetmap.josm.TestUtils
     7import org.openstreetmap.josm.actions.search.SearchAction
    78import org.openstreetmap.josm.actions.search.SearchCompiler
    89import org.openstreetmap.josm.data.osm.Relation
     
    2627    }
    2728
     29    static def regexpSearch(String search) {
     30        def setting = new SearchAction.SearchSetting()
     31        setting.text = search
     32        setting.regexSearch = true
     33        return setting
     34    }
     35
    2836    @Test
    2937    public void testCreate1() {
     
    3745    public void testCreate2() {
    3846        def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
    39         def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1.", false, false))
     47        def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1."))
    4048        def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, null)
    4149        assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1.1:inner, 1.1.2:inner]"
     
    4553    public void testUpdate1() {
    4654        def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
    47         def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=\".*1\$\"", false, true))
     55        def ways = Utils.filter(ds.getWays(), SearchCompiler.compile(regexpSearch("ref=\".*1\$\"")))
    4856        def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, null)
    4957        assert mp.b.getMembersCount() == 3
    5058        assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer]"
    51         def ways2 = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1.2", false, true))
     59        def ways2 = Utils.filter(ds.getWays(), SearchCompiler.compile(regexpSearch("ref=1.2")))
    5260        def mp2 = CreateMultipolygonAction.createMultipolygonCommand(ways2 as Collection<Way>, mp.b)
    5361        assert mp2.b.getMembersCount() == 4
     
    5866    public void testUpdate2() {
    5967        def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
    60         def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1.1", false, false))
     68        def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1.1"))
    6169        def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, null)
    6270        assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1.1:inner]"
    63         def ways2 = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1.1 OR ref=1.2 OR ref=1.1.2", false, true))
     71        def ways2 = Utils.filter(ds.getWays(), SearchCompiler.compile(regexpSearch("ref=1.1 OR ref=1.2 OR ref=1.1.2")))
    6472        def mp2 = CreateMultipolygonAction.createMultipolygonCommand(ways2 as Collection<Way>, mp.b)
    6573        assert getRefToRoleMap(mp2.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer, 1.1.2:outer, 1.2:inner]"
  • trunk/test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java

    r8509 r8811  
    3131    @Test
    3232    public void testAny() throws Exception {
    33         final SearchCompiler.Match c = SearchCompiler.compile("foo", false, false);
     33        final SearchCompiler.Match c = SearchCompiler.compile("foo");
    3434        Assert.assertTrue(c.match(newPrimitive("foobar", "true")));
    3535        Assert.assertTrue(c.match(newPrimitive("name", "hello-foo-xy")));
     
    3939    @Test
    4040    public void testEquals() throws Exception {
    41         final SearchCompiler.Match c = SearchCompiler.compile("foo=bar", false, false);
     41        final SearchCompiler.Match c = SearchCompiler.compile("foo=bar");
    4242        Assert.assertFalse(c.match(newPrimitive("foobar", "true")));
    4343        Assert.assertTrue(c.match(newPrimitive("foo", "bar")));
     
    4848    @Test
    4949    public void testCompare() throws Exception {
    50         final SearchCompiler.Match c1 = SearchCompiler.compile("start_date>1950", false, false);
     50        final SearchCompiler.Match c1 = SearchCompiler.compile("start_date>1950");
    5151        Assert.assertTrue(c1.match(newPrimitive("start_date", "1950-01-01")));
    5252        Assert.assertTrue(c1.match(newPrimitive("start_date", "1960")));
     
    5454        Assert.assertFalse(c1.match(newPrimitive("start_date", "1000")));
    5555        Assert.assertTrue(c1.match(newPrimitive("start_date", "101010")));
    56         final SearchCompiler.Match c2 = SearchCompiler.compile("start_date<1960", false, false);
     56        final SearchCompiler.Match c2 = SearchCompiler.compile("start_date<1960");
    5757        Assert.assertTrue(c2.match(newPrimitive("start_date", "1950-01-01")));
    5858        Assert.assertFalse(c2.match(newPrimitive("start_date", "1960")));
     
    6060        Assert.assertTrue(c2.match(newPrimitive("start_date", "1000")));
    6161        Assert.assertTrue(c2.match(newPrimitive("start_date", "200")));
    62         final SearchCompiler.Match c3 = SearchCompiler.compile("name<I", false, false);
     62        final SearchCompiler.Match c3 = SearchCompiler.compile("name<I");
    6363        Assert.assertTrue(c3.match(newPrimitive("name", "Alpha")));
    6464        Assert.assertFalse(c3.match(newPrimitive("name", "Sigma")));
    65         final SearchCompiler.Match c4 = SearchCompiler.compile("\"start_date\"<1960", false, false);
     65        final SearchCompiler.Match c4 = SearchCompiler.compile("\"start_date\"<1960");
    6666        Assert.assertTrue(c4.match(newPrimitive("start_date", "1950-01-01")));
    6767        Assert.assertFalse(c4.match(newPrimitive("start_date", "2000")));
     
    8383        way.addNode(node1);
    8484        way.addNode(node2);
    85         Assert.assertFalse(SearchCompiler.compile("nth:2", false, false).match(node1));
    86         Assert.assertTrue(SearchCompiler.compile("nth:1", false, false).match(node1));
    87         Assert.assertFalse(SearchCompiler.compile("nth:0", false, false).match(node1));
    88         Assert.assertTrue(SearchCompiler.compile("nth:0", false, false).match(node0));
    89         Assert.assertTrue(SearchCompiler.compile("nth:2", false, false).match(node2));
    90         Assert.assertTrue(SearchCompiler.compile("nth:-1", false, false).match(node2));
    91         Assert.assertTrue(SearchCompiler.compile("nth:-2", false, false).match(node1));
    92         Assert.assertTrue(SearchCompiler.compile("nth:-3", false, false).match(node0));
     85        Assert.assertFalse(SearchCompiler.compile("nth:2").match(node1));
     86        Assert.assertTrue(SearchCompiler.compile("nth:1").match(node1));
     87        Assert.assertFalse(SearchCompiler.compile("nth:0").match(node1));
     88        Assert.assertTrue(SearchCompiler.compile("nth:0").match(node0));
     89        Assert.assertTrue(SearchCompiler.compile("nth:2").match(node2));
     90        Assert.assertTrue(SearchCompiler.compile("nth:-1").match(node2));
     91        Assert.assertTrue(SearchCompiler.compile("nth:-2").match(node1));
     92        Assert.assertTrue(SearchCompiler.compile("nth:-3").match(node0));
    9393    }
    9494
    9595    @Test
    9696    public void testNthParseNegative() throws Exception {
    97         Assert.assertThat(SearchCompiler.compile("nth:-1", false, false).toString(), CoreMatchers.is("Nth{nth=-1, modulo=false}"));
     97        Assert.assertThat(SearchCompiler.compile("nth:-1").toString(), CoreMatchers.is("Nth{nth=-1, modulo=false}"));
    9898
    9999    }
Note: See TracChangeset for help on using the changeset viewer.