use of com.helger.css.writer.CSSWriter in project ph-css by phax.
the class AbstractFuncTestCSSReader method testReadGood.
protected final void testReadGood(@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("Filename: " + sKey);
final CollectingCSSParseErrorHandler aErrorHdl = new CollectingCSSParseErrorHandler();
m_aReaderSettings.setCustomErrorHandler(aErrorHdl.and(new LoggingCSSParseErrorHandler()));
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, m_aReaderSettings);
assertNotNull(sKey, aCSS);
// May have errors or not
if (m_bDebug)
m_aLogger.info("Parse errors: " + aErrorHdl.getAllParseErrors().toString());
CommonsTestHelper.testDefaultSerialization(aCSS);
// Write optimized version and compare it
String sCSS = new CSSWriter(m_aWriterSettings.setOptimizedOutput(true)).getCSSAsString(aCSS);
assertNotNull(sKey, sCSS);
if (m_bDebug)
m_aLogger.info("Created CSS: " + sCSS);
final CascadingStyleSheet aCSSReRead = CSSReader.readFromStringReader(sCSS, m_aReaderSettings);
assertNotNull("Failed to parse " + sKey + ":\n" + sCSS, aCSSReRead);
assertEquals(sKey + "\n" + sCSS, aCSS, aCSSReRead);
// Write non-optimized version and compare it
sCSS = new CSSWriter(m_aWriterSettings.setOptimizedOutput(false)).getCSSAsString(aCSS);
assertNotNull(sKey, sCSS);
if (m_bDebug)
m_aLogger.info("Read and re-created CSS: " + sCSS);
assertEquals(sKey, aCSS, CSSReader.readFromStringReader(sCSS, m_aReaderSettings));
// Write non-optimized and code-removed version and ensure it is not
// null
sCSS = new CSSWriter(m_aWriterSettings.setOptimizedOutput(false).setRemoveUnnecessaryCode(true)).getCSSAsString(aCSS);
assertNotNull(sKey, sCSS);
assertNotNull(sKey, CSSReader.readFromStringReader(sCSS, m_aReaderSettings));
// Restore value :)
m_aWriterSettings.setRemoveUnnecessaryCode(false);
}
}
use of com.helger.css.writer.CSSWriter in project ph-css by phax.
the class CSSReader30SpecialFuncTest method testReadSpecialGood.
@Test
public void testReadSpecialGood() {
final ECSSVersion eVersion = ECSSVersion.CSS30;
final Charset aCharset = StandardCharsets.UTF_8;
final File aFile = new File("src/test/resources/testfiles/css30/good/artificial/test-postcss-cssnext.css");
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, aCharset, eVersion);
assertNotNull(aCSS);
final String sCSS = new CSSWriter(eVersion, false).getCSSAsString(aCSS);
assertNotNull(sCSS);
if (false)
s_aLogger.info(sCSS);
}
use of com.helger.css.writer.CSSWriter in project ph-css by phax.
the class Issue24Test method testIssue.
@Test
public void testIssue() {
final IReadableResource aRes = new ClassPathResource("testfiles/css30/bad_but_browsercompliant/issue24.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.writer.CSSWriter in project ph-css by phax.
the class Issue4Test method testIssue4.
@Test
public void testIssue4() {
final IReadableResource aRes = new ClassPathResource("testfiles/css30/good/issue4.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.writer.CSSWriter in project ph-css by phax.
the class ECSSColorTest method testAll.
@Test
public void testAll() {
final CSSWriter aWriter = new CSSWriter(ECSSVersion.CSS30);
for (final ECSSColor eColor : ECSSColor.values()) {
assertTrue(StringHelper.hasText(eColor.getName()));
assertTrue(CSSColorHelper.isColorValue(eColor.getName()));
final String sHex = eColor.getAsHexColorValue();
assertTrue(sHex, CSSColorHelper.isHexColorValue(sHex));
final String sRGB = eColor.getAsRGBColorValue();
assertTrue(sRGB, CSSColorHelper.isRGBColorValue(sRGB));
assertNotNull(eColor.getAsRGB());
assertEquals(sRGB, aWriter.getCSSAsString(eColor.getAsRGB()));
final String sRGBA = eColor.getAsRGBAColorValue(1f);
assertTrue(sRGBA, CSSColorHelper.isRGBAColorValue(sRGBA));
assertNotNull(eColor.getAsRGBA(1));
assertEquals(sRGBA, aWriter.getCSSAsString(eColor.getAsRGBA(1)));
final String sHSL = eColor.getAsHSLColorValue();
assertTrue(sHSL, CSSColorHelper.isHSLColorValue(sHSL));
assertNotNull(eColor.getAsHSL());
assertEquals(sHSL, aWriter.getCSSAsString(eColor.getAsHSL()));
final String sHSLA = eColor.getAsHSLAColorValue(1f);
assertTrue(sHSLA, CSSColorHelper.isHSLAColorValue(sHSLA));
assertNotNull(eColor.getAsHSLA(1));
assertEquals(sHSLA, aWriter.getCSSAsString(eColor.getAsHSLA(1)));
assertSame(eColor, ECSSColor.getFromNameCaseInsensitiveOrNull(eColor.getName()));
assertTrue(ECSSColor.isDefaultColorName(eColor.getName()));
}
}
Aggregations