From 6c597ef7f1313cb76177a154d099844f4dd71491 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 5 Oct 2015 13:21:32 +0100 Subject: Extract readPrimitive --- .../tests/backends/python/PythonCompilerTests.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerTests.java b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerTests.java index 2563ff8..2df13b9 100644 --- a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerTests.java +++ b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerTests.java @@ -58,18 +58,24 @@ public class PythonCompilerTests extends BackendTests { val stderrOutput = readString(process.getErrorStream()); if (exitCode != 0) { throw new RuntimeException("stderr was: " + stderrOutput); - } else if (output.equals("None")) { - return PrimitiveValues.UNIT; - } else if (output.startsWith("'")) { - return value(output.substring(1, output.length() - 1)); } else { - return value(parseInt(output)); + return readPrimitive(output); } } finally { deleteRecursively(directoryPath.toFile()); } } + private PrimitiveValue readPrimitive(String output) { + if (output.equals("None")) { + return PrimitiveValues.UNIT; + } else if (output.startsWith("'")) { + return value(output.substring(1, output.length() - 1)); + } else { + return value(parseInt(output)); + } + } + private String readString(final InputStream stream) throws IOException { return CharStreams.toString(new InputStreamReader(stream, Charsets.UTF_8)); } -- cgit v1.2.3