Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active May 27, 2023 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/76e4bd8b42d4605b418cc3b341a8fcfd to your computer and use it in GitHub Desktop.
Save dacr/76e4bd8b42d4605b418cc3b341a8fcfd to your computer and use it in GitHub Desktop.
Configuration using Typesafe Config / published by https://github.com/dacr/code-examples-manager #2218d7d4-698b-4601-b3b0-4ce774e52d5c/1f39f37439e609b46e0238b1756fead41fbb19e2
// summary : Configuration using Typesafe Config
// keywords : config, typesafe, @testable
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : 2218d7d4-698b-4601-b3b0-4ce774e52d5c
// created-on : 2021-12-22T11:51:23+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.3.0"
//> using dep "org.scalatest::scalatest:3.2.16"
//> using dep "com.typesafe:config:1.4.1"
//> using objectWrapper
// ---------------------
import org.scalatest.*, flatspec.*, matchers.*
import com.typesafe.config.*
class ThatSpec extends AnyFlatSpec with should.Matchers {
override def suiteName = "ThatSpec"
"typesafe config" should "be able to manage boolean values but take care" in {
val config = ConfigFactory.parseString(
"""param-a: true
|param-b: True
|""".stripMargin
)
config.getBoolean("param-a") shouldBe true
intercept[ConfigException.WrongType] {
info("True | False are not booleans from typesafe config point of view, they are strings !")
config.getBoolean("param-b")
}
config.getString("param-a").toBoolean shouldBe true
config.getString("param-b").toBoolean shouldBe true
}
}
org.scalatest.tools.Runner.main(Array("-oDF", "-s", classOf[ThatSpec].getName))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment