Skip to content

Commit

Permalink
scalatest adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
carueda committed Nov 4, 2021
1 parent 46f2ac0 commit 6dadd95
Show file tree
Hide file tree
Showing 8 changed files with 637 additions and 511 deletions.
8 changes: 4 additions & 4 deletions src/test/scala/tscfg/JavaIdentifierSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ class JavaIdentifierSpec extends AnyWordSpec {

List("foo", "bar_3", "$baz") foreach { id =>
s"""keep valid identifier "$id"""" in {
javaIdentifier(id) === id
assert(javaIdentifier(id) === id)
}
}

Random.shuffle(javaKeywords).take(3) foreach { kw =>
s"""convert java keyword "$kw" to "${kw}_"""" in {
javaIdentifier(kw) === kw + "_"
assert(javaIdentifier(kw) === kw + "_")
}
}

List("foo-bar", "foo:bar", "foo#bar") foreach { id =>
s"""replace non java id character with '_': "$id" -> "foo_bar"""" in {
javaIdentifier(id) === "foo_bar"
assert(javaIdentifier(id) === "foo_bar")
}
}

s"""prefix with '_' if first character is valid but not at first position: "21" -> "_21"""" in {
javaIdentifier("21") === "_21"
assert(javaIdentifier("21") === "_21")
}
}
}
94 changes: 48 additions & 46 deletions src/test/scala/tscfg/ModelBuilderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ class ModelBuilderSpec extends AnyWordSpec {
comments: Option[String] = None
): Unit = {
val at = objType.members(memberName)
at.t === t
at.optional === optional
at.default === default
at.comments === comments
assert(at.t === t)
assert(at.optional === optional)
assert(at.default === default)
assert(at.comments === comments)
}

"with empty input" should {
val result = build("")
"build empty ObjectType" in {
result.objectType === ObjectType()
assert(result.objectType === ObjectType())
}
}

Expand Down Expand Up @@ -101,7 +101,7 @@ class ModelBuilderSpec extends AnyWordSpec {
""".stripMargin)

"translate into ListType(INTEGER)" in {
result.objectType.members("my_list").t === ListType(INTEGER)
assert(result.objectType.members("my_list").t === ListType(INTEGER))
}
}

Expand All @@ -111,7 +111,7 @@ class ModelBuilderSpec extends AnyWordSpec {
""".stripMargin)

"translate into ListType(LONG)" in {
result.objectType.members("my_list").t === ListType(LONG)
assert(result.objectType.members("my_list").t === ListType(LONG))
}
}

Expand All @@ -121,7 +121,7 @@ class ModelBuilderSpec extends AnyWordSpec {
""".stripMargin)

"translate into ListType(DOUBLE)" in {
result.objectType.members("my_list").t === ListType(DOUBLE)
assert(result.objectType.members("my_list").t === ListType(DOUBLE))
}
}

Expand All @@ -131,7 +131,7 @@ class ModelBuilderSpec extends AnyWordSpec {
""".stripMargin)

"translate into ListType(BOOLEAN)" in {
result.objectType.members("my_list").t === ListType(BOOLEAN)
assert(result.objectType.members("my_list").t === ListType(BOOLEAN))
}
}

