use of org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext in project webtools.sourceediting by eclipse.
the class TestCSSDecl method testInsertPropertyInExistingRule.
/**
* To test https://bugs.eclipse.org/298111
*/
public void testInsertPropertyInExistingRule() {
ICSSModel model = FileUtil.createModel();
try {
String originalDocument = "@CHARSET \"ISO-8859-1\";\r\n" + ".test {\r\n" + "}";
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(originalDocument);
IndexedRegion indexedRegion = model.getIndexedRegion(28);
assertTrue("Indexed region should be an ICSSStyleRule", indexedRegion instanceof ICSSStyleRule);
ICSSStyleRule rule = (ICSSStyleRule) indexedRegion;
ICSSStyleDeclaration declaration = (ICSSStyleDeclaration) rule.getStyle();
declaration.setProperty("color", "#008040", null);
CSSPropertyContext context = new CSSPropertyContext(declaration);
context.applyModified(declaration);
String newDocument = structuredDocument.get();
String expectedNewDocument = "@CHARSET \"ISO-8859-1\";\r\n" + ".test {\r\n" + "\tcolor: #008040\r\n" + "}";
assertEquals("The updated CSS document does not equal the expected", expectedNewDocument, newDocument);
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
use of org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext in project webtools.sourceediting by eclipse.
the class TestCSSDecl method testStandaloneCSSDecl.
// commenting out this test because decl.setCssText() is not an implemented method
// public void testDecl() {
// CSSPropertyContext context = new CSSPropertyContext();
// ICSSStyleDeclaration decl = CSSStyleDeclarationFactory.getInstance().createStyleDeclaration();
// context.initialize(decl);
// decl.setCssText(getString() != null ? getString() : "");//$NON-NLS-1$
// }
// private String getString() {
// return "body {}";
// }
public void testStandaloneCSSDecl() {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202615
CSSPropertyContext context = new CSSPropertyContext();
ICSSStyleDeclaration decl = CSSStyleDeclarationFactory.getInstance().createStyleDeclaration();
context.initialize(decl);
String cssText = decl.getCssText();
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("standalone css node was not initialized", "", cssText);
// $NON-NLS-1$
context.setMargin("auto");
// $NON-NLS-1$
context.setColor("red");
// $NON-NLS-1$
context.setBorder("thick");
context.applyFull(decl);
cssText = decl.getCssText();
// $NON-NLS-1$
String expected = "color: red; border: thick; margin: auto";
// $NON-NLS-1$
assertEquals("standalone css node's properties were not set as expected", expected, cssText);
}
Aggregations