Skip to content

Commit

Permalink
#5 rename NEWLINE constant to NewLine
Browse files Browse the repository at this point in the history
  • Loading branch information
FRosner committed Jan 19, 2016
1 parent 4b763ea commit d3633f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/main/scala/de/frosner/replhelper/Helper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.reflections.util.{ClasspathHelper, ConfigurationBuilder}

import scala.collection.JavaConversions

import Helper.NEWLINE
import Helper.NewLine

/**
* Utility class to provide interactive help for methods that are annotated with @Help.
Expand Down Expand Up @@ -55,11 +55,11 @@ class Helper private (val reflections: Reflections, val filter: Class[_] => Bool
def printAllMethods(out: PrintStream) = out.println(
methods.map {
case ((className, category), categoryMethods) => {
s"${Console.BOLD}${category}${Console.RESET} [$className]" + NEWLINE + categoryMethods.map {
s"${Console.BOLD}${category}${Console.RESET} [$className]" + NewLine + categoryMethods.map {
case (method, help) => "- " + getMethodSignature(method, help) + s": ${help.shortDescription}"
}.mkString(NEWLINE)
}.mkString(NewLine)
}
}.mkString(NEWLINE+NEWLINE)
}.mkString(NewLine+NewLine)
)

private def getMethodSignature(method: Method, help: Help) = {
Expand Down Expand Up @@ -92,21 +92,21 @@ 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)
}.mkString(NewLine+NewLine)
)
}

private def getLongDescriptionPrintable(methodWithHelp: ((String, String), Method, Help), out: PrintStream) = {
val ((className, category), method, help) = methodWithHelp
s"${Console.BOLD}${getMethodSignature(method, help)}${Console.RESET} [$className]" + NEWLINE + help.longDescription
s"${Console.BOLD}${getMethodSignature(method, help)}${Console.RESET} [$className]" + NewLine + help.longDescription
}

}


object Helper {

private[replhelper] val NEWLINE = System.getProperty("line.separator")
private[replhelper] val NewLine = System.getProperty("line.separator")

/**
* Factory method to provide interactive help for methods of a given class. It scans the class method definitions for
Expand Down
18 changes: 9 additions & 9 deletions src/test/scala/de/frosner/replhelper/HelperTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.io.{ByteArrayOutputStream, PrintStream}

import org.reflections.util.ClasspathHelper
import org.scalatest.{FlatSpec, Matchers}
import Helper.NEWLINE
import Helper.NewLine

class HelperTest extends FlatSpec with Matchers {

Expand Down Expand Up @@ -214,23 +214,23 @@ class HelperTest extends FlatSpec with Matchers {
val out = new PrintStream(result)
val helper = Helper(classOf[TestClass])
helper.printAllMethods(out)
result.toString.split(NEWLINE, -1) shouldBe TestClass.expectedShortOutput
result.toString.split(NewLine, -1) shouldBe TestClass.expectedShortOutput
}

it should "show the short description for multiple classes" in {
val result = new ByteArrayOutputStream()
val out = new PrintStream(result)
val helper = Helper(classOf[TestClass], classOf[TestClass2])
helper.printAllMethods(out)
result.toString.split(NEWLINE, -1) shouldBe TestClass.expectedShortOutput ++ TestClass2.expectedShortOutput
result.toString.split(NewLine, -1) shouldBe TestClass.expectedShortOutput ++ TestClass2.expectedShortOutput
}

"When specific methods are requested, it" should "show the long description" in {
val result = new ByteArrayOutputStream()
val out = new PrintStream(result)
val helper = Helper(classOf[TestClass])
helper.printMethods("help", out)
result.toString.split(NEWLINE, -1) shouldBe Array(
result.toString.split(NewLine, -1) shouldBe Array(
s"${Console.BOLD}help()${Console.RESET} [${TestClass.name}]",
"long help",
""
Expand All @@ -243,15 +243,15 @@ class HelperTest extends FlatSpec with Matchers {
val helper = Helper(classOf[TestClass2])
helper.printMethods("method", out)
println(result.toString)
result.toString.split(NEWLINE, -1) shouldBe TestClass2.expectedLongOutput
result.toString.split(NewLine, -1) shouldBe TestClass2.expectedLongOutput
}

"Curried parameters" should "be printed in correct order in the short description" in {
val result = new ByteArrayOutputStream()
val out = new PrintStream(result)
val helper = Helper(classOf[TestClass3])
helper.printAllMethods(out)
result.toString.split(NEWLINE, -1) shouldBe Array(
result.toString.split(NewLine, -1) shouldBe Array(
s"${Console.BOLD}category${Console.RESET} [${TestClass3.name}]",
"- method(1)(2)(3)(4)(5)(6)(7)(8)(9): short",
""
Expand All @@ -263,7 +263,7 @@ class HelperTest extends FlatSpec with Matchers {
val out = new PrintStream(result)
val helper = Helper(classOf[TestClass3])
helper.printMethods("method", out)
result.toString.split(NEWLINE, -1) shouldBe Array(
result.toString.split(NewLine, -1) shouldBe Array(
s"${Console.BOLD}method(1)(2)(3)(4)(5)(6)(7)(8)(9)${Console.RESET} [${TestClass3.name}]",
"long",
""
Expand All @@ -275,7 +275,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(
result.toString.split(NewLine, -1) shouldBe Array(
s"${Console.BOLD}method()${Console.RESET} [${DummyObjectThatIsNoCompanion.name}]",
"l",
""
Expand All @@ -287,7 +287,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(
result.toString.split(NewLine, -1) shouldBe Array(
s"${Console.BOLD}c${Console.RESET} [${DummyObjectThatIsNoCompanion.name}]",
"- method(): s",
""
Expand Down

0 comments on commit d3633f3

Please sign in to comment.