use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testJustServer2SideInJS.
public void testJustServer2SideInJS() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script><? !!!!!!!!!!!!!! ?></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("content not included\n" + translated, translated.length() != 0);
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testHTMLFormat.
public void testHTMLFormat() {
// get model
IStructuredModel structuredModel = getModel("test1.html");
assertNotNull("missing test model", structuredModel);
// compare
String formatted = structuredModel.getStructuredDocument().get();
String expectedFileName = "test1.html";
String expected = getFile(expectedFileName);
JsTranslationAdapterFactory.setupAdapterFactory(structuredModel);
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) ((IDOMModel) structuredModel).getDocument().getAdapterFor(IJsTranslation.class);
IJsTranslation translation = translationAdapter.getJsTranslation(false);
assertTrue("expected function definition is missing", translation.getJsText().indexOf("function blah()") >= 0);
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testJustServer1SideInJS.
public void testJustServer1SideInJS() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script><%= %></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("content not included\n" + translated, translated.length() != 0);
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testMangleMultipleMixedServerSideInJS_and_CheckProblems.
public void testMangleMultipleMixedServerSideInJS_and_CheckProblems() {
// 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("translated contents not as expected", " var text = _$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.IJsTranslation in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testCDATAAroundJS1.
public void testCDATAAroundJS1() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script> <![CDATA[ var text = 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("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