use of com.helger.css.writer.CSSWriter in project ph-css by phax.
the class CSSReader21SpecialFuncTest 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/css21/good/artificial/test-url.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 CSSReader30FuncTest method testSpecialCasesAsString.
@Test
public void testSpecialCasesAsString() {
final boolean bBrowserCompliantMode = isBrowserCompliantMode();
final CSSReaderSettings aSettings = new CSSReaderSettings().setCSSVersion(ECSSVersion.CSS30).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setBrowserCompliantMode(bBrowserCompliantMode);
// Parsing problem
String sCSS = ".class{color:red;.class{color:green}.class{color:blue}";
CascadingStyleSheet aCSS;
CascadingStyleSheet aCSS2;
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNotNull(aCSS);
assertEquals(bBrowserCompliantMode ? "" : ".class{color:red}.class{color:blue}", new CSSWriter(ECSSVersion.CSS30, true).getCSSAsString(aCSS));
sCSS = " \n/* comment */\n \n.class{color:red;}";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNotNull(aCSS);
assertEquals(".class{color:red}", new CSSWriter(ECSSVersion.CSS30, true).getCSSAsString(aCSS));
// With Umlauts
sCSS = "div { colör: räd; }";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNotNull(aCSS);
assertEquals("div{colör:räd}", new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(true)).getCSSAsString(aCSS));
aCSS2 = CSSReader.readFromStringReader(sCSS, aSettings);
assertNotNull(aCSS2);
assertEquals("div{colör:räd}", new CSSWriter(ECSSVersion.CSS30, true).getCSSAsString(aCSS2));
assertEquals(aCSS, aCSS2);
// With masking
sCSS = "#mask\\26{ color: red; }";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNotNull(aCSS);
assertEquals("#mask\\26{color:red}", new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(true)).getCSSAsString(aCSS));
sCSS = "#mask\\26 { color: red; }";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNotNull(aCSS);
assertEquals("#mask\\26 {color:red}", new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(true)).getCSSAsString(aCSS));
sCSS = "#mask\\26 { color: red; }";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNotNull(aCSS);
assertEquals("#mask\\26 {color:red}", new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(true)).getCSSAsString(aCSS));
// With masking
sCSS = "#mask\\x{ color: red; }";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNotNull(aCSS);
assertEquals("#mask\\x{color:red}", new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(true)).getCSSAsString(aCSS));
sCSS = "#mask\\x { color: red; }";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNotNull(aCSS);
assertEquals("#mask\\x{color:red}", new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(true)).getCSSAsString(aCSS));
sCSS = "#mask\\x { color: red; }";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNotNull(aCSS);
assertEquals("#mask\\x{color:red}", new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(true)).getCSSAsString(aCSS));
// With charset rule defined
sCSS = "@charset \"iso-8859-1\"; div{color:red ; }";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNotNull(aCSS);
assertEquals("div{color:red}", new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(true)).getCSSAsString(aCSS));
// Invalid identifier 1
sCSS = "-0{color:red;}";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNull(aCSS);
// Invalid identifier 2
sCSS = "$0{color:red;}";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNull(aCSS);
// Invalid identifier 3
sCSS = "*0{color:red;}";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
if (bBrowserCompliantMode) {
assertNotNull(aCSS);
assertEquals(1, aCSS.getRuleCount());
} else
assertNull(aCSS);
// Valid version of previous variant
sCSS = "*abc{color:red;}";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNotNull(aCSS);
assertEquals("*abc{color:red}", new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(true)).getCSSAsString(aCSS));
// Invalid identifier 4
sCSS = "0{color:red;}";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNull(aCSS);
// Invalid identifier 5
sCSS = "--{color:red;}";
aCSS = CSSReader.readFromStringReader(sCSS, aSettings);
assertNull(aCSS);
}
use of com.helger.css.writer.CSSWriter in project ph-css by phax.
the class Issue19Test method testIssue.
@Test
public void testIssue() {
// Multiple errors contained
final IReadableResource aRes = new ClassPathResource("testfiles/css30/bad_but_browsercompliant/issue19.css");
assertTrue(aRes.exists());
final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setCSSVersion(ECSSVersion.CSS30).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setBrowserCompliantMode(true));
assertNotNull(aCSS);
if (false)
System.out.println(new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS));
assertEquals(1, aCSS.getRuleCount());
assertEquals(1, aCSS.getStyleRuleCount());
}
use of com.helger.css.writer.CSSWriter in project ph-css by phax.
the class Issue34Test method testIssue.
@Test
@Ignore("TODO")
public void testIssue() {
final String css = ".pen {background-color:red} {* some incorrect block *} .pen {background-color: blue}";
final CSSReaderSettings aSettings = new CSSReaderSettings().setCSSVersion(ECSSVersion.LATEST).setBrowserCompliantMode(true).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setCustomExceptionHandler(new LoggingCSSParseExceptionCallback());
final CascadingStyleSheet cascadingStyleSheet = CSSReader.readFromStringStream(css, aSettings);
assertNotNull(cascadingStyleSheet);
final CSSWriter writer = new CSSWriter(new CSSWriterSettings(ECSSVersion.LATEST, true));
s_aLogger.info(writer.getCSSAsString(cascadingStyleSheet));
}
use of com.helger.css.writer.CSSWriter in project ph-css by phax.
the class Issue36Test method testIssue.
@Test
public void testIssue() {
final String css = "@media screen and (min-width: 768px) {.section {.\r\n" + " padding: 40px\r\n" + "}\r\n" + "\r\n" + "}";
final CSSReaderSettings aSettings = new CSSReaderSettings().setCSSVersion(ECSSVersion.LATEST).setBrowserCompliantMode(true).setCustomErrorHandler(new DoNothingCSSParseErrorHandler());
final CascadingStyleSheet cascadingStyleSheet = CSSReader.readFromStringStream(css, aSettings);
final CSSWriter writer = new CSSWriter(new CSSWriterSettings(ECSSVersion.LATEST, true));
assertEquals("@media screen and (min-width:768px){.section{}}", writer.getCSSAsString(cascadingStyleSheet));
}
Aggregations