Skip to content

Commit

Permalink
Wrote tests for hyphenated switches.
Browse files Browse the repository at this point in the history
  • Loading branch information
dave4420 committed Mar 24, 2011
1 parent 0fed867 commit 52f52a9
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/test/scala/switches-with-hyphens.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import org.scalatest.FunSuite
import org.scalatest.matchers.ShouldMatchers


class SpacedStubApp extends optional.Application {
var spaced: Option[String] = _
var unspaced: Option[String] = _
var args: List[String] = _

def main (switchlikethis: Option[String], switch_like_this: Option[String]) = {
spaced = switch_like_this
unspaced = switchlikethis
args = getArgs()
}
}


class SpacedTestSuite extends FunSuite with ShouldMatchers {
var app: SpacedStubApp = _

def generally (commandLine: Array[String], desiredSpaced: Option[String], desiredUnspaced: Option[String]) = {
app = new SpacedStubApp
app.main(commandLine)
app.args should equal (List())
app.spaced should equal (desiredSpaced)
app.unspaced should equal (desiredUnspaced)
app = new SpacedStubApp
app.main (Array.concat (commandLine, Array("trailing")))
app.args should equal (List("trailing"))
app.spaced should equal (desiredSpaced)
app.unspaced should equal (desiredUnspaced)
app = new SpacedStubApp
app.main (Array.concat (Array("leading"), commandLine))
app.args should equal (List("leading"))
app.spaced should equal (desiredSpaced)
app.unspaced should equal (desiredUnspaced)
}

test ("no switches works") {
generally (Array(), None, None)
}

test ("unspaced switch only works") {
generally (Array ("--switchlikethis", "cabbage"), None, Some("cabbage"))
}

test ("underscored switch only works") {
generally (Array ("--switch_like_this", "fruit"), Some("fruit"), None)
}

test ("unspaced and underscored switches works") {
generally (Array ("--switchlikethis", "blaze", "--switch_like_this", "pool"), Some("pool"), Some("blaze"))
}

test ("hyphenated switch only works") {
generally (Array ("--switch-like-this", "vegetable"), Some("vegetable"), None)
}

test ("hyphenated and underscored switches works") {
generally (Array ("--switchlikethis", "blaze", "--switch-like-this", "onion"), Some("onion"), Some("blaze"))
}
}

0 comments on commit 52f52a9

Please sign in to comment.