From a13f2dece099b450127bb97281a9489e01779c5f Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Tue, 8 Jul 2014 14:22:05 +0200 Subject: add tests for the current state --- build.sbt | 2 ++ .../scala/spray/boilerplate/GeneratorSpecs.scala | 34 ++++++++++++++++++++++ .../spray/boilerplate/TemplateParserSpecs.scala | 26 +++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/test/scala/spray/boilerplate/GeneratorSpecs.scala create mode 100644 src/test/scala/spray/boilerplate/TemplateParserSpecs.scala 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"))) + } + } +} -- cgit v1.2.3