use of org.eclipse.n4js.xpect.config.Config in project n4js by eclipse.
the class ContentAssistXpectMethod method assertContainingMatchAllOrdered.
private void assertContainingMatchAllOrdered(List<String> proposals, List<String> required, CommaSeparatedValuesExpectationImpl exp) {
List<String> matched = Lists.newArrayList();
HashMap<String, Integer> match2index = new HashMap<>();
// TODO review if needed
// boolean orderBroken = false;
int highestIdx = 0;
for (int i = 0; i < required.size(); i++) {
String r = required.get(i);
Optional<String> prop = proposals.stream().filter(p -> p.contains(r)).findFirst();
if (prop.isPresent()) {
int idx = proposals.indexOf(prop.get());
if (highestIdx >= idx) {
// orderBroken = true;
}
matched.add(r);
match2index.put(r, idx);
highestIdx = Math.max(highestIdx, idx);
}
}
// create the matchedOrder:
List<String> matchedOrder = match2index.entrySet().stream().sorted(new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Entry<String, Integer> e1, Entry<String, Integer> e2) {
return e1.getValue().compareTo(e2.getValue());
}
}).map(sme -> sme.getKey()).collect(Collectors.toList());
// change config to ordered:
CommaSeparatedValuesExpectationCfg cfg = new CommaSeparatedValuesExpectationCfg(exp.getAnnotation());
cfg.setOrdered(true);
CommaSeparatedValuesExpectationImpl expNCSV = new CommaSeparatedValuesExpectationImpl(exp, cfg);
expNCSV.assertEquals(matchedOrder);
}
Aggregations