use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testXMLComment.
public void testXMLComment() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script> if(a) <!-- --> </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();
assertEquals("translated content differs", " if(a) _$ta _$t ", translated);
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testMangleMultipleServerSide1InJSCheckProblems.
public void testMangleMultipleServerSide1InJSCheckProblems() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script> var text = <%= javaObject.getText() %>; <%= javaObject.getText() %></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", translated.indexOf("<%") < 0);
assertTrue("server-side script block included", translated.indexOf("%>") < 0);
assertTrue("var dropped", translated.indexOf("var text = ") > -1);
assertTrue("problems found in translation ", translation.getProblems().isEmpty());
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testMangleMultipleMixedServerSideInJSwithXMLcommentOnSameLine.
public void testMangleMultipleMixedServerSideInJSwithXMLcommentOnSameLine() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script> <!-- var text = <? serverObject.getText() ?>; <%=\"a\"%> <%=\"b\"%> <? serverObject.getText() ?><%=\"c\"%> </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();
assertEquals("script with leading comment but no new line should be blank", " ", translated);
assertTrue("server-side script block included", translated.indexOf("<?") < 0);
assertTrue("server-side script block included", translated.indexOf("?>") < 0);
assertTrue("server-side script block included", translated.indexOf("<%") < 0);
assertTrue("server-side script block included", translated.indexOf("%>") < 0);
assertTrue("problems found in translation ", translation.getProblems().isEmpty());
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testFunctionReturnInEventHandler.
public void testFunctionReturnInEventHandler() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<div onClick=\"return myMethod();\">");
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();
assertEquals("translated content differs", " (function(){return myMethod();;})();", translated);
StringBuffer problems = new StringBuffer();
translation.reconcileCompilationUnit();
List problemList = translation.getProblems();
for (int i = 0; i < problemList.size(); i++) {
problems.append(((IProblem) problemList.get(i)).getMessage());
problems.append('\n');
}
assertEquals("problems were found", "", problems.toString());
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testJustClientTagInJS.
public void testJustClientTagInJS() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script><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 too short", translated.length() > 0);
assertTrue("server-side script block included\n" + translated, translated.indexOf("<") < 0);
assertTrue("server-side script block included\n" + translated, translated.indexOf("/>") < 0);
assertTrue("content not included\n" + translated, translated.length() != 0);
// release model
structuredModel.releaseFromRead();
}
Aggregations