use of com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler in project ph-css by phax.
the class Issue9Test method testIssue9.
@Test
public void testIssue9() {
// File starts (and ends) with an invalid comment
final IReadableResource aRes = new ClassPathResource("testfiles/css30/bad/issue9.css");
assertTrue(aRes.exists());
final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, StandardCharsets.UTF_8, ECSSVersion.CSS30, new LoggingCSSParseErrorHandler());
assertNull(aCSS);
}
use of com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler in project ph-css by phax.
the class IssueGC22Test method testIssue22.
@Test
public void testIssue22() {
final IReadableResource aRes = new ClassPathResource("testfiles/css30/good/issue-gc-22.css");
assertTrue(aRes.exists());
final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, StandardCharsets.UTF_8, ECSSVersion.CSS30, new LoggingCSSParseErrorHandler());
assertNotNull(aCSS);
if (false)
System.out.println(new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS));
}
use of com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler in project ph-css by phax.
the class Issue22Test method testIssue.
@Test
public void testIssue() {
// Multiple errors contained
final IReadableResource aRes = new ClassPathResource("testfiles/css30/good/issue22.css");
assertTrue(aRes.exists());
final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setCustomErrorHandler(new LoggingCSSParseErrorHandler()));
assertNotNull(aCSS);
if (false)
System.out.println(new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS));
}
use of com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler in project ph-css by phax.
the class Issue26Test method testIssue.
@Test
public void testIssue() {
final IReadableResource aRes = new ClassPathResource("testfiles/css30/bad_but_browsercompliant/issue26.css");
assertTrue(aRes.exists());
final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setBrowserCompliantMode(true).setCustomErrorHandler(new LoggingCSSParseErrorHandler()));
assertNotNull(aCSS);
if (false)
System.out.println(new CSSWriter().getCSSAsString(aCSS));
}
use of com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler in project ph-css by phax.
the class AbstractFuncTestCSSReader method testReadBadButRecoverable.
protected final void testReadBadButRecoverable(@Nonnull final String sBaseDir) {
final File aBaseDir = new File(sBaseDir);
if (!aBaseDir.exists())
throw new IllegalArgumentException("BaseDir " + sBaseDir + " does not exist!");
for (final File aFile : new FileSystemRecursiveIterator(aBaseDir).withFilter(IFileFilter.filenameEndsWith(".css"))) {
final String sKey = aFile.getAbsolutePath();
if (m_bDebug)
m_aLogger.info(sKey);
// Handle each error as a fatal error!
final CollectingCSSParseErrorHandler aErrorHdl = new CollectingCSSParseErrorHandler();
m_aReaderSettings.setCustomErrorHandler(aErrorHdl.and(new LoggingCSSParseErrorHandler()));
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, m_aReaderSettings);
assertNotNull(sKey, aCSS);
assertTrue(sKey, aErrorHdl.hasParseErrors());
assertTrue(sKey, aErrorHdl.getParseErrorCount() > 0);
if (m_bDebug)
m_aLogger.info(aErrorHdl.getAllParseErrors().toString());
// Write optimized version and re-read it
final String sCSS = new CSSWriter(m_aWriterSettings.setOptimizedOutput(true)).getCSSAsString(aCSS);
assertNotNull(sKey, sCSS);
if (m_bDebug)
m_aLogger.info(sCSS);
final CascadingStyleSheet aCSSReRead = CSSReader.readFromStringReader(sCSS, m_aReaderSettings);
assertNotNull("Failed to parse:\n" + sCSS, aCSSReRead);
assertEquals(sKey, aCSS, aCSSReRead);
}
}
Aggregations