use of org.eclipse.jface.text.templates.TemplateVariable in project eclipse.platform.text by eclipse.
the class TemplateTranslatorTest method testTypedTemplate.
/* 3.3 typed template variables */
@Test
public void testTypedTemplate() throws Exception {
TemplateBuffer buffer = fTranslator.translate("foo ${var:type} bar");
assertNull(fTranslator.getErrorMessage());
assertEquals("foo var bar", buffer.getString());
TemplateVariable[] vars = buffer.getVariables();
assertEquals(1, vars.length);
assertEquals("var", vars[0].getName());
assertEquals(1, vars[0].getOffsets().length);
assertEquals(4, vars[0].getOffsets()[0]);
assertEquals(3, vars[0].getLength());
assertEquals(false, vars[0].isUnambiguous());
assertEquals("var", vars[0].getDefaultValue());
assertEquals(1, vars[0].getValues().length);
assertEquals("type", vars[0].getType());
assertEquals(vars[0].getDefaultValue(), vars[0].getValues()[0]);
}
use of org.eclipse.jface.text.templates.TemplateVariable in project eclipse.platform.text by eclipse.
the class TemplateTranslatorTest method testDollar.
@Test
public void testDollar() throws Exception {
TemplateBuffer buffer = fTranslator.translate("foo $$ bar");
assertNull(fTranslator.getErrorMessage());
TemplateVariable[] vars = buffer.getVariables();
assertEquals(0, vars.length);
assertEquals("foo $ bar", buffer.getString());
}
use of org.eclipse.jface.text.templates.TemplateVariable in project eclipse.platform.text by eclipse.
the class TemplateTranslatorTest method testNonAsciiVarTemplate.
@Test
public void testNonAsciiVarTemplate() throws Exception {
TemplateBuffer buffer = fTranslator.translate("System.out.println(${bl\u00F6d:var} + \" with element type \" + ${h\u00E4:elemType(bl\u00F6d)});");
assertNull(fTranslator.getErrorMessage());
assertEquals("System.out.println(bl\u00F6d + \" with element type \" + h\u00E4);", buffer.getString());
TemplateVariable[] vars = buffer.getVariables();
assertEquals(2, vars.length);
assertEquals("bl\u00F6d", vars[0].getName());
assertEquals(1, vars[0].getOffsets().length);
assertEquals(19, vars[0].getOffsets()[0]);
assertEquals(4, vars[0].getLength());
assertEquals(false, vars[0].isUnambiguous());
assertEquals("bl\u00F6d", vars[0].getDefaultValue());
assertEquals(1, vars[0].getValues().length);
assertEquals(vars[0].getDefaultValue(), vars[0].getValues()[0]);
assertEquals("var", vars[0].getType());
assertEquals("h\u00E4", vars[1].getName());
assertEquals(1, vars[1].getOffsets().length);
assertEquals(50, vars[1].getOffsets()[0]);
assertEquals(2, vars[1].getLength());
assertEquals(false, vars[1].isUnambiguous());
assertEquals("h\u00E4", vars[1].getDefaultValue());
assertEquals(1, vars[1].getValues().length);
assertEquals(vars[1].getDefaultValue(), vars[1].getValues()[0]);
assertEquals("elemType", vars[1].getType());
}
use of org.eclipse.jface.text.templates.TemplateVariable in project eclipse.platform.text by eclipse.
the class TemplateTranslatorTest method testParameterizedTypeTemplate.
@Test
public void testParameterizedTypeTemplate() throws Exception {
TemplateBuffer buffer = fTranslator.translate("foo ${var:type(param)} bar");
assertNull(fTranslator.getErrorMessage());
assertEquals("foo var bar", buffer.getString());
TemplateVariable[] vars = buffer.getVariables();
assertEquals(1, vars.length);
assertEquals("var", vars[0].getName());
assertEquals(1, vars[0].getOffsets().length);
assertEquals(4, vars[0].getOffsets()[0]);
assertEquals(3, vars[0].getLength());
assertEquals(false, vars[0].isUnambiguous());
assertEquals("var", vars[0].getDefaultValue());
assertEquals(1, vars[0].getValues().length);
assertEquals(vars[0].getDefaultValue(), vars[0].getValues()[0]);
assertEquals("type", vars[0].getType());
assertEquals(Collections.singletonList("param"), vars[0].getVariableType().getParams());
}
use of org.eclipse.jface.text.templates.TemplateVariable in project eclipse.platform.text by eclipse.
the class TemplateTranslatorTest method testNoVarTemplate.
public void testNoVarTemplate() throws Exception {
TemplateBuffer buffer = fTranslator.translate("foo bar");
assertNull(fTranslator.getErrorMessage());
TemplateVariable[] vars = buffer.getVariables();
assertEquals(0, vars.length);
assertEquals("foo bar", buffer.getString());
}
Aggregations