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); } } }
private void doTest(String test) { var userDir = System.getProperty("user.dir"); var sourcePath = PathHelper.combine(PathHelper.combine(userDir, "tests/resources/ParseExpressionTest/sources"), test + ".txt"); var fileReader = new InputStreamReader(new FileInputStream((sourcePath)), Charset.forName("UTF-8")); var code = readToEnd(fileReader); text = code.toCharArray(); var parser = new Parser(); var scanner = new SourceCodeScanner(new CodeErrorManager(), text); var expression = parser.parseExpression(scanner); var result = expressionToString(expression); var generatedPath = PathHelper.combine(userDir, "tests/resources/ParseExpressionTest/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 expectedPath = PathHelper.combine(userDir, "tests/resources/ParseExpressionTest/expected"); var expectedFile = new File(PathHelper.combine(expectedPath, test + ".txt")); Assert.assertTrue("Expected file not found: " + expectedFile, expectedFile.exists()); fileReader = new InputStreamReader(new FileInputStream((expectedFile)), Charset.forName("UTF-8")); var reference = readToEnd(fileReader); 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); } }
private void doTest(String test, TypeInfo typeInfo) { String result = typeToString(typeInfo, ""); var userDir = System.getProperty("user.dir"); var generatedPath = PathHelper.combine(userDir, "Tests/resources/TypeSystemTest/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 expectedPath = PathHelper.combine(userDir, "Tests/resources/TypeSystemTest/expected"); var expectedFile = new File(PathHelper.combine(expectedPath, test + ".txt")); Assert.assertTrue("Expected file not found: " + expectedFile, expectedFile.exists()); var fileReader = new InputStreamReader(new FileInputStream((expectedFile)), Charset.forName("UTF-8")); var reference = readToEnd(fileReader); 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); } }