GoSnippetExecutor extends AbstractSnippetExecutor<GoSnippetExecutorOptions> { protected String buildSourceCode(final CodeSnippet codeSnippet) throws IOException { final StringBuilder sourceCode = new StringBuilder(); sourceCode.append(getStartPackageDefinition(codeSnippet)).append("\n\n"); if (hasImports(codeSnippet)) { sourceCode.append(getImports(codeSnippet)).append("\n\n"); } if (mustBeWrappedIn(codeSnippet, WRAP_IN_MAIN_PROPERTY)) { sourceCode.append("func main() {\n") .append(codeSnippet.getCode()) .append("\n}"); } else { sourceCode.append(codeSnippet.getCode()); } return sourceCode.toString(); } GoSnippetExecutor(); @Override Parent getUI(final CodeSnippet codeSnippet); @Override Node getConfigurationUI(); @Override void saveNewOptions(); @Override ObservableList<String> execute(final CodeSnippet codeSnippet);  }
@Test public void buildSourceCodeWithoutImportsAndWithoutWrapInMainAndWithoutPackageName() throws IOException { final CodeSnippet snippet = new CodeSnippet(); snippet.setCode("func main() {\n\tfmt.Printf(\"Hello, world.\\n\")\n}"); final String expected = IOUtils.read(GoSnippetExecutorTest.class.getResourceAsStream("/com/twasyl/slideshowfx/snippet/executor/go/buildSourceCodeWithoutImportsAndWithoutWrapInMainAndWithoutPackageName_expected.txt")); assertEquals(expected, snippetExecutor.buildSourceCode(snippet)); }
@Test public void buildSourceCodeWithoutImportsAndWithoutWrapInMain() throws IOException { final CodeSnippet snippet = new CodeSnippet(); snippet.getProperties().put(PACKAGE_NAME_PROPERTY, "sfx"); snippet.setCode("func main() {\n\tfmt.Printf(\"Hello, world.\\n\")\n}"); final String expected = IOUtils.read(GoSnippetExecutorTest.class.getResourceAsStream("/com/twasyl/slideshowfx/snippet/executor/go/buildSourceCodeWithoutImportsAndWithoutWrapInMain_expected.txt")); assertEquals(expected, snippetExecutor.buildSourceCode(snippet)); }
@Test public void buildSourceCodeWithoutWrapInMain() throws IOException { final CodeSnippet snippet = new CodeSnippet(); snippet.getProperties().put(PACKAGE_NAME_PROPERTY, "sfx"); snippet.getProperties().put(IMPORTS_PROPERTY, "mypackage\nmysecondpackage"); snippet.setCode("func main() {\n\tfmt.Printf(\"Hello, world.\\n\")\n}"); final String expected = IOUtils.read(GoSnippetExecutor.class.getResourceAsStream("/com/twasyl/slideshowfx/snippet/executor/go/buildSourceCodeWithoutWrapInMain_expected.txt")); assertEquals(expected, snippetExecutor.buildSourceCode(snippet)); }
@Test public void buildSourceCode() throws IOException { final CodeSnippet snippet = new CodeSnippet(); snippet.getProperties().put(PACKAGE_NAME_PROPERTY, "sfx"); snippet.getProperties().put(IMPORTS_PROPERTY, "mypackage\nmysecondpackage"); snippet.getProperties().put(WRAP_IN_MAIN_PROPERTY, "true"); snippet.setCode("fmt.Printf(\"Hello, world.\\n\")"); final String expected = IOUtils.read(GoSnippetExecutor.class.getResourceAsStream("/com/twasyl/slideshowfx/snippet/executor/go/buildSourceCode_expected.txt")); assertEquals(expected, snippetExecutor.buildSourceCode(snippet)); }