- Timestamp:
- 2019-09-24T16:43:57+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/tools/OverpassTurboQueryWizardTest.java
r14327 r15370 4 4 import static org.junit.Assert.assertEquals; 5 5 6 import org.junit.Ignore; 6 7 import org.junit.Rule; 7 8 import org.junit.Test; … … 22 23 23 24 /** 24 * Test key=value.25 * Test {@code key=value}. 25 26 */ 26 27 @Test … … 39 40 40 41 /** 42 * Test {@code key!=value}. 43 */ 44 @Test 45 public void testKeyNotValue() { 46 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("amenity!=drinking_water"); 47 assertEquals("" + 48 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 49 "(\n" + 50 " node[\"amenity\"!=\"drinking_water\"];\n" + 51 " way[\"amenity\"!=\"drinking_water\"];\n" + 52 " relation[\"amenity\"!=\"drinking_water\"];\n" + 53 ");\n" + 54 "(._;>;);\n" + 55 "out meta;", query); 56 } 57 58 /** 59 * Test {@code foo=bar and baz=42}. 60 */ 61 @Test 62 public void testBooleanAnd() { 63 final String expected = "" + 64 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 65 "(\n" + 66 " node[\"foo\"=\"bar\"][\"baz\"=\"42\"];\n" + 67 " way[\"foo\"=\"bar\"][\"baz\"=\"42\"];\n" + 68 " relation[\"foo\"=\"bar\"][\"baz\"=\"42\"];\n" + 69 ");\n" + 70 "(._;>;);\n" + 71 "out meta;"; 72 assertEquals(expected, OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar and baz=42")); 73 assertEquals(expected, OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar && baz=42")); 74 assertEquals(expected, OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar & baz=42")); 75 } 76 77 /** 78 * Test {@code foo=bar or baz=42}. 79 */ 80 @Test 81 public void testBooleanOr() { 82 final String expected = "" + 83 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 84 "(\n" + 85 " node[\"foo\"=\"bar\"];\n" + 86 " way[\"foo\"=\"bar\"];\n" + 87 " relation[\"foo\"=\"bar\"];\n" + 88 " node[\"baz\"=\"42\"];\n" + 89 " way[\"baz\"=\"42\"];\n" + 90 " relation[\"baz\"=\"42\"];\n" + 91 ");\n" + 92 "(._;>;);\n" + 93 "out meta;"; 94 assertEquals(expected, OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar or baz=42")); 95 assertEquals(expected, OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar || baz=42")); 96 assertEquals(expected, OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar | baz=42")); 97 } 98 99 /** 100 * Test {@code (foo=* or bar=*) and (asd=* or fasd=*)}. 101 */ 102 @Test 103 public void testBoolean() { 104 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("(foo=* or bar=*) and (asd=* or fasd=*)"); 105 assertEquals("" + 106 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 107 "(\n" + 108 " node[\"foo\"][\"asd\"];\n" + 109 " way[\"foo\"][\"asd\"];\n" + 110 " relation[\"foo\"][\"asd\"];\n" + 111 " node[\"foo\"][\"fasd\"];\n" + 112 " way[\"foo\"][\"fasd\"];\n" + 113 " relation[\"foo\"][\"fasd\"];\n" + 114 " node[\"bar\"][\"asd\"];\n" + 115 " way[\"bar\"][\"asd\"];\n" + 116 " relation[\"bar\"][\"asd\"];\n" + 117 " node[\"bar\"][\"fasd\"];\n" + 118 " way[\"bar\"][\"fasd\"];\n" + 119 " relation[\"bar\"][\"fasd\"];\n" + 120 ");\n" + 121 "(._;>;);\n" + 122 "out meta;", query); 123 } 124 125 /** 126 * Test {@code foo=bar and (type:node or type:way)}. 127 */ 128 @Test 129 public void testType() { 130 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar and (type:node or type:way)"); 131 assertEquals("" + 132 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 133 "(\n" + 134 " node[\"foo\"=\"bar\"];\n" + 135 " way[\"foo\"=\"bar\"];\n" + 136 ");\n" + 137 "(._;>;);\n" + 138 "out meta;", query); 139 } 140 141 /** 142 * Test {@code user:foo or uid:42}. 143 */ 144 @Test 145 public void testUser() { 146 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("user:foo or uid:42"); 147 assertEquals("" + 148 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 149 "(\n" + 150 " node(user:\"foo\");\n" + 151 " way(user:\"foo\");\n" + 152 " relation(user:\"foo\");\n" + 153 " node(uid:42);\n" + 154 " way(uid:42);\n" + 155 " relation(uid:42);\n" + 156 ");\n" + 157 "(._;>;);\n" + 158 "out meta;", query); 159 } 160 161 /** 162 * Test {@code foo=bar and (type:node or type:way)}. 163 */ 164 @Test 165 public void testEmpty() { 166 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("foo='' and type:way"); 167 assertEquals("" + 168 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 169 "(\n" + 170 " way[\"foo\"~\"^$\"];\n" + 171 ");\n" + 172 "(._;>;);\n" + 173 "out meta;", query); 174 } 175 176 /** 177 * Test geocodeArea. 178 */ 179 @Test 180 public void testInArea() { 181 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar in Josmland"); 182 assertEquals("" + 183 "[out:xml][timeout:90];\n" + 184 "{{geocodeArea:Josmland}}->.searchArea;\n" + 185 "(\n" + 186 " node[\"foo\"=\"bar\"](area.searchArea);\n" + 187 " way[\"foo\"=\"bar\"](area.searchArea);\n" + 188 " relation[\"foo\"=\"bar\"](area.searchArea);\n" + 189 ");\n" + 190 "(._;>;);\n" + 191 "out meta;", query); 192 } 193 194 /** 195 * Test building an Overpass query based on a preset name. 196 */ 197 @Test 198 @Ignore("preset handling not implemented") 199 public void testPreset() { 200 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("Hospital"); 201 assertEquals("" + 202 "[out:xml][timeout:90];\n" + 203 "(\n" + 204 " node[\"amenity\"=\"hospital\"];\n" + 205 " way[\"amenity\"=\"hospital\"];\n" + 206 " relation[\"amenity\"=\"hospital\"];\n" + 207 ");\n" + 208 "(._;>;);\n" + 209 "out meta;", query); 210 } 211 212 /** 41 213 * Test erroneous value. 42 214 */
Note:
See TracChangeset
for help on using the changeset viewer.