### Question:
GoConverter implements ASTConverter { @Override public Tree parse(String content) { if (content.length() > MAX_SUPPORTED_SOURCE_FILE_SIZE) { throw new ParseException("The file size is too big and should be excluded," + " its size is " + content.length() + " (maximum allowed is " + MAX_SUPPORTED_SOURCE_FILE_SIZE + " bytes)"); } try { return JsonTree.fromJson(executeGoToJsonProcess(content)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ParseException("Go parser external process interrupted: " + e.getMessage(), null, e); } catch (IOException e) { throw new ParseException(e.getMessage(), null, e); } } GoConverter(File workDir);   GoConverter(Command command); @Override Tree parse(String content);  }### Answer:
@Test public void test_parse_return() { GoConverter converter = new GoConverter(Paths.get("build", "tmp").toFile()); Tree tree = converter.parse("package main\nfunc foo() {return 42}"); List<Tree> returnList = tree.descendants().filter(t -> t instanceof ReturnTree).collect(Collectors.toList()); assertThat(returnList).hasSize(1); }
@Test public void test_parse_infinite_for() { GoConverter converter = new GoConverter(Paths.get("build", "tmp").toFile()); Tree tree = converter.parse("package main\nfunc foo() {for {}}"); List<Tree> returnList = tree.descendants().filter(t -> t instanceof LoopTree).collect(Collectors.toList()); assertThat(returnList).hasSize(1); }
@Test public void parse_error() { exceptionRule.expect(ParseException.class); exceptionRule.expectMessage("Go parser external process returned non-zero exit value: 2"); GoConverter converter = new GoConverter(Paths.get("build", "tmp").toFile()); converter.parse("$!#@"); }
@Test public void invalid_command() { exceptionRule.expect(ParseException.class); exceptionRule.expectMessage(containsString("Cannot run program \"invalid-command\"")); GoConverter.Command command = mock(GoConverter.Command.class); when(command.getCommand()).thenReturn(Collections.singletonList("invalid-command")); GoConverter converter = new GoConverter(command); converter.parse("package main\nfunc foo() {}"); }
@Test public void parse_accepted_big_file() { GoConverter converter = new GoConverter(Paths.get("build", "tmp").toFile()); String code = "package main\n" + "func foo() {\n" + "}\n"; String bigCode = code + new String(new char[700_000 - code.length()]).replace("\0", "\n"); Tree tree = converter.parse(bigCode); assertThat(tree).isInstanceOf(TopLevelTree.class); }
@Test public void parse_rejected_big_file() { exceptionRule.expect(ParseException.class); exceptionRule.expectMessage("The file size is too big and should be excluded, its size is 700028 (maximum allowed is 700000 bytes)"); GoConverter converter = new GoConverter(Paths.get("build", "tmp").toFile()); String code = "package main\n" + "func foo() {\n" + "}\n"; String bigCode = code + new String(new char[700_000]).replace("\0", "\n"); converter.parse(bigCode); }