summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2013-11-15 11:04:09 -0800
committerSom Snytt <som.snytt@gmail.com>2013-11-18 13:39:22 -0800
commit8f20fa23dbb5b000f0889132b8c6e2acfff096b3 (patch)
tree8babddcc8944c37d98c5f0d27948a5f1d5440432 /test
parent02359a09ebb75deee2481d48835d5352b59e1c7e (diff)
downloadscala-8f20fa23dbb5b000f0889132b8c6e2acfff096b3.tar.gz
scala-8f20fa23dbb5b000f0889132b8c6e2acfff096b3.tar.bz2
scala-8f20fa23dbb5b000f0889132b8c6e2acfff096b3.zip
SI-7969 REPL variable columnar output
Extend column formatting to make columns only as wide as their widest element. This is similar to what `ls` does. Given the longest and shortest string, which bound the min and max column count, compute the layout for those possible column counts, and choose the minimal row count and minimal column count. The junit test is under pending because it uses expecty. (Edit: updated without expectytations.) Example that really benefits, witness the skinny columns: ``` scala> math. BigDecimal PartiallyOrdered cosh rint BigInt Pi exp round E ScalaNumber expm1 signum Equiv ScalaNumericAnyConversions floor sin Fractional ScalaNumericConversions hypot sinh IEEEremainder abs log sqrt Integral acos log10 tan LowPriorityEquiv asin log1p tanh LowPriorityOrderingImplicits atan max toDegrees Numeric atan2 min toRadians Ordered cbrt package ulp Ordering ceil pow PartialOrdering cos random ``` more
Diffstat (limited to 'test')
-rw-r--r--test/junit/scala/tools/nsc/interpreter/TabulatorTest.scala44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/interpreter/TabulatorTest.scala b/test/junit/scala/tools/nsc/interpreter/TabulatorTest.scala
index e252942f89..21e338eac0 100644
--- a/test/junit/scala/tools/nsc/interpreter/TabulatorTest.scala
+++ b/test/junit/scala/tools/nsc/interpreter/TabulatorTest.scala
@@ -7,6 +7,7 @@ import org.junit.runner.RunWith
import org.junit.runners.JUnit4
case class Tabby(width: Int = 80, isAcross: Boolean = false, marginSize: Int = 3) extends Tabulator
+case class VTabby(width: Int = 80, isAcross: Boolean = false, marginSize: Int = 3) extends VariColumnTabulator
@RunWith(classOf[JUnit4])
class TabulatorTest {
@@ -38,4 +39,47 @@ class TabulatorTest {
assert(res(1).size == 1) // no trailing empty strings
assert(res(1)(0) startsWith "c")
}
+ // before, two 9-width cols don't fit in 20
+ // but now, 5-col and 9-col do fit.
+ @Test def twolinerVariable() = {
+ val sut = VTabby(width = 20)
+ val items = (1 to 9) map (i => i.toString * i)
+ val rows = sut tabulate items
+ assert(rows.size == 5)
+ assert(rows(0).size == 2)
+ assert(rows(0)(0).size == 8) // width is 55555 plus margin of 3
+ }
+ @Test def sys() = {
+ val sut = VTabby(width = 40)
+ val items = List("BooleanProp", "PropImpl", "addShutdownHook", "error",
+ "process", "CreatorImpl", "ShutdownHookThread", "allThreads",
+ "exit", "props", "Prop", "SystemProperties",
+ "env", "package", "runtime")
+ val rows = sut tabulate items
+ assert(rows.size == 8)
+ assert(rows(0).size == 2)
+ assert(rows(0)(0).size == "ShutdownHookThread".length + sut.marginSize) // 21
+ }
+ @Test def syswide() = {
+ val sut = VTabby(width = 120)
+ val items = List("BooleanProp", "PropImpl", "addShutdownHook", "error",
+ "process", "CreatorImpl", "ShutdownHookThread", "allThreads",
+ "exit", "props", "Prop", "SystemProperties",
+ "env", "package", "runtime")
+ val rows = sut tabulate items
+ assert(rows.size == 2)
+ assert(rows(0).size == 8)
+ assert(rows(0)(0).size == "BooleanProp".length + sut.marginSize) // 14
+ }
+ @Test def resultFits() = {
+ val sut = VTabby(width = 10)
+ // each of two lines would fit, but layout is two cols of width six > 10
+ // therefore, should choose ncols = 1
+ val items = List("a", "bcd",
+ "efg", "h")
+ val rows = sut tabulate items
+ assert(rows.size == 4)
+ assert(rows(0).size == 1)
+ assert(rows(0)(0).size == "efg".length + sut.marginSize) // 6
+ }
}