@Test
public void prepareStatementToDonateTopLevelBreakRemovedWhenNecessary() throws Exception {

  // Checks that a top-level 'break' gets removed, unless injecting into a loop or switch.
  final DonateDeadCodeTransformation dlc = getDummyTransformationObject();
  final TranslationUnit donor = ParseHelper.parse("#version 310 es\n"
      + "void main() {\n"
      + "  for (int i = 0; i < 10; i ++)\n"
      + "     if (i > 5) break;\n"
      + "}\n");
  final TranslationUnit reference = ParseHelper.parse("#version 310 es\n"
      + "void main() {\n"
      + "  ;\n"
      + "  for(int i = 0; i < 100; i++) {\n"
      + "    switch (i) {\n"
      + "      case 0:\n"
      + "        i++;\n"
      + "      default:\n"
      + "        i++;\n"
      + "    }\n"
      + "  }"
      + "}\n");
  for (IInjectionPoint injectionPoint : new InjectionPoints(reference, new RandomWrapper(0),
      item -> true).getAllInjectionPoints()) {
    final Stmt toDonate = ((ForStmt) donor.getMainFunction().getBody().getStmt(0)).getBody()
        .clone();
    assert toDonate instanceof IfStmt;
    final DonationContext dc = new DonationContext(toDonate, new HashMap<>(),
        new ArrayList<>(), donor.getMainFunction());
    final Stmt donated = dlc.prepareStatementToDonate(injectionPoint, dc,
        TransformationProbabilities.DEFAULT_PROBABILITIES, new RandomWrapper(0),
        ShadingLanguageVersion.ESSL_310);
    final boolean containsBreak = new CheckPredicateVisitor() {
      @Override
      public void visitBreakStmt(BreakStmt breakStmt) {
        predicateHolds();
      }
    }.test(donated);
    assertEquals(containsBreak, injectionPoint.inLoop() || injectionPoint.inSwitch());
  }
}