@Test
public void prepareStatementToDonateTopLevelCaseAndDefaultRemoved() throws Exception {

  // Checks that top-level 'case' and 'default' labels get removed, even when injecting into
  // a switch.
  final DonateDeadCodeTransformation dlc = getDummyTransformationObject();
  final TranslationUnit donor = ParseHelper.parse("#version 310 es\n"
      + "void main() {\n"
      + "  int x = 3;\n"
      + "  switch (x) {\n"
      + "    case 0:\n"
      + "      x++;\n"
      + "    default:\n"
      + "      x++;\n"
      + "  }\n"
      + "}\n");
  final TranslationUnit reference = ParseHelper.parse("#version 310 es\n"
      + "void main() {\n"
      + "  switch (0) {\n"
      + "    case 1:\n"
      + "      1;\n"
      + "    default:\n"
      + "      2;\n"
      + "  }\n"
      + "}\n");
  for (IInjectionPoint injectionPoint : new InjectionPoints(reference, new RandomWrapper(0),
      item -> true).getAllInjectionPoints()) {
    final Stmt toDonate = ((SwitchStmt) donor.getMainFunction().getBody().getStmt(1)).getBody()
        .clone();
    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);
    new StandardVisitor() {
      @Override
      public void visitDefaultCaseLabel(DefaultCaseLabel defaultCaseLabel) {
        // 'default' labels should have been removed.
        fail();
      }
      @Override
      public void visitExprCaseLabel(ExprCaseLabel exprCaseLabel) {
        // 'case' labels should have been removed.
        fail();
      }
    }.visit(donated);
  }
}