diff --git a/src/main/scala/de/frosner/replhelper/Helper.scala b/src/main/scala/de/frosner/replhelper/Helper.scala index fdb0342..caa3e15 100644 --- a/src/main/scala/de/frosner/replhelper/Helper.scala +++ b/src/main/scala/de/frosner/replhelper/Helper.scala @@ -57,7 +57,7 @@ class Helper private (val reflections: Reflections, val filter: Class[_] => Bool case ((className, category), categoryMethods) => { s"${Console.BOLD}${category}${Console.RESET} [$className]" + NewLine + categoryMethods.map { case (method, help) => "- " + getMethodSignature(method, help) + s": ${help.shortDescription}" - }.mkString(NewLine) + }.distinct.mkString(NewLine) } }.mkString(NewLine+NewLine) ) @@ -92,7 +92,7 @@ class Helper private (val reflections: Reflections, val filter: Class[_] => Bool case ((className, category), method, help) => getMethodSignature(method, help) }.map { methodWithHelp => getLongDescriptionPrintable(methodWithHelp, out) - }.mkString(NewLine+NewLine) + }.distinct.mkString(NewLine+NewLine) ) } diff --git a/src/test/scala/de/frosner/replhelper/DummyObjectThatIsNoCompanion.scala b/src/test/scala/de/frosner/replhelper/DummyObjectThatIsNoCompanion.scala index 177a5e7..01ab295 100644 --- a/src/test/scala/de/frosner/replhelper/DummyObjectThatIsNoCompanion.scala +++ b/src/test/scala/de/frosner/replhelper/DummyObjectThatIsNoCompanion.scala @@ -5,11 +5,27 @@ object DummyObjectThatIsNoCompanion { @Help( category = "c", shortDescription = "s", - longDescription = "l" + longDescription = "DummyObjectThatIsNoCompanionLong" ) def method = ??? val name = this.getClass.getSimpleName.replace("$", "") val category = "c" + val expectedMethodShortDescription = "- method(): s" + + val expectedShortDescription = Array( + s"${Console.BOLD}c${Console.RESET} [${DummyObjectThatIsNoCompanion.name}]", + expectedMethodShortDescription, + "" + ) + + val expectedMethodLongDescription = "DummyObjectThatIsNoCompanionLong" + + val expectedLongDescription = Array( + s"${Console.BOLD}method()${Console.RESET} [${DummyObjectThatIsNoCompanion.name}]", + expectedMethodLongDescription, + "" + ) + } diff --git a/src/test/scala/de/frosner/replhelper/HelperTest.scala b/src/test/scala/de/frosner/replhelper/HelperTest.scala index 1b33716..60c5213 100644 --- a/src/test/scala/de/frosner/replhelper/HelperTest.scala +++ b/src/test/scala/de/frosner/replhelper/HelperTest.scala @@ -225,6 +225,14 @@ class HelperTest extends FlatSpec with Matchers { result.toString.split(NewLine, -1) shouldBe TestClass.expectedShortOutput ++ TestClass2.expectedShortOutput } + it should "not show duplicate entries for singleton objects" in { + val result = new ByteArrayOutputStream() + val out = new PrintStream(result) + val helper = Helper(ClasspathHelper.forClass(DummyObjectThatIsNoCompanion.getClass)) + helper.printAllMethods(out) + result.toString.split(NewLine, -1).count(_ == DummyObjectThatIsNoCompanion.expectedMethodShortDescription) shouldBe 1 + } + "When specific methods are requested, it" should "show the long description" in { val result = new ByteArrayOutputStream() val out = new PrintStream(result) @@ -246,6 +254,16 @@ class HelperTest extends FlatSpec with Matchers { result.toString.split(NewLine, -1) shouldBe TestClass2.expectedLongOutput } + it should "not show duplicate entries for singleton objects" in { + val result = new ByteArrayOutputStream() + val out = new PrintStream(result) + val helper = Helper(ClasspathHelper.forClass(DummyObjectThatIsNoCompanion.getClass)) + helper.printMethods("method", out) + println(result) + result.toString.split(NewLine, -1).count(_ == DummyObjectThatIsNoCompanion.expectedMethodLongDescription) shouldBe 1 + } + + "Curried parameters" should "be printed in correct order in the short description" in { val result = new ByteArrayOutputStream() val out = new PrintStream(result) @@ -275,11 +293,7 @@ class HelperTest extends FlatSpec with Matchers { val out = new PrintStream(result) val helper = Helper(DummyObjectThatIsNoCompanion.getClass) helper.printMethods("method", out) - result.toString.split(NewLine, -1) shouldBe Array( - s"${Console.BOLD}method()${Console.RESET} [${DummyObjectThatIsNoCompanion.name}]", - "l", - "" - ) + result.toString.split(NewLine, -1) shouldBe DummyObjectThatIsNoCompanion.expectedLongDescription } it should "not contain $ in their name when short description is printed" in { @@ -287,11 +301,7 @@ class HelperTest extends FlatSpec with Matchers { val out = new PrintStream(result) val helper = Helper(DummyObjectThatIsNoCompanion.getClass) helper.printAllMethods(out) - result.toString.split(NewLine, -1) shouldBe Array( - s"${Console.BOLD}c${Console.RESET} [${DummyObjectThatIsNoCompanion.name}]", - "- method(): s", - "" - ) + result.toString.split(NewLine, -1) shouldBe DummyObjectThatIsNoCompanion.expectedShortDescription } }