use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel 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.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class CSSSourceParserTest method readModelAppend.
private ICSSModel readModelAppend(String filename) throws IOException {
String source = FileUtil.createString(FILES_DIR, filename);
ICSSModel model = FileUtil.createModel();
IStructuredDocument document = model.getStructuredDocument();
for (int i = 0; i < source.length(); i++) {
document.replaceText(null, i, 0, source.substring(i, i + 1));
}
return model;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class CSSSourceParserTest method readModelOpen.
private ICSSModel readModelOpen(String filename) throws IOException {
String source = FileUtil.createString(FILES_DIR, filename);
ICSSModel model = FileUtil.createModel();
IStructuredDocument document = model.getStructuredDocument();
document.replaceText(null, 0, 0, source);
return model;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class CSSUrlTest method testDeclaration2.
/**
* Declaration: without quotes, with surrounded space
*/
public void testDeclaration2() {
ICSSModel model = FileUtil.createModel();
IStructuredDocument document = model.getStructuredDocument();
((CSSSourceParser) document.getParser()).setParserMode(CSSSourceParser.MODE_DECLARATION_VALUE);
// $NON-NLS-1$
document.set("background-image: url( white space.gif );");
UrlInfo[] urls = pickupUrl(document);
assertEquals(1, urls.length);
assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[0].getType());
// $NON-NLS-1$
assertEquals("white space.gif", urls[0].getUrl());
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class CSSUrlTest method testFixError2.
/**
* Import rule and style rule: Two urls but parenthesis are missed, so
* concatenated url is identified. By adding parenthesis, urls are
* corrected.
*/
public void testFixError2() {
ICSSModel model = FileUtil.createModel();
IStructuredDocument document = model.getStructuredDocument();
// ____________01234567890123456789012345678901234567890123456789012345678901234567890123456789
// $NON-NLS-1$
document.set("@import url(white space.css;LI { background-image: urlwhite space.gif); }");
UrlInfo[] urls = pickupUrl(document);
assertEquals(1, urls.length);
assertEquals(CSSRegionContexts.CSS_URI, urls[0].getType());
// $NON-NLS-1$
assertEquals("white space.css;LI { background-image: urlwhite space.gif", urls[0].getUrl());
// correct first url
// $NON-NLS-1$
document.replaceText(null, 27, 0, ")");
urls = pickupUrl(document);
assertEquals(1, urls.length);
assertEquals(CSSRegionContexts.CSS_URI, urls[0].getType());
// $NON-NLS-1$
assertEquals("white space.css", urls[0].getUrl());
// correct second url
// $NON-NLS-1$
document.replaceText(null, 55, 0, "(");
urls = pickupUrl(document);
assertEquals(2, urls.length);
assertEquals(CSSRegionContexts.CSS_URI, urls[0].getType());
// $NON-NLS-1$
assertEquals("white space.css", urls[0].getUrl());
assertEquals(CSSRegionContexts.CSS_DECLARATION_VALUE_URI, urls[1].getType());
// $NON-NLS-1$
assertEquals("white space.gif", urls[1].getUrl());
}
Aggregations