Skip to content

Commit

Permalink
Additional test & Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardpeters committed Sep 16, 2024
1 parent d788cf3 commit c92d497
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@ largerExample =
, age = 1006
, honesty = False
}


type NestedUnion
= First (Maybe Int) String (List Int)
| Second String
| Third


defaultUnion : NestedUnion
defaultUnion =
First Nothing "" []
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,23 @@ object DefaultsTestingSpec extends MorphirBaseSpec {
test("Record matches Default") {
ZIO.serviceWithZIO[(Distribution, TypedMorphirRuntime)] { (dist, rt) =>
for {
res <- rt.evaluate(qn"Defaults:Defaults:expectedDefault")
expected <- rt.evaluate(qn"Defaults:Defaults:expectedDefault")
.provideEnvironment(MorphirEnv.live)
.toZIOWith(RTExecutionContext.typeChecked)
concept <- getConcept(qn"Defaults:Defaults:DefaultRecord")
default <- ZIO.fromEither(concept.defaultData())
} yield assertTrue(res == default)
actual <- ZIO.fromEither(concept.defaultData())
} yield assertTrue(actual == expected)
}
},
test("Record doesn't match non-default") {
test("Enum matches") {
ZIO.serviceWithZIO[(Distribution, TypedMorphirRuntime)] { (dist, rt) =>
for {
res <- rt.evaluate(qn"Defaults:Defaults:nonDefault")
expected <- rt.evaluate(qn"Defaults:Defaults:defaultUnion")
.provideEnvironment(MorphirEnv.live)
.toZIOWith(RTExecutionContext.typeChecked)
concept <- getConcept(qn"Defaults:Defaults:DefaultRecord")
default <- ZIO.fromEither(concept.defaultData())
} yield assertTrue(res != default)
concept <- getConcept(qn"Defaults:Defaults:NestedUnion")
actual <- ZIO.fromEither(concept.defaultData())
} yield assertTrue(actual == expected)
}
}
// test("Record can be filled with defaults") {
Expand Down
2 changes: 1 addition & 1 deletion morphir/src/org/finos/morphir/datamodel/Concept.scala
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ object Concept {
val firstCase = concept.cases.head
for {
args <- collectAll(firstCase.fields, (label: EnumLabel, concept: Concept) => default(concept).map((label, _)))
res = Data.Case(args, firstCase.label.toString(), concept)
res = Data.Case(args, firstCase.label.value, concept)
} yield res
}
def defaultInt64: DefaultEither = Right(Data.Int64(0))
Expand Down

0 comments on commit c92d497

Please sign in to comment.