Expand All @@ -142,7 +142,7 @@ class ModelBuilderSpec extends AnyWordSpec {

"translate into ListType(BOOLEAN)" in {
val at = result.objectType.members("optInt")
at.t === INTEGER
assert(at.t === INTEGER)
assert(at.optional)
assert(at.default contains "21")
}
Expand All @@ -155,7 +155,7 @@ class ModelBuilderSpec extends AnyWordSpec {

"translate into DURATION(ms) with given default" in {
val at = result.objectType.members("idleTimeout")
at.t === DURATION(ms)
assert(at.t === DURATION(ms))
assert(at.optional)
assert(at.default contains "75 seconds")
}
Expand Down Expand Up @@ -202,46 +202,48 @@ class ModelBuilderSpec extends AnyWordSpec {
val objType = result.objectType

"build expected objType" in {
objType.members.keySet === Set("foo")
assert(objType.members.keySet === Set("foo"))
val foo = objType.members("foo")
foo.optional === false
assert(foo.optional === false)
assert(foo.default.isEmpty)
assert(foo.comments.isEmpty)
assert(foo.t.isInstanceOf[ObjectType])
val fooObj = foo.t.asInstanceOf[ObjectType]
fooObj.members.keySet === Set(
"reqStr",
"reqInt",
"reqLong",
"reqDouble",
"reqBoolean",
"reqDuration",
"duration_ns",
"duration_µs",
"duration_ms",
"duration_se",
"duration_mi",
"duration_hr",
"duration_dy",
"optStr",
"optInt",
"optLong",
"optDouble",
"optBoolean",
"optDuration",
"dflStr",
"dflInt",
"dflLong",
"dflDouble",
"dflBoolean",
"dflDuration",
"listStr",
"listInt",
"listLong",
"listBoolean",
"listDouble",
"listDuration",
"listDuration_se"
assert(
fooObj.members.keySet === Set(
"reqStr",
"reqInt",
"reqLong",
"reqDouble",
"reqBoolean",
"reqDuration",
"duration_ns",
"duration_µs",
"duration_ms",
"duration_se",
"duration_mi",
"duration_hr",
"duration_dy",
"optStr",
"optInt",
"optLong",
"optDouble",
"optBoolean",
"optDuration",
"dflStr",
"dflInt",
"dflLong",
"dflDouble",
"dflBoolean",
"dflDuration",
"listStr",
"listInt",
"listLong",
"listBoolean",
"listDouble",
"listDuration",
"listDuration_se"
)
)
verify(fooObj, "reqStr", STRING)
verify(fooObj, "reqInt", INTEGER)
Expand Down
24 changes: 13 additions & 11 deletions src/test/scala/tscfg/NamespaceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ class NamespaceSpec extends AnyWordSpec {

"root namespace" should {
"have expected path" in {
root.getPathString === ""
assert(root.getPathString === "")
}

"add and resolve define" in {
root.addDefine("RootDef1", objectType)
assert(root.resolveDefine("RootDef1").isDefined)
root.getAllDefines.keys === Set("RootDef1")
assert(root.getAllDefines.keys === Set("RootDef1"))
}
}

"nested namespace ns00 under root" should {
"have expected path" in {
ns00.getPathString === "ns00"
assert(ns00.getPathString === "ns00")
}

"add and resolve define in own namespace" in {
ns00.addDefine("n00def1", objectType)
assert(ns00.resolveDefine("n00def1").isDefined)

root.getAllDefines.keys === Set("RootDef1", "ns00.n00def1")
assert(root.getAllDefines.keys === Set("RootDef1", "ns00.n00def1"))
}

"resolve define in parent namespace" in {
Expand All @@ -43,17 +43,19 @@ class NamespaceSpec extends AnyWordSpec {

"nested namespace ns000 under ns000" should {
"have expected path" in {
ns000.getPathString === "ns00.ns000"
assert(ns000.getPathString === "ns00.ns000")
}

"add and resolve define in own namespace" in {
ns000.addDefine("n000def1", objectType)
assert(ns000.resolveDefine("n000def1").isDefined)

root.getAllDefines.keys === Set(
"RootDef1",
"ns00.n00def1",
"ns00.ns000.n000def1"
assert(
root.getAllDefines.keys === Set(
"RootDef1",
"ns00.n00def1",
"ns00.ns000.n000def1"
)
)
}
}
Expand All @@ -66,7 +68,7 @@ class NamespaceSpec extends AnyWordSpec {

"nested namespace ns01 under root" should {
"have expected path" in {
ns01.getPathString === "ns01"
assert(ns01.getPathString === "ns01")
}

"not resolve define outside own namespace" in {
Expand All @@ -78,7 +80,7 @@ class NamespaceSpec extends AnyWordSpec {
"all defines" should {
"resolve" in {
val all = root.getAllDefines
all.size === 3
assert(all.size === 3)
assert(all.get("RootDef1") contains objectType)
assert(all.get("ns00.n00def1") contains objectType)
assert(all.get("ns00.ns000.n000def1") contains objectType)
Expand Down
12 changes: 6 additions & 6 deletions src/test/scala/tscfg/generators/java/JavaExampleSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ class JavaExampleSpec extends AnyWordSpec {
val cfg: JavaExampleCfg = new JavaExampleCfg(config)

"capture given required values" in {
cfg.endpoint.path === "/var/www"
cfg.endpoint.intReq === 12
assert(cfg.endpoint.path === "/var/www")
assert(cfg.endpoint.intReq === 12)
}

"capture given optional values" in {
cfg.endpoint.interface_.port === 9191
cfg.endpoint.interface_.`type` === "foo"
assert(cfg.endpoint.interface_.port === 9191)
assert(cfg.endpoint.interface_.`type` === "foo")
}

"capture default values" in {
cfg.endpoint.url === "http://example.net"
cfg.endpoint.serial === null
assert(cfg.endpoint.url === "http://example.net")
assert(cfg.endpoint.serial === null)
}
}

Expand Down
Loading

0 comments on commit 6dadd95

Please sign in to comment.