use of org.eclipse.jface.text.templates.TemplateBuffer in project eclipse.platform.text by eclipse.
the class TemplateTranslatorTest method testTextParameterTemplate.
@Test
public void testTextParameterTemplate() throws Exception {
TemplateBuffer buffer = fTranslator.translate("foo ${ var : qual.type ( 'a parameter 1', qual.param2, 'a parameter ''3' ) } 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("qual.type", vars[0].getType());
List<String> params = new ArrayList<>(3);
params.add("a parameter 1");
params.add("qual.param2");
params.add("a parameter '3");
assertEquals(params, vars[0].getVariableType().getParams());
}
use of org.eclipse.jface.text.templates.TemplateBuffer 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.TemplateBuffer 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.TemplateBuffer 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.TemplateBuffer 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());
}
Aggregations