Skip to content

Commit

Permalink
Merge pull request #194 from nikitaDanilenko/193-fix-elm-encoder-for-…
Browse files Browse the repository at this point in the history
…lists

Issue 193 - Fix Elm encoder for lists
  • Loading branch information
pvillega authored Oct 14, 2023
2 parents 3967c27 + 3de1c3f commit c3c3bf3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/bridges/elm/ElmJsonEncoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ trait ElmJsonEncoder extends ElmUtils {
"Maybe.withDefault Encode.null (Maybe.map " +
encodeType(optTpe, objectName, fieldName, customTypeReplacements) + ")"
case Arr(arrTpe) =>
"Encode.list (List.map " +
encodeType(arrTpe, objectName, fieldName, customTypeReplacements) + ")"
"Encode.list " +
encodeType(arrTpe, objectName, fieldName, customTypeReplacements)
case Dict(kTpe, vTpe) =>
"(Encode.dict " +
encodeType(kTpe, objectName, fieldName, customTypeReplacements) + " " +
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/bridges/elm/ElmFileBuilderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class ElmFileBuilderSpec extends AnyFreeSpec with Matchers {
encoderNavigation : Navigation -> Encode.Value
encoderNavigation tpe =
case tpe of
Node name children -> Encode.object [ ("name", Encode.string name), ("children", Encode.list (List.map encoderNavigation children)), ("type", Encode.string "Node") ]
NodeList all -> Encode.object [ ("all", Encode.list (List.map encoderNavigation all)), ("type", Encode.string "NodeList") ]
Node name children -> Encode.object [ ("name", Encode.string name), ("children", Encode.list encoderNavigation children), ("type", Encode.string "Node") ]
NodeList all -> Encode.object [ ("all", Encode.list encoderNavigation all), ("type", Encode.string "NodeList") ]
"""
val expected = ("Navigation.elm", fileContent)

Expand Down Expand Up @@ -333,7 +333,7 @@ class ElmFileBuilderSpec extends AnyFreeSpec with Matchers {


encoderTypeOne : TypeOne -> Encode.Value
encoderTypeOne obj = Encode.object [ ("name", Encode.string obj.name), ("values", Encode.list (List.map encoderTypeTwo obj.values)) ]
encoderTypeOne obj = Encode.object [ ("name", Encode.string obj.name), ("values", Encode.list encoderTypeTwo obj.values) ]

encoderTypeTwo : TypeTwo -> Encode.Value
encoderTypeTwo tpe =
Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/bridges/elm/ElmJsonEncoderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ElmJsonEncoderSpec extends AnyFreeSpec with Matchers {
Elm.encoder(decl[ArrayClass]) shouldBe {
i"""
encoderArrayClass : ArrayClass -> Encode.Value
encoderArrayClass obj = Encode.object [ ("aList", Encode.list (List.map Encode.string obj.aList)), ("optField", Maybe.withDefault Encode.null (Maybe.map Encode.float obj.optField)) ]
encoderArrayClass obj = Encode.object [ ("aList", Encode.list Encode.string obj.aList), ("optField", Maybe.withDefault Encode.null (Maybe.map Encode.float obj.optField)) ]
"""
}
}
Expand Down Expand Up @@ -94,8 +94,8 @@ class ElmJsonEncoderSpec extends AnyFreeSpec with Matchers {
encoderNavigation : Navigation -> Encode.Value
encoderNavigation tpe =
case tpe of
Node name children -> Encode.object [ ("name", Encode.string name), ("children", Encode.list (List.map encoderNavigation children)), ("type", Encode.string "Node") ]
NodeList all -> Encode.object [ ("all", Encode.list (List.map encoderNavigation all)), ("type", Encode.string "NodeList") ]
Node name children -> Encode.object [ ("name", Encode.string name), ("children", Encode.list encoderNavigation children), ("type", Encode.string "Node") ]
NodeList all -> Encode.object [ ("all", Encode.list encoderNavigation all), ("type", Encode.string "NodeList") ]
"""
}
}
Expand All @@ -113,7 +113,7 @@ class ElmJsonEncoderSpec extends AnyFreeSpec with Matchers {
Elm.encoder(List(decl[TypeOne], decl[TypeTwo]), Map.empty[Ref, TypeReplacement]) shouldBe {
i"""
encoderTypeOne : TypeOne -> Encode.Value
encoderTypeOne obj = Encode.object [ ("name", Encode.string obj.name), ("values", Encode.list (List.map encoderTypeTwo obj.values)) ]
encoderTypeOne obj = Encode.object [ ("name", Encode.string obj.name), ("values", Encode.list encoderTypeTwo obj.values) ]

encoderTypeTwo : TypeTwo -> Encode.Value
encoderTypeTwo tpe =
Expand Down Expand Up @@ -217,7 +217,7 @@ class ElmJsonEncoderSpec extends AnyFreeSpec with Matchers {
Elm.encoder(decl[Recursive2]) shouldBe {
i"""
encoderRecursive2 : Recursive2 -> Encode.Value
encoderRecursive2 obj = Encode.object [ ("head", Encode.int obj.head), ("tail", Encode.list (List.map encoderRecursive2 obj.tail)) ]
encoderRecursive2 obj = Encode.object [ ("head", Encode.int obj.head), ("tail", Encode.list encoderRecursive2 obj.tail) ]
"""
}
}
Expand Down

0 comments on commit c3c3bf3

Please sign in to comment.