Skip to content

Commit

Permalink
add tests, rm dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-williams committed Dec 4, 2017
1 parent 24cc3a5 commit 02ea6b5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
8 changes: 0 additions & 8 deletions io/src/main/scala/org/hammerlab/io/print/Level.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package org.hammerlab.io.print

case class Level(var v: Int) {
def unary_+ : Level = { v += 1; this }
def unary_- : Level = { v -= 1; this }
def ++ : Level = { v += 1; this }
def -- : Level = { v -= 1; this }
def apply[T](fn: T): T = {
++
val t = fn
--
t
}
}

object Level {
Expand Down
6 changes: 3 additions & 3 deletions io/src/main/scala/org/hammerlab/io/print/Printer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import hammerlab.show._
/**
* Interface for writing [[Line]]s with configurable indentation levels
*/
abstract class Printer
trait Printer
extends Closeable {

protected def showLine(line: Line): Unit

implicit val level = Level(0)

/**
* Aliases for underlying [[apply]]
*
Expand All @@ -26,8 +28,6 @@ abstract class Printer
l2: Lines,
rest: Lines*): Unit = apply(l1, l2, rest)

implicit val level = Level(0)

def ind(fn: Unit): Unit = {
level++;
fn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package org.hammerlab.io.print

import hammerlab.print._
import hammerlab.show._
import org.hammerlab.io.print.Test._
import org.hammerlab.io.print.ToLinesTest._
import org.hammerlab.test.Suite

class Test
class ToLinesTest
extends Suite {
test("tab") {
test("nested indents") {
import hammerlab.indent.implicits.tab
Foos(
111,
Expand All @@ -25,14 +25,25 @@ class Test
.stripMargin
)
}

test("generic") {
implicit val indent = hammerlab.indent.spaces.four
Pair(111, "aaa").showLines should be(
"""Pair(
| 111
| aaa
|)"""
.stripMargin
)
}
}

object Test {
object ToLinesTest {

/**
* Example coproduct that wraps an [[Int]] ([[Num]]) or a recursive collection of [[Foo]]s ([[Foos]])
*
* Used to demonstrate a [[cats.Show]] implementation with progressive levels of indentation; see [[Foos.showFoos]]
* Used to demonstrate a [[ToLines]] implementation with progressive levels of indentation; see [[Foos.toLines]]
*/
sealed trait Foo
object Foo {
Expand All @@ -46,13 +57,15 @@ object Test {

case class Foos(foos: Foo*) extends Foo
object Foos {
implicit val showFoos: ToLines[Foos] =
implicit val toLines: ToLines[Foos] =
ToLines[Foos] {
case Foos(foos @ _*)
foos map {
case foos: Foos showFoos.apply(foos).indent
case foos: Foos toLines(foos).indent
case Num(n) Lines(n.show)
}
}
}

case class Pair(n: Int, s: String)
}

0 comments on commit 02ea6b5

Please sign in to comment.