Changeset 16261 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2020-04-11T17:37:02+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/tools/OverpassTurboQueryWizardTest.java
r15814 r16261 22 22 public JOSMTestRules test = new JOSMTestRules().timeout(15000); 23 23 24 private void assertQueryEquals(String expectedQueryPart, String input) { 25 final String query = OverpassTurboQueryWizard.getInstance().constructQuery(input); 26 assertEquals("" + 27 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 28 "(\n" + 29 expectedQueryPart + 30 ");\n" + 31 "(._;>;);\n" + 32 "out meta;", query); 33 } 34 24 35 /** 25 36 * Test {@code key=value}. … … 27 38 @Test 28 39 public void testKeyValue() { 29 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("amenity=drinking_water"); 30 assertEquals("" + 31 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 32 "(\n" + 33 " nwr[\"amenity\"=\"drinking_water\"];\n" + 34 ");\n" + 35 "(._;>;);\n" + 36 "out meta;", query); 37 } 38 39 /** 40 * Test {@code key!=value}. 40 assertQueryEquals(" nwr[\"amenity\"=\"drinking_water\"];\n", "amenity=drinking_water"); 41 } 42 43 /** 44 * Test {@code key!=value} and {@code key<>value}. 41 45 */ 42 46 @Test 43 47 public void testKeyNotValue() { 44 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("amenity!=drinking_water"); 45 assertEquals("" + 46 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 47 "(\n" + 48 " nwr[\"amenity\"!=\"drinking_water\"];\n" + 49 ");\n" + 50 "(._;>;);\n" + 51 "out meta;", query); 48 assertQueryEquals(" nwr[\"amenity\"!=\"drinking_water\"];\n", "amenity!=drinking_water"); 49 assertQueryEquals(" nwr[\"amenity\"!=\"drinking_water\"];\n", "amenity<>drinking_water"); 50 } 51 52 /** 53 * Test {@code key~value} and similar. 54 */ 55 @Test 56 public void testKeyLikeValue() { 57 assertQueryEquals(" nwr[\"foo\"~\"bar\"];\n", "foo~bar"); 58 assertQueryEquals(" nwr[\"foo\"~\"bar\"];\n", "foo~/bar/"); 59 assertQueryEquals(" nwr[\"foo\"~\"bar\"];\n", "foo~=bar"); 60 assertQueryEquals(" nwr[\"foo\"~\"bar\"];\n", "foo~=/bar/"); 61 assertQueryEquals(" nwr[\"foo\"~\"bar\"];\n", "foo like bar"); 62 assertQueryEquals(" nwr[\"foo\"~\"bar\"];\n", "foo like /bar/"); 63 // case insensitive 64 assertQueryEquals(" nwr[\"foo\"~\"bar\",i];\n", "foo~/bar/i"); 65 // negated 66 assertQueryEquals(" nwr[\"foo\"!~\"bar\"];\n", "foo!~bar"); 67 assertQueryEquals(" nwr[\"foo\"!~\"bar\"];\n", "foo not like bar"); 52 68 } 53 69 … … 57 73 @Test 58 74 public void testBooleanAnd() { 59 final String expected = "" + 60 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 61 "(\n" + 62 " nwr[\"foo\"=\"bar\"][\"baz\"=\"42\"];\n" + 63 ");\n" + 64 "(._;>;);\n" + 65 "out meta;"; 66 assertEquals(expected, OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar and baz=42")); 67 assertEquals(expected, OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar && baz=42")); 68 assertEquals(expected, OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar & baz=42")); 75 assertQueryEquals(" nwr[\"foo\"=\"bar\"][\"baz\"=\"42\"];\n", "foo=bar and baz=42"); 76 assertQueryEquals(" nwr[\"foo\"=\"bar\"][\"baz\"=\"42\"];\n", "foo=bar && baz=42"); 77 assertQueryEquals(" nwr[\"foo\"=\"bar\"][\"baz\"=\"42\"];\n", "foo=bar & baz=42"); 69 78 } 70 79 … … 74 83 @Test 75 84 public void testBooleanOr() { 76 final String expected = "" + 77 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 85 assertQueryEquals(" nwr[\"foo\"=\"bar\"];\n nwr[\"baz\"=\"42\"];\n", "foo=bar or baz=42"); 86 assertQueryEquals(" nwr[\"foo\"=\"bar\"];\n nwr[\"baz\"=\"42\"];\n", "foo=bar || baz=42"); 87 assertQueryEquals(" nwr[\"foo\"=\"bar\"];\n nwr[\"baz\"=\"42\"];\n", "foo=bar | baz=42"); 88 } 89 90 /** 91 * Test {@code (foo=* or bar=*) and (asd=* or fasd=*)}. 92 */ 93 @Test 94 public void testBoolean() { 95 assertQueryEquals("" + 96 " nwr[\"foo\"][\"baz1\"];\n" + 97 " nwr[\"foo\"][\"baz2\"];\n" + 98 " nwr[\"foo\"][\"baz3\"][\"baz4\"];\n" + 99 " nwr[\"foo\"][\"baz3\"][\"baz5\"];\n" + 100 " nwr[\"bar\"][\"baz1\"];\n" + 101 " nwr[\"bar\"][\"baz2\"];\n" + 102 " nwr[\"bar\"][\"baz3\"][\"baz4\"];\n" + 103 " nwr[\"bar\"][\"baz3\"][\"baz5\"];\n", 104 "(foo=* or bar=*) and (baz1=* or baz2=* or (baz3=* and (baz4=* or baz5=*)))"); 105 } 106 107 /** 108 * Test {@code foo=bar and (type:node or type:way)}. 109 */ 110 @Test 111 public void testType() { 112 assertQueryEquals(" node[\"foo\"=\"bar\"];\n way[\"foo\"=\"bar\"];\n", "foo=bar and (type:node or type:way)"); 113 } 114 115 /** 116 * Test {@code user:foo or uid:42}. 117 */ 118 @Test 119 public void testUser() { 120 assertQueryEquals(" nwr(user:\"foo\");\n nwr(uid:42);\n", "user:foo or uid:42"); 121 } 122 123 /** 124 * Test {@code foo=bar and (type:node or type:way)}. 125 */ 126 @Test 127 public void testEmpty() { 128 assertQueryEquals(" way[\"foo\"~\"^$\"];\n", "foo='' and type:way"); 129 } 130 131 /** 132 * Test geocodeArea. 133 */ 134 @Test 135 public void testInArea() { 136 String query = OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar | foo=baz in Innsbruck"); 137 assertEquals("" + 138 "[out:xml][timeout:90];\n" + 139 "{{geocodeArea:Innsbruck}}->.searchArea;\n" + 140 "(\n" + 141 " nwr[\"foo\"=\"bar\"](area.searchArea);\n" + 142 " nwr[\"foo\"=\"baz\"](area.searchArea);\n" + 143 ");\n" + 144 "(._;>;);\n" + 145 "out meta;", query); 146 query = OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar | foo=baz in \"Sankt Sigmund im Sellrain\""); 147 assertEquals("" + 148 "[out:xml][timeout:90];\n" + 149 "{{geocodeArea:Sankt Sigmund im Sellrain}}->.searchArea;\n" + 150 "(\n" + 151 " nwr[\"foo\"=\"bar\"](area.searchArea);\n" + 152 " nwr[\"foo\"=\"baz\"](area.searchArea);\n" + 153 ");\n" + 154 "(._;>;);\n" + 155 "out meta;", query); 156 query = OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar | foo=baz in \"Новосибирск\""); 157 assertEquals("" + 158 "[out:xml][timeout:90];\n" + 159 "{{geocodeArea:Новосибирск}}->.searchArea;\n" + 160 "(\n" + 161 " nwr[\"foo\"=\"bar\"](area.searchArea);\n" + 162 " nwr[\"foo\"=\"baz\"](area.searchArea);\n" + 163 ");\n" + 164 "(._;>;);\n" + 165 "out meta;", query); 166 } 167 168 /** 169 * Test geocodeArea. 170 */ 171 @Test 172 public void testAroundArea() { 173 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar | foo=baz around \"Sankt Sigmund im Sellrain\""); 174 assertEquals("" + 175 "[out:xml][timeout:90];\n" + 176 "{{radius=1000}}\n" + 177 "(\n" + 178 " nwr[\"foo\"=\"bar\"](around:{{radius}},{{geocodeCoords:Sankt Sigmund im Sellrain}});\n" + 179 " nwr[\"foo\"=\"baz\"](around:{{radius}},{{geocodeCoords:Sankt Sigmund im Sellrain}});\n" + 180 ");\n" + 181 "(._;>;);\n" + 182 "out meta;", query); 183 } 184 185 /** 186 * Test global query. 187 */ 188 @Test 189 public void testGlobal() { 190 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar global"); 191 assertEquals("" + 192 "[out:xml][timeout:90];\n" + 78 193 "(\n" + 79 194 " nwr[\"foo\"=\"bar\"];\n" + 80 " nwr[\"baz\"=\"42\"];\n" + 81 ");\n" + 82 "(._;>;);\n" + 83 "out meta;"; 84 assertEquals(expected, OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar or baz=42")); 85 assertEquals(expected, OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar || baz=42")); 86 assertEquals(expected, OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar | baz=42")); 87 } 88 89 /** 90 * Test {@code (foo=* or bar=*) and (asd=* or fasd=*)}. 91 */ 92 @Test 93 public void testBoolean() { 94 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("(foo=* or bar=*) and (asd=* or fasd=*)"); 95 assertEquals("" + 96 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 97 "(\n" + 98 " nwr[\"foo\"][\"asd\"];\n" + 99 " nwr[\"foo\"][\"fasd\"];\n" + 100 " nwr[\"bar\"][\"asd\"];\n" + 101 " nwr[\"bar\"][\"fasd\"];\n" + 102 ");\n" + 103 "(._;>;);\n" + 104 "out meta;", query); 105 } 106 107 /** 108 * Test {@code foo=bar and (type:node or type:way)}. 109 */ 110 @Test 111 public void testType() { 112 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar and (type:node or type:way)"); 113 assertEquals("" + 114 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 115 "(\n" + 116 " node[\"foo\"=\"bar\"];\n" + 117 " way[\"foo\"=\"bar\"];\n" + 118 ");\n" + 119 "(._;>;);\n" + 120 "out meta;", query); 121 } 122 123 /** 124 * Test {@code user:foo or uid:42}. 125 */ 126 @Test 127 public void testUser() { 128 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("user:foo or uid:42"); 129 assertEquals("" + 130 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 131 "(\n" + 132 " nwr(user:\"foo\");\n" + 133 " nwr(uid:42);\n" + 134 ");\n" + 135 "(._;>;);\n" + 136 "out meta;", query); 137 } 138 139 /** 140 * Test {@code foo=bar and (type:node or type:way)}. 141 */ 142 @Test 143 public void testEmpty() { 144 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("foo='' and type:way"); 145 assertEquals("" + 146 "[out:xml][timeout:90][bbox:{{bbox}}];\n" + 147 "(\n" + 148 " way[\"foo\"~\"^$\"];\n" + 149 ");\n" + 150 "(._;>;);\n" + 151 "out meta;", query); 152 } 153 154 /** 155 * Test geocodeArea. 156 */ 157 @Test 158 public void testInArea() { 159 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("foo=bar in Josmland"); 160 assertEquals("" + 161 "[out:xml][timeout:90];\n" + 162 "{{geocodeArea:Josmland}}->.searchArea;\n" + 163 "(\n" + 164 " nwr[\"foo\"=\"bar\"](area.searchArea);\n" + 165 ");\n" + 166 "(._;>;);\n" + 167 "out meta;", query); 195 ");\n" + 196 "(._;>;);\n" + 197 "out meta;", query); 198 } 199 200 /** 201 * Test "in bbox" query. 202 */ 203 @Test 204 public void testInBbox() { 205 assertQueryEquals(" nwr[\"foo\"=\"bar\"];\n", "foo=bar IN BBOX"); 168 206 } 169 207 … … 174 212 @Ignore("preset handling not implemented") 175 213 public void testPreset() { 176 final String query = OverpassTurboQueryWizard.getInstance().constructQuery("Hospital"); 177 assertEquals("" + 178 "[out:xml][timeout:90];\n" + 179 "(\n" + 180 " nwr[\"amenity\"=\"hospital\"];\n" + 181 ");\n" + 182 "(._;>;);\n" + 183 "out meta;", query); 214 assertQueryEquals(" nwr[\"amenity\"=\"hospital\"];\n", "Hospital"); 184 215 } 185 216
Note:
See TracChangeset
for help on using the changeset viewer.