Skip to content

Commit

Permalink
Adding more testing (#297)
Browse files Browse the repository at this point in the history
* Adding more tests

* Adding extranames
  • Loading branch information
michelchan authored Sep 25, 2024
1 parent 2753034 commit c4f2747
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 12 deletions.
4 changes: 4 additions & 0 deletions morphir/src/org/finos/morphir/lang/elm/ElmDependencyMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ object ElmDependencyMap extends Subtype[Map[ElmPackageName, ElmPackageVersion]]:
subtypeCodec[Map[ElmPackageName, ElmPackageVersion], ElmDependencyMap]

def fromMap(map: Map[ElmPackageName, ElmPackageVersion]): ElmDependencyMap = unsafeMake(map)

def apply(elems: (ElmPackageName, ElmPackageVersion)*): ElmDependencyMap =
fromMap(Map.from(elems))

end ElmDependencyMap
15 changes: 11 additions & 4 deletions morphir/src/org/finos/morphir/lang/elm/project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ object ElmProject extends ConfigCompanion[ElmProject]:
case _ => Configured.error("Expected an object")
}

given confEncoder: ConfEncoder[ElmProject] = new ConfEncoder[ElmProject] {
def write(project: ElmProject): Conf = project match
case app: ElmApplication =>
ElmApplication.confEncoder.write(app)
case pack: ElmPackage => ElmPackage.confEncoder.write(pack)
}

final case class ElmApplication(
@ExtraName("source-directories") override val sourceDirectories: List[String],
@ExtraName("elm-version") elmVersion: SemVerString,
Expand All @@ -59,13 +66,13 @@ object ElmProject extends ConfigCompanion[ElmProject]:
end ElmApplication

final case class ElmPackage(
name: ElmPackageName,
@ExtraName("name") name: ElmPackageName,
summary: Option[String],
version: ElmPackageVersion,
elmVersion: String,
exposedModules: List[ElmModuleName],
@ExtraName("elm-version") elmVersion: String,
@ExtraName("exposed-modules") exposedModules: List[ElmModuleName],
dependencies: Map[String, String],
testDependencies: Map[String, String]
@ExtraName("test-dependencies") testDependencies: Map[String, String]
) extends ElmProject

object ElmPackage:
Expand Down
89 changes: 81 additions & 8 deletions morphir/test/src/org/finos/morphir/lang/elm/ElmProjectSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ package org.finos.morphir.lang.elm

import org.finos.morphir.testing.{MorphirKyoSpecDefault, MorphirSpecDefault}
import kyo.*
import metaconfig.{Conf, ConfDecoder, ConfEncoder, Configured, Input}
import org.finos.morphir.NonNegativeInt
import metaconfig.{Conf, Configured, Input}
import zio.test.*
import zio.test.Assertion.*
import org.finos.morphir.config.*
import org.finos.morphir.lang.elm.ElmProjectSpec.{compileError, test}
import org.finos.morphir.api.MajorVersionNumber
import org.finos.morphir.api.MinorVersionNumber
import org.finos.morphir.api.PatchVersionNumber
import org.finos.morphir.api.{MajorVersionNumber, MinorVersionNumber, PatchVersionNumber, SemVerString}

object ElmProjectSpec extends MorphirSpecDefault {
def spec = suite("ElmProjectSuite")(
Expand All @@ -22,15 +18,92 @@ object ElmProjectSpec extends MorphirSpecDefault {
)

private def elmProjectSuite =
// import ElmApplication.given

suite("ElmProjectSpec")(
test("should be able to read an application elm.json file") {
val workspaceFilePath = os.resource / "org" / "finos" / "morphir" / "lang" / "elm" / "application" / "elm.json"
val contents: String = os.read(workspaceFilePath)
val input: metaconfig.Input = Input.String(contents)
val actual = ElmProject.parseInput(input)
assertTrue(actual.isInstanceOf[kyo.Result.Success[ElmProject]])
},
test("should be able to create an application elm.json file") {
val app = ElmProject.ElmApplication(
List("sourceOne", "sourceTwo"),
SemVerString("v0.0.2"),
ElmApplicationDependencies(
ElmDependencyMap(ElmPackageName("author/direct") -> ElmPackageVersion.default),
ElmDependencyMap(ElmPackageName("author/indirect") -> ElmPackageVersion.default)
),
ElmApplicationDependencies(
ElmDependencyMap(ElmPackageName("author/direct2") -> ElmPackageVersion.default),
ElmDependencyMap(ElmPackageName("author/indirect2") -> ElmPackageVersion.default)
)
)
val result = ElmProject.confEncoder.write(app)
assertTrue(
result ==
Conf.Obj(
"sourceDirectories" -> Conf.Lst(Conf.Str("sourceOne"), Conf.Str("sourceTwo")),
"elmVersion" -> Conf.Str("v0.0.2"),
"dependencies" -> Conf.Obj(
"direct" -> Conf.Obj(
"author/direct" -> Conf.Str("0.0.1")
),
"indirect" -> Conf.Obj(
"author/indirect" -> Conf.Str("0.0.1")
)
),
"testDependencies" -> Conf.Obj(
"direct" -> Conf.Obj(
"author/direct2" -> Conf.Str("0.0.1")
),
"indirect" -> Conf.Obj(
"author/indirect2" -> Conf.Str("0.0.1")
)
)
)
)
},
test("should be able to read an package elm.json file") {
val workspaceFilePath = os.resource / "org" / "finos" / "morphir" / "lang" / "elm" / "elm-package" / "elm.json"
val contents: String = os.read(workspaceFilePath)
val input: metaconfig.Input = Input.String(contents)
val actual = ElmProject.parseInput(input)
assertTrue(actual.isInstanceOf[kyo.Result.Success[ElmProject]])
} @@ TestAspect.ignore, // TODO: doesn't match the field names in file
test("should be able to create a package elm.json file") {
val pack = ElmProject.ElmPackage(
ElmPackageName("author/package"),
None,
ElmPackageVersion.default,
"0.19.0 <= v < 0.20.0",
List(
ElmModuleName("Morphir.SDK.Decimal"),
ElmModuleName("Morphir.SDK.String")
),
Map("elm/pack" -> "0.1.0 <= v < 0.2.0"),
Map("test/pack" -> "4.2.0 <= v < 5.0.0")
)
val result = ElmProject.confEncoder.write(pack)
assertTrue(
result ==
Conf.Obj(
"name" -> Conf.Str("author/package"),
"summary" -> Conf.Null(),
"version" -> Conf.Str("0.0.1"),
"elmVersion" -> Conf.Str("0.19.0 <= v < 0.20.0"),
"exposedModules" -> Conf.Lst(
Conf.Str("Morphir.SDK.Decimal"),
Conf.Str("Morphir.SDK.String")
),
"dependencies" -> Conf.Obj(
"elm/pack" -> Conf.Str("0.1.0 <= v < 0.2.0")
),
"testDependencies" -> Conf.Obj(
"test/pack" -> Conf.Str("4.2.0 <= v < 5.0.0")
)
)
)
}
)

Expand Down

0 comments on commit c4f2747

Please sign in to comment.