-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
metaconfig-tests/shared/src/test/scala/metaconfig/ConfGetSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package metaconfig | ||
|
||
class ConfGetSuite extends munit.FunSuite { | ||
import Conf._ | ||
|
||
test("getNested good") { | ||
val confA = Str("a") | ||
assertEquals(confA.getNested[String](), Configured.Ok("a")) | ||
|
||
val confB = Obj("b" -> confA) | ||
assertEquals(confB.getNested[String]("b"), Configured.Ok("a")) | ||
|
||
val confC = Obj("c" -> confB) | ||
assertEquals(confC.getNested[String]("c", "b"), Configured.Ok("a")) | ||
|
||
val confD = Obj("d" -> confC) | ||
assertEquals(confD.getNested[String]("d", "c", "b"), Configured.Ok("a")) | ||
} | ||
|
||
test("getNested fail") { | ||
val confA = Str("a") | ||
assertEquals( | ||
confA.getNested[Boolean]().toEither.left.get.msg, | ||
"""|Type mismatch; | ||
| found : String (value: "a") | ||
| expected : Bool""".stripMargin | ||
) | ||
|
||
assertEquals( | ||
confA.getNested[Boolean]("c").toEither.left.get.msg, | ||
"""|Type mismatch; | ||
| found : String (value: "a") | ||
| expected : Conf.Obj with key 'c'""".stripMargin | ||
) | ||
|
||
val confB = Obj("b" -> confA) | ||
assertEquals( | ||
confB.getNested[String]("c").toEither.left.get.msg, | ||
"""{"b": "a"} has no field 'c'.""" | ||
) | ||
} | ||
|
||
} |