Skip to content

Commit

Permalink
Merge pull request #10 from ivanfrolovmd/add-guards
Browse files Browse the repository at this point in the history
Add guards
  • Loading branch information
ivanfrolovmd committed Jul 29, 2018
2 parents 1f3a69a + b0c439d commit aade792
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ allprojects {
}
dependencies {
compile 'com.github.ivanfrolovmd:asciitable:0.0.7'
compile 'com.github.ivanfrolovmd:asciitable:0.0.8'
}
```

Expand All @@ -129,12 +129,12 @@ dependencies {
<dependency>
<groupId>com.github.ivanfrolovmd</groupId>
<artifactId>asciitable</artifactId>
<version>0.0.7</version>
<version>0.0.8</version>
</dependency>
```

### SBT
```
resolvers += "jitpack" at "https://jitpack.io"
libraryDependencies += "com.github.ivanfrolovmd" % "asciitable" % "0.0.7"
libraryDependencies += "com.github.ivanfrolovmd" % "asciitable" % "0.0.8"
```
8 changes: 4 additions & 4 deletions src/main/scala/io/github/asciitable/AsciiTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ final class AsciiTable {
def rows(rows: TraversableOnce[TraversableOnce[String]]): AsciiTable = { streamBuilder ++= rows.map(_.toSeq); this }

// configuration
def width(value: Int): AsciiTable = { width = Some(value); this }
def width(value: Int): AsciiTable = { require(value >= 5); width = Some(value); this }
def multiline(value: Boolean): AsciiTable = { multiline = value; this }
def emptyMessage(value: String): AsciiTable = { emptyMessage = value; this }
def rowMaxHeight(value: Int): AsciiTable = { rowMaxHeight = value; this }
def columnMinWidth(value: Int): AsciiTable = { columnMinWidth = value; this }
def sampleAtMostRows(value: Int): AsciiTable = { sampleRows = value; this }
def rowMaxHeight(value: Int): AsciiTable = { require(value > 0); rowMaxHeight = value; this }
def columnMinWidth(value: Int): AsciiTable = { require(value > 0); columnMinWidth = value; this }
def sampleAtMostRows(value: Int): AsciiTable = { require(value > 0); sampleRows = value; this }
def useAscii(value: Boolean): AsciiTable = { chars = if (value) Ascii else Unicode; this }

private lazy val rows = streamBuilder.result()
Expand Down
25 changes: 25 additions & 0 deletions src/test/scala/io/github/asciitable/AsciiTableTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,30 @@ class AsciiTableTest extends FreeSpec with Matchers {
|╚═╧═════╧═╧══╛→
|""".stripMargin
}

"should render arrows when the width is too small" in {
AsciiTable()
.width(5)
.row("one", "two", "three")
.row("one", "two", "three")
.row("one", "two", "three")
.toString shouldBe
"""╔═╕→
|║o│→
|║n│→
|║e│→
|╟─┤→
|║o│→
|║n│→
|║e│→
|╟─┤→
|║o│→
|║n│→
|║e│→
|╚═╛→
|""".stripMargin

assertThrows[IllegalArgumentException](AsciiTable().width(4))
}
}
}

0 comments on commit aade792

Please sign in to comment.