aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Rudolph <johannes.rudolph@gmail.com>2014-07-08 14:22:05 +0200
committerJohannes Rudolph <johannes.rudolph@gmail.com>2014-07-08 14:22:05 +0200
commita13f2dece099b450127bb97281a9489e01779c5f (patch)
tree8c4691597b97227fef81082410b44b325dc9cd41
parentd9ecb3358e08d8bb41eb33a166f90c4459d94cc3 (diff)
downloadsbt-boilerplate-a13f2dece099b450127bb97281a9489e01779c5f.tar.gz
sbt-boilerplate-a13f2dece099b450127bb97281a9489e01779c5f.tar.bz2
sbt-boilerplate-a13f2dece099b450127bb97281a9489e01779c5f.zip
add tests for the current state
-rw-r--r--build.sbt2
-rw-r--r--src/test/scala/spray/boilerplate/GeneratorSpecs.scala34
-rw-r--r--src/test/scala/spray/boilerplate/TemplateParserSpecs.scala26
3 files changed, 62 insertions, 0 deletions
diff --git a/build.sbt b/build.sbt
index f3feaf5..2c1efcc 100644
--- a/build.sbt
+++ b/build.sbt
@@ -39,3 +39,5 @@ seq(lsSettings :_*)
(LsKeys.docsUrl in LsKeys.lsync) <<= homepage
crossBuildingSettings
+
+libraryDependencies += "org.specs2" %% "specs2" % "2.3.13" % "test"
diff --git a/src/test/scala/spray/boilerplate/GeneratorSpecs.scala b/src/test/scala/spray/boilerplate/GeneratorSpecs.scala
new file mode 100644
index 0000000..7651398
--- /dev/null
+++ b/src/test/scala/spray/boilerplate/GeneratorSpecs.scala
@@ -0,0 +1,34 @@
+package spray.boilerplate
+
+import org.specs2.mutable.Specification
+
+class GeneratorSpecs extends Specification {
+ "Generation" should {
+ "keep outer template unchanged" in {
+ gen4("a1b2c3d4") === "a1b2c3d4" pendingUntilFixed
+ }
+ "inflate 1 in expansion" in {
+ gen4("[#a1#]") === "a1, a2, a3, a4"
+ }
+ "inflate 0 in expansion" in {
+ gen4("[#a0#]") === "a0, a1, a2, a3"
+ }
+ "inflate 2 in expansion" in {
+ gen4("[#a2#]") === "a2, a3, a4, a5"
+ }
+ "encode sharp" in {
+ gen4("[#a#1#]") === "a#1, a#2, a#3, a#4" pendingUntilFixed
+ }
+ "don't inflate when quoted in expansion" in {
+ gen4("[#a1 ##1#]") === "a1 1, a2 1, a3 1, a4 1"
+ }
+ "inflate inner" in {
+ gen4("[#a1([#T1#])#]") === "a1(T1), a2(T1, T2), a3(T1, T2, T3), a4(T1, T2, T3, T4)"
+ }
+ "support custom separator" in {
+ gen4("[#a1#.]") === "a1.a2.a3.a4"
+ }
+ }
+
+ def gen4(template: String): String = Generator.generateFromTemplate(template, 4)
+}
diff --git a/src/test/scala/spray/boilerplate/TemplateParserSpecs.scala b/src/test/scala/spray/boilerplate/TemplateParserSpecs.scala
new file mode 100644
index 0000000..063eaa0
--- /dev/null
+++ b/src/test/scala/spray/boilerplate/TemplateParserSpecs.scala
@@ -0,0 +1,26 @@
+package spray.boilerplate
+
+import org.specs2.mutable.Specification
+
+class TemplateParserSpecs extends Specification {
+ import TemplateParser.parse
+
+ "TemplateParser.parse" should {
+ "without expansion" in {
+ parse("abc") === FixedString("abc") pendingUntilFixed
+ }
+
+ "just expansion" in {
+ parse("[# def #]") === Expand(LiteralString(" def "), ", ") pendingUntilFixed
+ }
+
+ "multiple expansions" in {
+ parse("[#a#]abc[#b#]") ===
+ Sequence(List(Expand(LiteralString("a"), ", "), FixedString("abc"), Expand(LiteralString("b"), ", "))) pendingUntilFixed
+ }
+
+ "one surrounded expansion" in {
+ parse("abc[#a#]def") === Sequence(List(FixedString("abc"), Expand(LiteralString("a"), ", "), FixedString("def")))
+ }
+ }
+}