Changeset 4431 in josm for trunk/test/unit/org/openstreetmap/josm/tools
- Timestamp:
- 2011-09-17T10:59:32+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/tools/template_engine/TemplateEngineTest.java
r4282 r4431 7 7 8 8 import org.junit.Assert; 9 import org.junit.BeforeClass; 9 10 import org.junit.Test; 11 import org.openstreetmap.josm.Main; 10 12 import org.openstreetmap.josm.actions.search.SearchCompiler; 11 13 import org.openstreetmap.josm.actions.search.SearchCompiler.Match; 14 import org.openstreetmap.josm.data.Preferences; 15 import org.openstreetmap.josm.data.osm.Relation; 12 16 import org.unitils.reflectionassert.ReflectionAssert; 13 17 14 18 public class TemplateEngineTest { 19 20 @BeforeClass 21 public static void before() { 22 Main.pref = new Preferences(); 23 } 15 24 16 25 @Test … … 62 71 TemplateEngineDataProvider dataProvider = new TemplateEngineDataProvider() { 63 72 @Override 64 public Object getTemplateValue(String name) { 65 if ("name".equals(name)) 66 return "waypointName"; 67 else if ("number".equals(name)) 68 return 10; 69 else 70 return null; 73 public Object getTemplateValue(String name, boolean special) { 74 if (special) { 75 if ("localName".equals(name)) 76 return "localName"; 77 else 78 return null; 79 } else { 80 if ("name".equals(name)) 81 return "waypointName"; 82 else if ("number".equals(name)) 83 return 10; 84 else if ("special:key".equals(name)) 85 return "specialKey"; 86 else 87 return null; 88 } 71 89 } 72 90 @Override … … 90 108 91 109 @Test 110 public void testFillingSearchExpression() throws Exception { 111 TemplateParser parser = new TemplateParser("?{ admin_level = 2 'NUTS 1' | admin_level = 4 'NUTS 2' | '{admin_level}'}"); 112 TemplateEntry templateEntry = parser.parse(); 113 114 StringBuilder sb = new StringBuilder(); 115 Relation r = new Relation(); 116 r.put("admin_level", "2"); 117 templateEntry.appendText(sb, r); 118 Assert.assertEquals("NUTS 1", sb.toString()); 119 120 sb.setLength(0); 121 r.put("admin_level", "5"); 122 templateEntry.appendText(sb, r); 123 Assert.assertEquals("5", sb.toString()); 124 } 125 126 @Test 92 127 public void testPrintAll() throws Exception { 93 TemplateParser parser = new TemplateParser("{ *}");128 TemplateParser parser = new TemplateParser("{special:everything}"); 94 129 TemplateEntry entry = parser.parse(); 95 130 StringBuilder sb = new StringBuilder(); … … 107 142 } 108 143 144 @Test 145 public void testSpecialVariable() throws Exception { 146 TemplateParser parser = new TemplateParser("{name}u{special:localName}u{special:special:key}"); 147 TemplateEntry templateEntry = parser.parse(); 148 149 StringBuilder sb = new StringBuilder(); 150 templateEntry.appendText(sb, dataProvider); 151 Assert.assertEquals("waypointNameulocalNameuspecialKey", sb.toString()); 152 153 } 154 109 155 110 156 }
Note:
See TracChangeset
for help on using the changeset viewer.