diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-11-25 14:46:38 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-11-25 14:46:38 -0800 |
commit | 7a1a160d8ba2d1c2a8d71453978ac8e4d3838f06 (patch) | |
tree | fb62a71b049ab221e22fd3595c460569888c329d /test/junit | |
parent | 84c096762b0cd24184bea1567a033f07909f5cff (diff) | |
parent | 8f20fa23dbb5b000f0889132b8c6e2acfff096b3 (diff) | |
download | scala-7a1a160d8ba2d1c2a8d71453978ac8e4d3838f06.tar.gz scala-7a1a160d8ba2d1c2a8d71453978ac8e4d3838f06.tar.bz2 scala-7a1a160d8ba2d1c2a8d71453978ac8e4d3838f06.zip |
Merge pull request #3147 from som-snytt/issue/repl-columns
SI-7969 REPL -C columnar output
Diffstat (limited to 'test/junit')
-rw-r--r-- | test/junit/scala/tools/nsc/interpreter/TabulatorTest.scala | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/interpreter/TabulatorTest.scala b/test/junit/scala/tools/nsc/interpreter/TabulatorTest.scala new file mode 100644 index 0000000000..21e338eac0 --- /dev/null +++ b/test/junit/scala/tools/nsc/interpreter/TabulatorTest.scala @@ -0,0 +1,85 @@ +package scala.tools.nsc +package interpreter + +//import org.junit.Assert._ +import org.junit.Test +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 { + + @Test def oneliner() = { + val sut = Tabby() + val items = List("a", "b", "c") + val res = sut tabulate items + assert(res.size == 1) + assert(res(0).size == 1) + assert(res(0)(0) startsWith "a") + assert(res(0)(0) endsWith "c") + } + @Test def twoliner() = { + val sut = Tabby(width = 40) + val items = List("a" * 15, "b" * 15, "c" * 15) + val res = sut tabulate items + assert(res.size == 2) + assert(res(0).size == 2) + assert(res(1).size == 2) // trailing empty strings + assert(res(1)(0) startsWith "b") + } + @Test def twolinerx() = { + val sut = Tabby(width = 40, isAcross = true) + val items = List("a" * 15, "b" * 15, "c" * 15) + val res = sut tabulate items + assert(res.size == 2) + assert(res(0).size == 2) + 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 + } +} |