Skip to content

Commit

Permalink
align SConfig2ClassSuite with TypesafeConfig2ClassSuite
Browse files Browse the repository at this point in the history
  • Loading branch information
github-brice-jaglin committed May 26, 2021
1 parent b414085 commit 8b62638
Showing 1 changed file with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package metaconfig.sconfig
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
import metaconfig.Conf
import metaconfig.{Conf, Position}

class SConfig2ClassSuite extends munit.FunSuite {
test("basic") {
Expand Down Expand Up @@ -50,4 +50,54 @@ class SConfig2ClassSuite extends munit.FunSuite {
)
assertEquals(obtained, expected)
}

test("include") {
val dir = Files.createTempDirectory("include")

val main = dir.resolve("main.conf")
Files.write(
main,
"""|a = [ 1 ]
|include "included.conf"
|c = bar
|""".stripMargin.getBytes()
)

val included = dir.resolve("included.conf")
Files.write(
included,
s"""|a = $${a} [
| "2",
| 3,
| true
|]
|b = foo
|""".stripMargin.getBytes()
)

val obtained = SConfig2Class.gimmeConfFromFile(main.toFile).get
val expected: Conf = Conf.Obj(
"a" -> Conf.Lst(
Conf.Num(1),
Conf.Str("2"),
Conf.Num(3),
Conf.Bool(true)
),
"b" -> Conf.Str("foo"),
"c" -> Conf.Str("bar")
)
assertEquals(obtained, expected)

val obtainedObj = obtained.asInstanceOf[Conf.Obj]

// declaration spread between main file and included file -> unknown position
val aPos = obtainedObj.field("a").get.pos
assertEquals(aPos, Position.None: Position)

val bPos = obtainedObj.field("b").get.pos
assertEquals(bPos.lineContent, "b = foo")

val cPos = obtainedObj.field("c").get.pos
assertEquals(cPos.lineContent, "c = bar")
}
}

0 comments on commit 8b62638

Please sign in to comment.