Changeset 16307 in josm for trunk/test
- Timestamp:
- 2020-04-15T21:59:16+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java
r16268 r16307 26 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; 27 27 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 28 import org.openstreetmap.josm.data.osm.OsmUtils; 28 29 import org.openstreetmap.josm.data.osm.Relation; 29 30 import org.openstreetmap.josm.data.osm.RelationData; … … 108 109 } 109 110 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 116 111 /** 117 112 * Search anything. … … 121 116 public void testAny() throws SearchParseError { 122 117 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"))); 126 121 assertEquals("foo", c.toString()); 127 122 } … … 134 129 public void testEquals() throws SearchParseError { 135 130 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"))); 140 135 assertEquals("foo=bar", c.toString()); 141 136 } … … 148 143 public void testRegexp() throws SearchParseError { 149 144 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"))); 155 150 assertEquals("foo=[Bb]a[rz]", c.toString()); 156 151 } … … 163 158 public void testCompare() throws SearchParseError { 164 159 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"))); 170 165 171 166 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"))); 177 172 178 173 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"))); 181 176 182 177 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"))); 185 180 186 181 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"))); 192 187 193 188 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"))); 196 191 } 197 192 … … 458 453 public void testBooleanLogic() throws SearchParseError { 459 454 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"))); 461 456 assertEquals("foo && bar && baz", c1.toString()); 462 457 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"))); 465 460 assertEquals("foo && (bar || baz)", c2.toString()); 466 461 final SearchCompiler.Match c3 = SearchCompiler.compile("foo OR (bar baz)");
Note:
See TracChangeset
for help on using the changeset viewer.