### Question:
KotlinConverter implements ASTConverter { @Override public Tree parse(String content) { KotlinTree kotlinTree = new KotlinTree(content); KotlinTreeVisitor kotlinTreeVisitor = new KotlinTreeVisitor(kotlinTree.psiFile, kotlinTree.metaDataProvider); return kotlinTreeVisitor.getSLangAST(); }  @Override Tree parse(String content);  }### Answer:
@Test public void testParseException() { thrown.expect(ParseException.class); thrown.expectMessage("Cannot convert file due to syntactic errors"); converter.parse("enum class A {\n<!REDECLARATION!>FOO<!>,<!REDECLARATION!>FOO<!>}"); }
@Test public void testWinEOL() { Tree tree = converter.parse( "fun main(args: Array<String>) {\r\n" + "\r\n" + "}\r\n"); assertThat(tree.children()).hasSize(1); }
@Test public void testParsedExceptionWithPartialParsing() { thrown.expect(ParseException.class); thrown.expectMessage("Cannot convert file due to syntactic errors"); converter.parse("fun foo() { a b c ...}"); }
@Test public void testParseWithoutNullPointer() { thrown.expect(ParseException.class); thrown.expectMessage("Cannot convert file due to syntactic errors"); converter.parse("package ${package}"); }
@Test public void testFirstCpdToken() { TopLevelTree topLevel = (TopLevelTree) converter.parse("" + "@file:JvmName(\"xxx\")\n" + "package com.example\n" + "import com.example.MyClass\n" + "fun main(args: Array<String>) {}\n" + "class A {}"); assertThat(topLevel.declarations()).hasSize(5); assertThat(topLevel.firstCpdToken().text()).isEqualTo("fun"); }
@Test public void testImport() { Tree topLevel = converter.parse("import abc"); assertThat(topLevel.children()).hasSize(1); assertThat(topLevel.children().get(0)).isInstanceOf(ImportDeclarationTree.class); }
@Test public void testPackage() { Tree topLevel = converter.parse("package abc"); assertThat(topLevel.children()).hasSize(1); assertThat(topLevel.children().get(0)).isInstanceOf(PackageDeclarationTree.class); }
@Test public void testComments() { Tree parent = converter.parse("#! Shebang comment\n\nfun function1(a: Int, b: String): Boolean { assertTree(parent).isInstanceOf(TopLevelTree.class); assertThat(parent.children()).hasSize(1); TopLevelTree topLevelTree = (TopLevelTree) parent; List<Comment> comments = topLevelTree.allComments(); assertThat(comments).hasSize(4); Comment comment = comments.get(1); assertRange(comment.textRange()).hasRange(2, 0, 3, 2); assertRange(comment.contentRange()).hasRange(2, 3, 3, 0); assertThat(comment.contentText()).isEqualTo(" Doc comment \n"); assertThat(comment.text()).isEqualTo(""); FunctionDeclarationTree tree = (FunctionDeclarationTree) topLevelTree.declarations().get(0); List<Comment> commentsInsideFunction = tree.metaData().commentsInside(); assertThat(commentsInsideFunction).hasSize(3); comment = commentsInsideFunction.get(2); assertRange(comment.textRange()).hasRange(4, 63, 4, 77); assertRange(comment.contentRange()).hasRange(4, 65, 4, 77); assertThat(comment.text()).isEqualTo(" }
@Test public void testMappedComments() { TopLevelTree kotlinTree = (TopLevelTree) converter .parse("\n TopLevelTree slangTree = (TopLevelTree) new SLangConverter() .parse("\n assertThat(kotlinTree.allComments()).hasSize(3); assertThat(kotlinTree.allComments()).isNotEqualTo(slangTree.allComments()); List<String> slangCommentsWithDelimiters = slangTree.allComments().stream().map(Comment::text).collect(Collectors.toList()); assertThat(kotlinTree.allComments()).extracting(Comment::text).isEqualTo(slangCommentsWithDelimiters); }