use of org.eclipse.n4js.xpect.config.Preferences in project n4js by eclipse.
the class FormatterXpectMethod method formattedLines.
/**
*/
@Xpect
@ParameterParser(syntax = "arg1=INT")
public void formattedLines(@StringExpectation(whitespaceSensitive = true) IStringExpectation exp, // arg1
int lines, XpectInvocation inv, TargetSyntaxSupport syntax, ITextRegionAccess reg, ISetupInitializer<Preferences> prefInit) {
ITextSegment region = getRegionForLines(reg, syntax.findFirstSemanticCharAfterStatement(inv), lines);
Preferences prefs = new Preferences();
// First put some defaults
prefs.put(N4JSFormatterPreferenceKeys.FORMAT_PARENTHESIS, true);
prefs.put(FormatterPreferenceKeys.lineSeparator, "\n");
// Second init from concrete tests - will override defaults.
prefInit.initialize(prefs);
IFormatter2 formatter = formatterProvider.get();
FormatterRequest request = formatterRequestProvider.get();
request.setTextRegionAccess(reg);
request.setExceptionHandler(ExceptionAcceptor.THROWING);
// needed in case a check like this will be implemented:
// org.eclipse.xtext.testing.formatter.FormatterTester.assertAllWhitespaceIsFormatted()
request.setAllowIdentityEdits(true);
request.setFormatUndefinedHiddenRegionsOnly(false);
request.addRegion(region);
request.setPreferences(prefs);
List<ITextReplacement> replacements = formatter.format(request);
String fmt = reg.getRewriter().renderToString(replacements);
ITextSegment doc = reg.regionForDocument();
int endIndex = region.getEndOffset() + (fmt.length() - doc.getLength()) - 1;
String selection = fmt.substring(region.getOffset(), endIndex);
exp.assertEquals(selection);
}
Aggregations