Changeset 16307 in josm for trunk/test/unit


Ignore:
Timestamp:
2020-04-15T21:59:16+02:00 (5 years ago)
Author:
simon04
Message:

SearchCompilerTest: use OsmUtils.createPrimitive

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java

    r16268 r16307  
    2626import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2727import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     28import org.openstreetmap.josm.data.osm.OsmUtils;
    2829import org.openstreetmap.josm.data.osm.Relation;
    2930import org.openstreetmap.josm.data.osm.RelationData;
     
    108109    }
    109110
    110     private static OsmPrimitive newPrimitive(String key, String value) {
    111         final Node p = new Node();
    112         p.put(key, value);
    113         return p;
    114     }
    115 
    116111    /**
    117112     * Search anything.
     
    121116    public void testAny() throws SearchParseError {
    122117        final SearchCompiler.Match c = SearchCompiler.compile("foo");
    123         assertTrue(c.match(newPrimitive("foobar", "true")));
    124         assertTrue(c.match(newPrimitive("name", "hello-foo-xy")));
    125         assertFalse(c.match(newPrimitive("name", "X")));
     118        assertTrue(c.match(OsmUtils.createPrimitive("node foobar=true")));
     119        assertTrue(c.match(OsmUtils.createPrimitive("node name=hello-foo-xy")));
     120        assertFalse(c.match(OsmUtils.createPrimitive("node name=X")));
    126121        assertEquals("foo", c.toString());
    127122    }
     
    134129    public void testEquals() throws SearchParseError {
    135130        final SearchCompiler.Match c = SearchCompiler.compile("foo=bar");
    136         assertFalse(c.match(newPrimitive("foobar", "true")));
    137         assertTrue(c.match(newPrimitive("foo", "bar")));
    138         assertFalse(c.match(newPrimitive("fooX", "bar")));
    139         assertFalse(c.match(newPrimitive("foo", "barX")));
     131        assertFalse(c.match(OsmUtils.createPrimitive("node foobar=true")));
     132        assertTrue(c.match(OsmUtils.createPrimitive("node foo=bar")));
     133        assertFalse(c.match(OsmUtils.createPrimitive("node fooX=bar")));
     134        assertFalse(c.match(OsmUtils.createPrimitive("node foo=barX")));
    140135        assertEquals("foo=bar", c.toString());
    141136    }
     
    148143    public void testRegexp() throws SearchParseError {
    149144        final SearchCompiler.Match c = SearchCompiler.compile("foo~[Bb]a[rz]");
    150         assertFalse(c.match(newPrimitive("foobar", "true")));
    151         assertFalse(c.match(newPrimitive("foo", "foo")));
    152         assertTrue(c.match(newPrimitive("foo", "bar")));
    153         assertTrue(c.match(newPrimitive("foo", "baz")));
    154         assertTrue(c.match(newPrimitive("foo", "Baz")));
     145        assertFalse(c.match(OsmUtils.createPrimitive("node foobar=true")));
     146        assertFalse(c.match(OsmUtils.createPrimitive("node foo=foo")));
     147        assertTrue(c.match(OsmUtils.createPrimitive("node foo=bar")));
     148        assertTrue(c.match(OsmUtils.createPrimitive("node foo=baz")));
     149        assertTrue(c.match(OsmUtils.createPrimitive("node foo=Baz")));
    155150        assertEquals("foo=[Bb]a[rz]", c.toString());
    156151    }
     
    163158    public void testCompare() throws SearchParseError {
    164159        final SearchCompiler.Match c1 = SearchCompiler.compile("start_date>1950");
    165         assertTrue(c1.match(newPrimitive("start_date", "1950-01-01")));
    166         assertTrue(c1.match(newPrimitive("start_date", "1960")));
    167         assertFalse(c1.match(newPrimitive("start_date", "1950")));
    168         assertFalse(c1.match(newPrimitive("start_date", "1000")));
    169         assertTrue(c1.match(newPrimitive("start_date", "101010")));
     160        assertTrue(c1.match(OsmUtils.createPrimitive("node start_date=1950-01-01")));
     161        assertTrue(c1.match(OsmUtils.createPrimitive("node start_date=1960")));
     162        assertFalse(c1.match(OsmUtils.createPrimitive("node start_date=1950")));
     163        assertFalse(c1.match(OsmUtils.createPrimitive("node start_date=1000")));
     164        assertTrue(c1.match(OsmUtils.createPrimitive("node start_date=101010")));
    170165
    171166        final SearchCompiler.Match c2 = SearchCompiler.compile("start_date<1960");
    172         assertTrue(c2.match(newPrimitive("start_date", "1950-01-01")));
    173         assertFalse(c2.match(newPrimitive("start_date", "1960")));
    174         assertTrue(c2.match(newPrimitive("start_date", "1950")));
    175         assertTrue(c2.match(newPrimitive("start_date", "1000")));
    176         assertTrue(c2.match(newPrimitive("start_date", "200")));
     167        assertTrue(c2.match(OsmUtils.createPrimitive("node start_date=1950-01-01")));
     168        assertFalse(c2.match(OsmUtils.createPrimitive("node start_date=1960")));
     169        assertTrue(c2.match(OsmUtils.createPrimitive("node start_date=1950")));
     170        assertTrue(c2.match(OsmUtils.createPrimitive("node start_date=1000")));
     171        assertTrue(c2.match(OsmUtils.createPrimitive("node start_date=200")));
    177172
    178173        final SearchCompiler.Match c3 = SearchCompiler.compile("name<I");
    179         assertTrue(c3.match(newPrimitive("name", "Alpha")));
    180         assertFalse(c3.match(newPrimitive("name", "Sigma")));
     174        assertTrue(c3.match(OsmUtils.createPrimitive("node name=Alpha")));
     175        assertFalse(c3.match(OsmUtils.createPrimitive("node name=Sigma")));
    181176
    182177        final SearchCompiler.Match c4 = SearchCompiler.compile("\"start_date\"<1960");
    183         assertTrue(c4.match(newPrimitive("start_date", "1950-01-01")));
    184         assertFalse(c4.match(newPrimitive("start_date", "2000")));
     178        assertTrue(c4.match(OsmUtils.createPrimitive("node start_date=1950-01-01")));
     179        assertFalse(c4.match(OsmUtils.createPrimitive("node start_date=2000")));
    185180
    186181        final SearchCompiler.Match c5 = SearchCompiler.compile("height>180");
    187         assertTrue(c5.match(newPrimitive("height", "200")));
    188         assertTrue(c5.match(newPrimitive("height", "99999")));
    189         assertFalse(c5.match(newPrimitive("height", "50")));
    190         assertFalse(c5.match(newPrimitive("height", "-9999")));
    191         assertFalse(c5.match(newPrimitive("height", "fixme")));
     182        assertTrue(c5.match(OsmUtils.createPrimitive("node height=200")));
     183        assertTrue(c5.match(OsmUtils.createPrimitive("node height=99999")));
     184        assertFalse(c5.match(OsmUtils.createPrimitive("node height=50")));
     185        assertFalse(c5.match(OsmUtils.createPrimitive("node height=-9999")));
     186        assertFalse(c5.match(OsmUtils.createPrimitive("node height=fixme")));
    192187
    193188        final SearchCompiler.Match c6 = SearchCompiler.compile("name>C");
    194         assertTrue(c6.match(newPrimitive("name", "Delta")));
    195         assertFalse(c6.match(newPrimitive("name", "Alpha")));
     189        assertTrue(c6.match(OsmUtils.createPrimitive("node name=Delta")));
     190        assertFalse(c6.match(OsmUtils.createPrimitive("node name=Alpha")));
    196191    }
    197192
     
    458453    public void testBooleanLogic() throws SearchParseError {
    459454        final SearchCompiler.Match c1 = SearchCompiler.compile("foo AND bar AND baz");
    460         assertTrue(c1.match(newPrimitive("foobar", "baz")));
     455        assertTrue(c1.match(OsmUtils.createPrimitive("node foobar=baz")));
    461456        assertEquals("foo && bar && baz", c1.toString());
    462457        final SearchCompiler.Match c2 = SearchCompiler.compile("foo AND (bar OR baz)");
    463         assertTrue(c2.match(newPrimitive("foobar", "yes")));
    464         assertTrue(c2.match(newPrimitive("foobaz", "yes")));
     458        assertTrue(c2.match(OsmUtils.createPrimitive("node foobar=yes")));
     459        assertTrue(c2.match(OsmUtils.createPrimitive("node foobaz=yes")));
    465460        assertEquals("foo && (bar || baz)", c2.toString());
    466461        final SearchCompiler.Match c3 = SearchCompiler.compile("foo OR (bar baz)");
Note: See TracChangeset for help on using the changeset viewer.