generated from finos/software-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Construct enum variant from ordinal, not Java Class[T]
- Loading branch information
1 parent
4b3f795
commit f9fa34d
Showing
4 changed files
with
74 additions
and
34 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
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
47 changes: 47 additions & 0 deletions
47
morphir/test/src-3/org/finos/morphir/datamodel/ToDataEnumsSimple.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,47 @@ | ||
package org.finos.morphir.datamodel | ||
|
||
import org.finos.morphir.datamodel.{*, given} | ||
import org.finos.morphir.datamodel.Concept.Enum | ||
import org.finos.morphir.datamodel.Data | ||
import org.finos.morphir.datamodel.Data.Case | ||
import org.finos.morphir.datamodel.Util.* | ||
import org.finos.morphir.datamodel.namespacing.* | ||
import org.finos.morphir.datamodel.namespacing.PackageName.root | ||
import org.finos.morphir.datamodel.namespacing.Namespace.ns | ||
|
||
object EnumData4 { | ||
import EnumGns._ | ||
implicit val gnsImpl: GlobalDatamodelContext = new GlobalDatamodelContext { | ||
def value = gns | ||
} | ||
|
||
enum Foo { | ||
case Bar | ||
case Baz | ||
} | ||
|
||
val deriver = Deriver.gen[Foo] | ||
} | ||
|
||
class ToDataEnumsSimple extends munit.FunSuite { | ||
import EnumGns._ | ||
|
||
val concept = | ||
Enum( | ||
gns :: ("Foo"), | ||
Enum.Case(l"Bar"), | ||
Enum.Case(l"Baz") | ||
) | ||
|
||
test("Enum Data 4") { | ||
import EnumData4._ | ||
assertEquals(deriver.derive(Foo.Bar), Case()("Bar", concept)) | ||
} | ||
|
||
test("Enum Data 4.1") { | ||
import EnumData4._ | ||
interceptMessage[IllegalArgumentException]("The value `null` is not an instance of the needed enum class Foo") { | ||
deriver.derive(null) | ||
} | ||
} | ||
} |