use of com.helger.css.decl.CSSDeclarationList in project ph-css by phax.
the class CSSReaderDeclarationListTest method testRead21.
@Test
public void testRead21() {
final ICSSParseExceptionCallback aHdl = new DoNothingCSSParseExceptionCallback();
for (final String sCSS : VALID) {
final CSSDeclarationList aDL = CSSReaderDeclarationList.readFromString(sCSS, ECSSVersion.CSS30, aHdl);
assertNotNull(aDL);
}
for (final String sCSS : INVALID) assertNull(sCSS, CSSReaderDeclarationList.readFromString(sCSS, ECSSVersion.CSS30, aHdl));
}
use of com.helger.css.decl.CSSDeclarationList in project ph-css by phax.
the class WikiReadFromHtml method readFromStyleAttribute.
public static CSSDeclarationList readFromStyleAttribute() {
final String sStyle = "color:red; background:fixed !important";
final CSSDeclarationList aDeclList = CSSReaderDeclarationList.readFromString(sStyle, ECSSVersion.CSS30);
if (aDeclList == null)
throw new IllegalStateException("Failed to parse CSS: " + sStyle);
return aDeclList;
}
use of com.helger.css.decl.CSSDeclarationList in project ph-css by phax.
the class CSSVisitorDeclarationListFuncTest method testModifyingCSSUrlVisitor.
@Test
public void testModifyingCSSUrlVisitor() {
final CSSDeclarationList aCSS = CSSReaderDeclarationList.readFromString("background:url(a.gif);background:url(b.gif);", ECSSVersion.CSS30);
assertNotNull(aCSS);
// Append ".modified" to all URLs
final MockModifyingCSSUrlVisitor aVisitor2 = new MockModifyingCSSUrlVisitor();
CSSVisitor.visitAllDeclarationUrls(aCSS, aVisitor2);
// Check the result
assertEquals("background:url(a.gif.modified);background:url(b.gif.modified)", new CSSWriter(ECSSVersion.CSS30, true).getCSSAsString(aCSS));
// Re-iterate to check twice
CSSVisitor.visitAllDeclarationUrls(aCSS, new DefaultCSSUrlVisitor() {
@Override
public void onImport(@Nonnull final CSSImportRule aImportRule) {
assertTrue(aImportRule.getLocationString().endsWith(".modified"));
}
@Override
public void onUrlDeclaration(@Nullable final ICSSTopLevelRule aTopLevelRule, @Nonnull final CSSDeclaration aDeclaration, @Nonnull final CSSExpressionMemberTermURI aURITerm) {
assertTrue(aURITerm.getURIString().endsWith(".modified"));
}
});
}
use of com.helger.css.decl.CSSDeclarationList in project ph-css by phax.
the class CSSVisitorDeclarationListFuncTest method testVisitConstantCSS.
@Test
public void testVisitConstantCSS() {
// CSS 1
CSSDeclarationList aCSS = CSSReaderDeclarationList.readFromString("color:red;", ECSSVersion.CSS30);
assertNotNull(aCSS);
MockCountingUrlVisitor aVisitor = new MockCountingUrlVisitor();
CSSVisitor.visitAllDeclarationUrls(aCSS, aVisitor);
CSSVisitor.visitAllDeclarationUrls(aCSS, new DefaultCSSUrlVisitor());
CSSVisitor.visitAllDeclarations(aCSS, new DefaultCSSVisitor());
assertEquals(0, aVisitor.getCount());
// CSS 2
aCSS = CSSReaderDeclarationList.readFromString("background:url(a.gif)", ECSSVersion.CSS30);
assertNotNull(aCSS);
aVisitor = new MockCountingUrlVisitor();
CSSVisitor.visitAllDeclarationUrls(aCSS, aVisitor);
CSSVisitor.visitAllDeclarationUrls(aCSS, new DefaultCSSUrlVisitor());
CSSVisitor.visitAllDeclarations(aCSS, new DefaultCSSVisitor());
assertEquals(1, aVisitor.getCount());
// CSS 3
aCSS = CSSReaderDeclarationList.readFromString("background:url(a.gif);background:url(b.gif);", ECSSVersion.CSS30);
assertNotNull(aCSS);
aVisitor = new MockCountingUrlVisitor();
CSSVisitor.visitAllDeclarationUrls(aCSS, aVisitor);
CSSVisitor.visitAllDeclarationUrls(aCSS, new DefaultCSSUrlVisitor());
CSSVisitor.visitAllDeclarations(aCSS, new DefaultCSSVisitor());
assertEquals(2, aVisitor.getCount());
}
use of com.helger.css.decl.CSSDeclarationList in project ph-css by phax.
the class CSSReaderDeclarationListTest method testReadAndValidate.
@Test
public void testReadAndValidate() {
final CSSDeclarationList aList = CSSReaderDeclarationList.readFromString("color:red; background:fixed;", ECSSVersion.CSS30);
assertNotNull(aList);
assertEquals(2, aList.getDeclarationCount());
CSSDeclaration aDecl = aList.getDeclarationAtIndex(0);
assertNotNull(aDecl);
assertEquals("color", aDecl.getProperty());
assertEquals(1, aDecl.getExpression().getMemberCount());
assertEquals("red", ((CSSExpressionMemberTermSimple) aDecl.getExpression().getMemberAtIndex(0)).getValue());
aDecl = aList.getDeclarationAtIndex(1);
assertNotNull(aDecl);
assertEquals("background", aDecl.getProperty());
}
Aggregations