summaryrefslogtreecommitdiff
path: root/crashboxd/src/test/scala/io/crashbox/ci/yaml
diff options
context:
space:
mode:
Diffstat (limited to 'crashboxd/src/test/scala/io/crashbox/ci/yaml')
-rw-r--r--crashboxd/src/test/scala/io/crashbox/ci/yaml/CompositeReadersSpec.scala26
-rw-r--r--crashboxd/src/test/scala/io/crashbox/ci/yaml/SimpleReadersSpec.scala23
-rw-r--r--crashboxd/src/test/scala/io/crashbox/ci/yaml/YamlSpec.scala40
3 files changed, 89 insertions, 0 deletions
diff --git a/crashboxd/src/test/scala/io/crashbox/ci/yaml/CompositeReadersSpec.scala b/crashboxd/src/test/scala/io/crashbox/ci/yaml/CompositeReadersSpec.scala
new file mode 100644
index 0000000..02a13ca
--- /dev/null
+++ b/crashboxd/src/test/scala/io/crashbox/ci/yaml/CompositeReadersSpec.scala
@@ -0,0 +1,26 @@
+package io.crashbox.ci
+package yaml
+
+import org.scalatest._
+
+class CompositeReadersSpec
+ extends FlatSpec
+ with Matchers
+ with CompositeReaders
+ with SimpleReaders {
+
+ "CompositeReaders" should "convert yaml" in {
+ assert(
+ Yaml.parse("hello: world").convertTo[Map[String, String]] == Map(
+ "hello" -> "world"))
+ assert(
+ Yaml.parse("hello: 42").convertTo[Map[String, Int]] == Map(
+ "hello" -> 42))
+
+ assert(Yaml.parse("- 42").convertTo[Seq[Int]] == Seq(42))
+ assert(
+ Yaml.parse("hello:\n - 42").convertTo[Map[String, Seq[Int]]] == Map(
+ "hello" -> Seq(42)))
+ }
+
+}
diff --git a/crashboxd/src/test/scala/io/crashbox/ci/yaml/SimpleReadersSpec.scala b/crashboxd/src/test/scala/io/crashbox/ci/yaml/SimpleReadersSpec.scala
new file mode 100644
index 0000000..198e921
--- /dev/null
+++ b/crashboxd/src/test/scala/io/crashbox/ci/yaml/SimpleReadersSpec.scala
@@ -0,0 +1,23 @@
+package io.crashbox.ci
+package yaml
+
+import org.scalatest._
+
+class SimpleReadersSpec extends FlatSpec with Matchers with SimpleReaders {
+
+ "SimpleReaders" should "convert yaml" in {
+ assert(Yaml.parse("hello").convertTo[String] == "hello")
+ assert(Yaml.parse("42").convertTo[Byte] == 42.toByte)
+ assert(Yaml.parse("42").convertTo[Short] == 42.toShort)
+ assert(Yaml.parse("42").convertTo[Int] == 42)
+ assert(Yaml.parse("42").convertTo[Long] == 42l)
+ assert(Yaml.parse("42.0").convertTo[Float] == 42f)
+ assert(Yaml.parse("42.0").convertTo[Double] == 42.0)
+ assert(Yaml.parse("true").convertTo[Boolean] == true)
+ assert(Yaml.parse("false").convertTo[Boolean] == false)
+ }
+
+ "SimpleReaders" should "fail to convert invalid yaml" in {
+ intercept[YamlFormatException](Yaml.parse("foo").convertTo[Boolean])
+ }
+}
diff --git a/crashboxd/src/test/scala/io/crashbox/ci/yaml/YamlSpec.scala b/crashboxd/src/test/scala/io/crashbox/ci/yaml/YamlSpec.scala
new file mode 100644
index 0000000..6d1de66
--- /dev/null
+++ b/crashboxd/src/test/scala/io/crashbox/ci/yaml/YamlSpec.scala
@@ -0,0 +1,40 @@
+package io.crashbox.ci
+package yaml
+
+import org.scalatest._
+
+class YamlSpec extends FlatSpec with Matchers {
+
+ val yml = """|---
+ |foo: bar
+ |buz: qux
+ |list:
+ | - elem1
+ | - elem2
+ |map:
+ | elem1: foo
+ | elem2: bar
+ | elem3:
+ |""".stripMargin
+
+ val tree = YamlMap(
+ Map(
+ "foo" -> YamlString("bar"),
+ "buz" -> YamlString("qux"),
+ "list" -> YamlSeq(
+ Seq(
+ YamlString("elem1"),
+ YamlString("elem2")
+ )),
+ "map" -> YamlMap(
+ Map(
+ "elem1" -> YamlString("foo"),
+ "elem2" -> YamlString("bar"),
+ "elem3" -> YamlString("")
+ ))
+ ))
+
+ "Yaml" should "parse valid yaml" in {
+ assert(Yaml.parse(yml) == tree)
+ }
+}