private String lambdaToString(LambdaExpression lambda) { var sb = new StringBuilder(); sb.append("stab.tree.ExpressionTree<"); sb.append(lambda.Type); sb.append("> tree =\n\t("); var first = true; foreach (var p in lambda.Parameters) { if (first) { first = false; } else { sb.append(", "); } variableToString(p, sb); } sb.append(") =>\n"); statementToString(lambda.Body, sb, " "); return sb.toString(); }
private void doTest(String test, LambdaExpression lambda) { variables = new ArrayList<VariableExpression>(); labels = new ArrayList<Label>(); switchLabels = new ArrayList<SwitchLabel>(); var result = lambdaToString(lambda); var userDir = System.getProperty("user.dir"); var generatedPath = PathHelper.combine(userDir, "tests/resources/ExpressionTreesTest/generated"); var generatedDir = new File(generatedPath); if (!generatedDir.exists()) { generatedDir.mkdir(); } var fileWriter = new FileWriter(PathHelper.combine(generatedPath, test + ".txt")); fileWriter.write(result); fileWriter.close(); var referencePath = PathHelper.combine(PathHelper.combine(userDir, "tests/resources/ExpressionTreesTest/references"), test + ".txt"); var referenceFile = new File(referencePath); String reference = null; if (referenceFile.exists()) { var fileReader = new InputStreamReader(new FileInputStream((referencePath)), Charset.forName("UTF-8")); reference = readToEnd(fileReader); } else { Assert.fail("No reference for '" + test + "'"); } if (reference != null) { var genReader = new BufferedReader(new StringReader(result)); var refReader = new BufferedReader(new StringReader(reference)); for (;;) { var genLine = genReader.readLine(); var refLine = refReader.readLine(); if (genLine == null && refLine == null) { break; } Assert.assertEquals(refLine, genLine); } } }