use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testMangleTagAndServerSideInJS.
public void testMangleTagAndServerSideInJS() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script> var a = <%= 4 %>5;\nif(a < <custom:tag/>) {} ; </script>");
assertNotNull("missing test model", structuredModel);
// do translation
JsTranslationAdapterFactory.setupAdapterFactory(structuredModel);
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) ((IDOMModel) structuredModel).getDocument().getAdapterFor(IJsTranslation.class);
IJsTranslation translation = translationAdapter.getJsTranslation(false);
String translated = translation.getJsText();
assertTrue("translation empty", translated.length() > 5);
assertTrue("server-side script block included\n" + translated, translated.indexOf("<%") < 0);
assertTrue("server-side script block included\n" + translated, translated.indexOf("%>") < 0);
assertTrue("tag included\n" + translated, translated.indexOf("custom") < 0);
assertTrue("tag included\n" + translated, translated.indexOf("/>") < 0);
assertTrue("var dropped\n" + translated, translated.indexOf("var a = ") > -1);
assertTrue("if dropped\n" + translated, translated.indexOf("5;\nif(a < ") > -1);
assertTrue("block dropped\n" + translated, translated.indexOf(") {} ; ") > -1);
assertTrue("problems found in translation ", translation.getProblems().isEmpty());
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class TestHTMLValidator method testRemoveAndAddBackCommentEndTag.
/**
* Regression test for Bug 285285
*
* @see org.eclipse.wst.xml.ui.internal.validation.TestDelegatingSourceValidatorForXML#testRemoveAndAddBackCommentEndTag
* @see org.eclipse.wst.html.ui.tests.validation.TestHTMLValidator#testRemoveAndAddBackCommentEndTag
* @see org.eclipse.jst.jsp.ui.tests.validation.JSPHTMLValidatorTest#testRemoveAndAddBackCommentEndTag
*/
public void testRemoveAndAddBackCommentEndTag() throws Exception {
IFile testFile = null;
IStructuredModel model = null;
try {
// get test file
testFile = fProject.getFile("RemoveAndAddBackCommentEndTag.html");
assertTrue("Test file " + testFile + " does not exist", testFile.exists());
// get the document
model = StructuredModelManager.getModelManager().getModelForEdit(testFile);
IStructuredDocument document = model.getStructuredDocument();
// set up for fValidator
WorkbenchContext context = new WorkbenchContext();
List fileList = new ArrayList();
fileList.add(testFile.getFullPath().toPortableString());
context.setValidationFileURIs(fileList);
// validate clean file
TestReporter reporter = new TestReporter();
fValidator.validate(context, reporter);
assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
// need to dynamically find where the --> is because
// its different on unix vs windows because of line endings
String contents = document.get();
int endCommentIndex = contents.indexOf("-->");
// remove -->
document.replace(endCommentIndex, 3, "");
// validate file with error
reporter = new TestReporter();
fValidator.validate(context, reporter);
assertTrue("There should be validation errors on " + testFile, reporter.isMessageReported());
// replace -->
document.replace(endCommentIndex, 0, "-->");
// validate clean file
reporter = new TestReporter();
fValidator.validate(context, reporter);
assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class TestHTMLValidator method testInvalidateTagNameThenFix.
/**
* Regression test for Bug 298472
*/
public void testInvalidateTagNameThenFix() throws Exception {
IFile testFile = null;
IStructuredModel model = null;
try {
// get test file
testFile = fProject.getFile("InvalidateTagNameThenFix.html");
assertTrue("Test file " + testFile + " does not exist", testFile.exists());
// get the document
model = StructuredModelManager.getModelManager().getModelForEdit(testFile);
IStructuredDocument document = model.getStructuredDocument();
// set up for validator
WorkbenchContext context = new WorkbenchContext();
List fileList = new ArrayList();
fileList.add(testFile.getFullPath().toPortableString());
context.setValidationFileURIs(fileList);
// validate clean file
TestReporter reporter = new TestReporter();
fValidator.validate(context, reporter);
assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
// need to dynamically find where the --> is because
// its different on unix vs windows because of line endings
String contents = document.get();
int endOfStartTagIndex = contents.indexOf("></div>");
// change to <divx></div>
document.replace(endOfStartTagIndex, 0, "x");
// validate file with error
reporter = new TestReporter();
fValidator.validate(context, reporter);
assertTrue("There should be validation errors on " + testFile, reporter.isMessageReported());
// change back to <div></div>
document.replace(endOfStartTagIndex, 1, "");
// validate clean file
reporter = new TestReporter();
fValidator.validate(context, reporter);
assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerHTML method getModelForEdit.
/**
* must release model (from edit) after
* @param filename relative to this class (TestStructuredPartitioner)
*/
private IStructuredModel getModelForEdit(String filename) {
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
InputStream inStream = getClass().getResourceAsStream(filename);
if (inStream == null)
inStream = new StringBufferInputStream("");
model = modelManager.getModelForEdit(filename, inStream, null);
} catch (IOException ex) {
ex.printStackTrace();
}
return model;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerHTML method doComputePartitioningTest.
/**
* Compute the partitions for the given filename using the default partitioner
* for that file type.
*
* @param filename
* @return int
* @throws IOException
* @throws BadLocationException
*/
protected int doComputePartitioningTest(String filename) throws IOException, BadLocationException {
IModelManager modelManager = StructuredModelManager.getModelManager();
InputStream inStream = getClass().getResourceAsStream(filename);
if (inStream == null)
inStream = new StringBufferInputStream("");
IStructuredModel model = modelManager.getModelForEdit(filename, inStream, null);
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (DEBUG_PRINT_RESULT && useFormatter) {
double baseTen = Math.log(10);
formatter.setMinimumIntegerDigits((int) (Math.log(structuredDocument.getLength()) / baseTen) + 1);
formatter.setGroupingUsed(false);
}
partitions = structuredDocument.computePartitioning(0, structuredDocument.getLength());
if (DEBUG_PRINT_RESULT) {
String contents = null;
System.out.println("\nfilename: " + filename);
for (int i = 0; i < partitions.length; i++) {
try {
contents = structuredDocument.get(partitions[i].getOffset(), partitions[i].getLength());
} catch (BadLocationException e) {
contents = "*error*";
}
if (useFormatter)
System.out.println(formatter.format(partitions[i].getOffset()) + ":" + formatter.format(partitions[i].getLength()) + " - " + partitions[i].getType() + " [" + StringUtils.escape(contents) + "]");
else
System.out.println(partitions[i] + " [" + StringUtils.escape(contents) + "]");
}
}
checkSeams();
model.releaseFromEdit();
inStream.close();
if (partitions == null)
return -1;
return partitions.length;
}
Aggregations