Skip to content

Commit

Permalink
add overflow decode tests #12
Browse files Browse the repository at this point in the history
  • Loading branch information
caroott committed Jun 20, 2024
1 parent 93fb070 commit b0c2c30
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion tests/YAMLicious.Tests/Tests.EncoderDecoder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,29 @@ author_emails:
]
ExtensionData =
let dict = System.Collections.Generic.Dictionary<string, YAMLicious.YAMLiciousTypes.YAMLElement>()
dict.Add("author", YAMLicious.YAMLiciousTypes.YAMLElement.Value (YAMLicious.YAMLiciousTypes.YAMLContent.create("TestAuthor")))
dict.Add("author",
YAMLicious.YAMLiciousTypes.YAMLElement.Object [
YAMLicious.YAMLiciousTypes.YAMLElement.Value (
YAMLicious.YAMLiciousTypes.YAMLContent.create("TestAuthor")
)
]
)
dict.Add("author_emails",
YAMLicious.YAMLiciousTypes.YAMLElement.Object [
YAMLicious.YAMLiciousTypes.YAMLElement.Sequence [
YAMLicious.YAMLiciousTypes.YAMLElement.Object [
YAMLicious.YAMLiciousTypes.YAMLElement.Value (
YAMLicious.YAMLiciousTypes.YAMLContent.create("[email protected]")
)
]
YAMLicious.YAMLiciousTypes.YAMLElement.Object [
YAMLicious.YAMLiciousTypes.YAMLElement.Value (
YAMLicious.YAMLiciousTypes.YAMLContent.create("[email protected]")
)
]
]
]
)
dict
}

Expand Down Expand Up @@ -272,6 +294,27 @@ validation_packages:
let actual = Examples.ValidationPackageTypes.string |> Decode.read |> arcValidationDecoder
let expected = Examples.ValidationPackageTypes.type_
Expect.equal actual expected ""
testCase "overflow" <| fun _ ->
let packageEncoder = Decode.object (fun get ->
{
Name = get.Required.Field "name" Decode.string
Version = get.Optional.Field "version" Decode.string
}
)
let arcValidationDecoder =
Decode.object (fun get ->
{
ArcSpecificationVersion = get.Required.Field "arc_specification" Decode.string
Packages = get.Required.Field "validation_packages" (Decode.list packageEncoder)
ExtensionData = get.Overflow.FieldList ["author";"author_emails"]
}
)
let actual = Examples.ValidationPackageTypes.stringOverflow |> Decode.read |> arcValidationDecoder
let expected = Examples.ValidationPackageTypes.typeOverflow_
Expect.equal actual.ArcSpecificationVersion expected.ArcSpecificationVersion ""
Expect.equal actual.Packages expected.Packages ""
Expect.equal (actual.ExtensionData.Item "author") (expected.ExtensionData.Item "author") ""
Expect.equal (actual.ExtensionData.Item "author_emails") (expected.ExtensionData.Item "author_emails") ""
]

let Main = testList "EncoderDecoder" [
Expand Down

0 comments on commit b0c2c30

Please sign in to comment.