Changeset 8331 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r8318 r8331 8 8 import java.io.InputStream; 9 9 import java.io.Reader; 10 import java.io.StringReader; 10 11 import java.text.MessageFormat; 11 12 import java.util.ArrayList; … … 317 318 static List<TagCheck> readMapCSS(Reader css) throws ParseException { 318 319 CheckParameterUtil.ensureParameterNotNull(css, "css"); 319 return readMapCSS(new MapCSSParser(css)); 320 } 321 322 static List<TagCheck> readMapCSS(MapCSSParser css) throws ParseException { 323 CheckParameterUtil.ensureParameterNotNull(css, "css"); 320 324 321 final MapCSSStyleSource source = new MapCSSStyleSource(""); 325 css.sheet(source); 322 final MapCSSParser preprocessor = new MapCSSParser(css, MapCSSParser.LexicalState.PREPROCESSOR); 323 324 css = new StringReader(preprocessor.pp_root(source)); 325 final MapCSSParser parser = new MapCSSParser(css, MapCSSParser.LexicalState.DEFAULT); 326 parser.sheet(source); 326 327 assert source.getErrors().isEmpty(); 327 328 // Ignore "meta" rule(s) from external rules of JOSM wiki -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r8260 r8331 9 9 10 10 import java.io.InputStream; 11 import java.io.Reader; 11 12 import java.util.ArrayList; 12 13 import java.util.Arrays; … … 87 88 throw new RuntimeException(e); 88 89 } 90 return new MapCSSParserTokenManager(scs, initState.idx); 91 } 92 93 /** 94 * Constructor which initializes the parser with a certain lexical state. 95 */ 96 public MapCSSParser(Reader in, LexicalState initState) { 97 this(createTokenManager(in, initState)); 98 declarationCounter = 0; 99 } 100 101 protected static MapCSSParserTokenManager createTokenManager(Reader in, LexicalState initState) { 102 final SimpleCharStream scs = new SimpleCharStream(in, 1, 1); 89 103 return new MapCSSParserTokenManager(scs, initState.idx); 90 104 } -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
r8266 r8331 118 118 119 119 @Test 120 public void testPreprocessing() throws Exception { 121 final MapCSSTagChecker test = buildTagChecker("" + 122 "@media (min-josm-version: 1) { *[foo] { throwWarning: \"!\"; } }\n" + 123 "@media (min-josm-version: 2147483647) { *[bar] { throwWarning: \"!\"; } }\n"); 124 assertThat(test.getErrorsForPrimitive(OsmUtils.createPrimitive("way foo=1"), false).size(), is(1)); 125 assertThat(test.getErrorsForPrimitive(OsmUtils.createPrimitive("way bar=1"), false).size(), is(0)); 126 } 127 128 @Test 120 129 public void testInit() throws Exception { 121 130 MapCSSTagChecker c = new MapCSSTagChecker();
Note:
See TracChangeset
for help on using the changeset viewer.