use of org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testLeadingXMLComment.
public void testLeadingXMLComment() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "0<script> <!--12</script>3");
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 empty", " ", translated);
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testMangleServerSide1InJSCheckProblems.
// public void testMangleOverlappingTagAndServerSideInJS() {
// // get model
// String fileName = getName() + ".html";
// IStructuredModel structuredModel = getSharedModel(fileName, "<script> var a = <%= 4 %>5;\nif(a < <custom:tag attr=\"<%=%>\"/>) {} ; </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("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();
// }
public void testMangleServerSide1InJSCheckProblems() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script> var text = <%= 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.JsTranslationAdapter in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testMangleMultipleServerSide2InJSCheckProblems.
public void testMangleMultipleServerSide2InJSCheckProblems() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script> var text = <? serverObject.getText() ?>; <? serverObject.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.JsTranslationAdapter in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testMangleMultipleMixedServerSideAndClientTagInJS_and_CheckProblems2.
public void testMangleMultipleMixedServerSideAndClientTagInJS_and_CheckProblems2() {
// get model
String fileName = getName() + ".jsp";
IStructuredModel structuredModel = getSharedModel(fileName, "<script> var text = <? serverObject.getText() ?>; <%=\"a\"%> <%=\"b\"%> <server:tag/> <? 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("translated contents not as expected", " var text = _$tag_______________________; _$tag___ _$tag___ _$tag________ _$tag________________________$tag___ ", translated);
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("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.JsTranslationAdapter in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testCDATAInJS.
public void testCDATAInJS() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script> var text = <![CDATA[ serverObject.getText() ;\n//]]> </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("CDATA start found", translated.indexOf("CDATA") < 0);
assertTrue("CDATA start found", translated.indexOf("[") < 0);
assertTrue("CDATA end found", translated.indexOf("]") < 0);
assertTrue("problems found in translation ", translation.getProblems().isEmpty());
// release model
structuredModel.releaseFromRead();
}
Aggregations