Changeset 4546 in josm for trunk/test/unit/org
- Timestamp:
- 2011-10-29T09:01:30+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/tools/template_engine/TemplateEngineTest.java
r4431 r4546 13 13 import org.openstreetmap.josm.actions.search.SearchCompiler.Match; 14 14 import org.openstreetmap.josm.data.Preferences; 15 import org.openstreetmap.josm.data.osm.DatasetFactory; 16 import org.openstreetmap.josm.data.osm.Node; 15 17 import org.openstreetmap.josm.data.osm.Relation; 18 import org.openstreetmap.josm.data.osm.RelationMember; 16 19 import org.unitils.reflectionassert.ReflectionAssert; 17 20 … … 150 153 templateEntry.appendText(sb, dataProvider); 151 154 Assert.assertEquals("waypointNameulocalNameuspecialKey", sb.toString()); 152 153 } 154 155 } 156 157 @Test 158 public void testSearchExpression() throws Exception { 159 Match match = compile("(parent type=type1 type=parent1) | (parent type=type2 type=parent2)"); 160 //"parent(type=type1,type=parent1) | (parent(type=type2,type=parent2)" 161 //TODO 162 } 163 164 @Test 165 public void testSwitchContext() throws Exception { 166 TemplateParser parser = new TemplateParser("!{parent() type=parent2 '{name}'}"); 167 DatasetFactory ds = new DatasetFactory(); 168 Relation parent1 = ds.addRelation(1); 169 parent1.put("type", "parent1"); 170 parent1.put("name", "name_parent1"); 171 Relation parent2 = ds.addRelation(2); 172 parent2.put("type", "parent2"); 173 parent2.put("name", "name_parent2"); 174 Node child = ds.addNode(1); 175 parent1.addMember(new RelationMember("", child)); 176 parent2.addMember(new RelationMember("", child)); 177 178 StringBuilder sb = new StringBuilder(); 179 TemplateEntry entry = parser.parse(); 180 entry.appendText(sb, child); 181 182 Assert.assertEquals("name_parent2", sb.toString()); 183 } 184 185 @Test 186 public void testSetOr() throws ParseError { 187 TemplateParser parser = new TemplateParser("!{(parent(type=type1) type=parent1) | (parent type=type2 type=parent2) '{name}'}"); 188 DatasetFactory ds = new DatasetFactory(); 189 Relation parent1 = ds.addRelation(1); 190 parent1.put("type", "parent1"); 191 parent1.put("name", "name_parent1"); 192 Relation parent2 = ds.addRelation(2); 193 parent2.put("type", "parent2"); 194 parent2.put("name", "name_parent2"); 195 Node child1 = ds.addNode(1); 196 child1.put("type", "type1"); 197 parent1.addMember(new RelationMember("", child1)); 198 parent2.addMember(new RelationMember("", child1)); 199 Node child2 = ds.addNode(2); 200 child2.put("type", "type2"); 201 parent1.addMember(new RelationMember("", child2)); 202 parent2.addMember(new RelationMember("", child2)); 203 204 205 StringBuilder sb = new StringBuilder(); 206 TemplateEntry entry = parser.parse(); 207 entry.appendText(sb, child1); 208 entry.appendText(sb, child2); 209 210 Assert.assertEquals("name_parent1name_parent2", sb.toString()); 211 } 212 213 @Test 214 public void testMultilevel() throws ParseError { 215 TemplateParser parser = new TemplateParser("!{(parent(parent(type=type1)) type=grandparent) | (parent type=type2 type=parent2) '{name}'}"); 216 DatasetFactory ds = new DatasetFactory(); 217 Relation parent1 = ds.addRelation(1); 218 parent1.put("type", "parent1"); 219 parent1.put("name", "name_parent1"); 220 Relation parent2 = ds.addRelation(2); 221 parent2.put("type", "parent2"); 222 parent2.put("name", "name_parent2"); 223 Node child1 = ds.addNode(1); 224 child1.put("type", "type1"); 225 parent1.addMember(new RelationMember("", child1)); 226 parent2.addMember(new RelationMember("", child1)); 227 Node child2 = ds.addNode(2); 228 child2.put("type", "type2"); 229 parent1.addMember(new RelationMember("", child2)); 230 parent2.addMember(new RelationMember("", child2)); 231 Relation grandParent = ds.addRelation(3); 232 grandParent.put("type", "grandparent"); 233 grandParent.put("name", "grandparent_name"); 234 grandParent.addMember(new RelationMember("", parent1)); 235 236 237 StringBuilder sb = new StringBuilder(); 238 TemplateEntry entry = parser.parse(); 239 entry.appendText(sb, child1); 240 entry.appendText(sb, child2); 241 242 Assert.assertEquals("grandparent_namename_parent2", sb.toString()); 243 } 244 245 @Test(expected=ParseError.class) 246 public void testErrorsNot() throws ParseError { 247 TemplateParser parser = new TemplateParser("!{-parent() '{name}'}"); 248 parser.parse(); 249 } 250 251 @Test(expected=ParseError.class) 252 public void testErrorOr() throws ParseError { 253 TemplateParser parser = new TemplateParser("!{parent() | type=type1 '{name}'}"); 254 parser.parse(); 255 } 256 257 @Test 258 public void testChild() throws ParseError { 259 TemplateParser parser = new TemplateParser("!{((child(type=type1) type=child1) | (child type=type2 type=child2)) type=child2 '{name}'}"); 260 DatasetFactory ds = new DatasetFactory(); 261 Relation parent1 = ds.addRelation(1); 262 parent1.put("type", "type1"); 263 Relation parent2 = ds.addRelation(2); 264 parent2.put("type", "type2"); 265 Node child1 = ds.addNode(1); 266 child1.put("type", "child1"); 267 child1.put("name", "child1"); 268 parent1.addMember(new RelationMember("", child1)); 269 parent2.addMember(new RelationMember("", child1)); 270 Node child2 = ds.addNode(2); 271 child2.put("type", "child2"); 272 child2.put("name", "child2"); 273 parent1.addMember(new RelationMember("", child2)); 274 parent2.addMember(new RelationMember("", child2)); 275 276 277 StringBuilder sb = new StringBuilder(); 278 TemplateEntry entry = parser.parse(); 279 entry.appendText(sb, parent2); 280 281 Assert.assertEquals("child2", sb.toString()); 282 } 155 283 156 284 }
Note:
See TracChangeset
for help on using the changeset viewer.