From ad5bf47d25920ef5f1e469725e01b3d8a01b346e Mon Sep 17 00:00:00 2001 From: kolektiv Date: Sun, 26 Jul 2015 17:37:21 +0100 Subject: [PATCH 1/3] exceptions thrown on infinte and NaN double serialization. error on failing lens retrieval. --- src/Chiron.Schema/Chiron.Schema.fsproj | 10 +- src/Chiron/Chiron.fs | 123 +++++++++++++------------ src/Chiron/Chiron.fsproj | 6 +- tests/Chiron.Tests/Chiron.Tests.fsproj | 8 +- 4 files changed, 75 insertions(+), 72 deletions(-) diff --git a/src/Chiron.Schema/Chiron.Schema.fsproj b/src/Chiron.Schema/Chiron.Schema.fsproj index 71aec39..4d2066d 100644 --- a/src/Chiron.Schema/Chiron.Schema.fsproj +++ b/src/Chiron.Schema/Chiron.Schema.fsproj @@ -70,7 +70,7 @@ --> - + ..\..\packages\Aether\lib\net40\Aether.dll @@ -81,7 +81,7 @@ - + ..\..\packages\FParsec\lib\net40-client\FParsec.dll @@ -97,7 +97,7 @@ - + ..\..\packages\Freya.Types\lib\net40\Freya.Types.dll @@ -108,7 +108,7 @@ - + ..\..\packages\Freya.Types.Uri\lib\net40\Freya.Types.Uri.dll @@ -119,7 +119,7 @@ - + ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll diff --git a/src/Chiron/Chiron.fs b/src/Chiron/Chiron.fs index 2706907..1d11267 100644 --- a/src/Chiron/Chiron.fs +++ b/src/Chiron/Chiron.fs @@ -30,49 +30,46 @@ type Json = (* Isomorphisms *) - static member ArrayPIso : PIso = + static member Array_ : PIso = (function | Array x -> Some x | _ -> None), Array - static member BoolPIso : PIso = + static member Bool_ : PIso = (function | Bool x -> Some x | _ -> None), Bool - static member NullPIso : PIso = + static member Null_ : PIso = (function | Null () -> Some () | _ -> None), Null - static member NumberPIso : PIso = + static member Number_ : PIso = (function | Number x -> Some x | _ -> None), Number - static member ObjectPIso : PIso> = + static member Object_ : PIso> = (function | Object x -> Some x | _ -> None), Object - static member StringPIso : PIso = + static member String_ : PIso = (function | String x -> Some x | _ -> None), String - (* Lenses *) +(* Lenses *) - static member ArrayPLens : PLens = - idLens <-?> Json.ArrayPIso +let private array_ = + idLens <-?> Json.Array_ - static member BoolPLens : PLens = - idLens <-?> Json.BoolPIso +let private bool_ = + idLens <-?> Json.Bool_ - static member NullPLens : PLens = - idLens <-?> Json.NullPIso +let private number_ = + idLens <-?> Json.Number_ - static member NumberPLens : PLens = - idLens <-?> Json.NumberPIso +let private object_ = + idLens <-?> Json.Object_ - static member ObjectPLens : PLens> = - idLens <-?> Json.ObjectPIso - - static member StringPLens : PLens = - idLens <-?> Json.StringPIso +let private string_ = + idLens <-?> Json.String_ (* Functional @@ -227,7 +224,7 @@ module Lens = fun json -> match Lens.getPartial l json with | Some x -> Value x, json - | _ -> Error (sprintf "couldn't use lens %A on json '%A'" l json), json + | _ -> Error (sprintf "Couldn't use (Partial) Lens %A on JSON: '%A'." l json), json let tryGetLensPartial l : Json<_> = fun json -> @@ -624,37 +621,37 @@ module Mapping = (* Basic Types *) static member inline FromJson (_: bool) = - Json.getLensPartial Json.BoolPLens + Json.getLensPartial bool_ static member inline FromJson (_: decimal) = - id Json.getLensPartial Json.NumberPLens + id Json.getLensPartial number_ static member inline FromJson (_: float) = - float Json.getLensPartial Json.NumberPLens + float Json.getLensPartial number_ static member inline FromJson (_: int) = - int Json.getLensPartial Json.NumberPLens + int Json.getLensPartial number_ static member inline FromJson (_: int16) = - int16 Json.getLensPartial Json.NumberPLens + int16 Json.getLensPartial number_ static member inline FromJson (_: int64) = - int64 Json.getLensPartial Json.NumberPLens + int64 Json.getLensPartial number_ static member inline FromJson (_: single) = - single Json.getLensPartial Json.NumberPLens + single Json.getLensPartial number_ static member inline FromJson (_: string) = - Json.getLensPartial Json.StringPLens + Json.getLensPartial string_ static member inline FromJson (_: uint16) = - uint16 Json.getLensPartial Json.NumberPLens + uint16 Json.getLensPartial number_ static member inline FromJson (_: uint32) = - uint32 Json.getLensPartial Json.NumberPLens + uint32 Json.getLensPartial number_ static member inline FromJson (_: uint64) = - uint64 Json.getLensPartial Json.NumberPLens + uint64 Json.getLensPartial number_ (* Common Types *) @@ -663,21 +660,21 @@ module Mapping = match DateTime.TryParseExact (x, [| "s"; "r"; "o" |], null, DateTimeStyles.AdjustToUniversal) with | true, x -> Json.init x | _ -> Json.error "datetime" - =<< Json.getLensPartial Json.StringPLens + =<< Json.getLensPartial string_ static member inline FromJson (_: DateTimeOffset) = fun x -> match DateTimeOffset.TryParseExact (x, [|"yyyy-MM-dd'T'HH:mm:ss.FFFK" |], null, DateTimeStyles.None) with | true, x -> Json.init x | _ -> Json.error "datetimeoffset" - =<< Json.getLensPartial Json.StringPLens + =<< Json.getLensPartial string_ static member inline FromJson (_: Guid) = fun x -> match Guid.TryParse x with | true, x -> Json.init x | _ -> Json.error "guid" - =<< Json.getLensPartial Json.StringPLens + =<< Json.getLensPartial string_ (* Json Type *) @@ -714,13 +711,13 @@ module Mapping = static member inline FromJson (_: 'a array) : Json<'a array> = fromJsonFold Array.empty (fun x xs -> Array.append [| x |] xs) >> Json.ofResult - =<< Json.getLensPartial Json.ArrayPLens + =<< Json.getLensPartial array_ (* Lists *) static member inline FromJson (_: 'a list) : Json<'a list> = fromJsonFold List.empty (fun x xs -> x :: xs) >> Json.ofResult - =<< Json.getLensPartial Json.ArrayPLens + =<< Json.getLensPartial array_ (* Maps *) @@ -728,13 +725,13 @@ module Mapping = fun x -> let k, v = (Map.toList >> List.unzip) x List.zip k >> Map.ofList Json.ofResult (fromJsonFold [] (fun x xs -> x :: xs) v) - =<< Json.getLensPartial Json.ObjectPLens + =<< Json.getLensPartial object_ (* Sets *) static member inline FromJson (_: Set<'a>) : Json> = fromJsonFold Set.empty Set.add >> Json.ofResult - =<< Json.getLensPartial Json.ArrayPLens + =<< Json.getLensPartial array_ (* Options *) @@ -752,7 +749,7 @@ module Mapping = <*> Json.ofResult (fromJson b) | _ -> Json.error "tuple2" - =<< Json.getLensPartial Json.ArrayPLens + =<< Json.getLensPartial array_ static member inline FromJson (_: 'a * 'b * 'c) : Json<'a * 'b * 'c> = function | a :: b :: c :: [] -> @@ -762,7 +759,7 @@ module Mapping = <*> Json.ofResult (fromJson c) | _ -> Json.error "tuple3" - =<< Json.getLensPartial Json.ArrayPLens + =<< Json.getLensPartial array_ (* To @@ -775,48 +772,51 @@ module Mapping = (* Basic Types *) static member inline ToJson (x: bool) = - Json.setLensPartial Json.BoolPLens x + Json.setLensPartial bool_ x static member inline ToJson (x: decimal) = - Json.setLensPartial Json.NumberPLens x + Json.setLensPartial number_ x static member inline ToJson (x: float) = - Json.setLensPartial Json.NumberPLens (decimal x) + match x with + | x when Double.IsInfinity x -> failwith "Serialization of Infinite Numbers Invalid." + | x when Double.IsNaN x -> failwith "Serialization of NaN Invalid." + | x -> Json.setLensPartial number_ (decimal x) static member inline ToJson (x: int) = - Json.setLensPartial Json.NumberPLens (decimal x) + Json.setLensPartial number_ (decimal x) static member inline ToJson (x: int16) = - Json.setLensPartial Json.NumberPLens (decimal x) + Json.setLensPartial number_ (decimal x) static member inline ToJson (x: int64) = - Json.setLensPartial Json.NumberPLens (decimal x) + Json.setLensPartial number_ (decimal x) static member inline ToJson (x: single) = - Json.setLensPartial Json.NumberPLens (decimal x) + Json.setLensPartial number_ (decimal x) static member inline ToJson (x: string) = - Json.setLensPartial Json.StringPLens x + Json.setLensPartial string_ x static member inline ToJson (x: uint16) = - Json.setLensPartial Json.NumberPLens (decimal x) + Json.setLensPartial number_ (decimal x) static member inline ToJson (x: uint32) = - Json.setLensPartial Json.NumberPLens (decimal x) + Json.setLensPartial number_ (decimal x) static member inline ToJson (x: uint64) = - Json.setLensPartial Json.NumberPLens (decimal x) + Json.setLensPartial number_ (decimal x) (* Common Types *) static member inline ToJson (x: DateTime) = - Json.setLensPartial Json.StringPLens (x.ToUniversalTime().ToString("o")) + Json.setLensPartial string_ (x.ToUniversalTime().ToString("o")) static member inline ToJson (x: DateTimeOffset) = - Json.setLensPartial Json.StringPLens (x.ToString("o")) + Json.setLensPartial string_ (x.ToString("o")) static member inline ToJson (x: Guid) = - Json.setLensPartial Json.StringPLens (string x) + Json.setLensPartial string_ (string x) (* Json Type *) @@ -883,20 +883,23 @@ module Mapping = let inline read key = fromJson >> Json.ofResult - =<< Json.getLensPartial (Json.ObjectPLens >??> mapPLens key) + =<< Json.getLensPartial (object_ >??> mapPLens key) let inline readOrDefault key def = function | Some json -> Json.ofResult (fromJson json) | _ -> Json.init def - =<< Json.tryGetLensPartial (Json.ObjectPLens >??> mapPLens key) + =<< Json.tryGetLensPartial (object_ >??> mapPLens key) let inline tryRead key = function | Some json -> Some Json.ofResult (fromJson json) | _ -> Json.init None - =<< Json.tryGetLensPartial (Json.ObjectPLens >??> mapPLens key) + =<< Json.tryGetLensPartial (object_ >??> mapPLens key) let inline write key value = - Json.setLensPartial (Json.ObjectPLens >??> mapPLens key) (toJson value) + Json.setLensPartial (object_ >??> mapPLens key) (toJson value) + + let inline writeNone key = + Json.setLensPartial (object_ >??> mapPLens key) (Json.Null ()) (* Serialization/Deserialization *) @@ -924,6 +927,6 @@ module Patterns = /// Parse a Property from a Json Object token, and try to deserialize it to the /// inferred type. let inline (|Property|_|) key = - Lens.getPartial (Json.ObjectPLens >??> mapPLens key) + Lens.getPartial (object_ >??> mapPLens key) >> Option.bind (Json.tryDeserialize >> function | Choice1Of2 json -> Some json | _ -> None) \ No newline at end of file diff --git a/src/Chiron/Chiron.fsproj b/src/Chiron/Chiron.fsproj index d8b5db8..fe1009d 100644 --- a/src/Chiron/Chiron.fsproj +++ b/src/Chiron/Chiron.fsproj @@ -64,7 +64,7 @@ --> - + ..\..\packages\Aether\lib\net40\Aether.dll @@ -75,7 +75,7 @@ - + ..\..\packages\FParsec\lib\net40-client\FParsec.dll @@ -91,7 +91,7 @@ - + ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll diff --git a/tests/Chiron.Tests/Chiron.Tests.fsproj b/tests/Chiron.Tests/Chiron.Tests.fsproj index 404782a..71c1501 100644 --- a/tests/Chiron.Tests/Chiron.Tests.fsproj +++ b/tests/Chiron.Tests/Chiron.Tests.fsproj @@ -70,7 +70,7 @@ - + ..\..\packages\Aether\lib\net40\Aether.dll @@ -81,7 +81,7 @@ - + ..\..\packages\FsCheck\lib\net45\FsCheck.dll @@ -92,7 +92,7 @@ - + ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll @@ -173,7 +173,7 @@ - + ..\..\packages\Unquote\lib\net40\Unquote.dll From 725f969bdcf875862021b4dd2dd93616f2ca2c51 Mon Sep 17 00:00:00 2001 From: Marcus Griep Date: Mon, 5 Oct 2015 21:57:14 -0400 Subject: [PATCH 2/3] Add writeUnlessDefault function --- src/Chiron/Chiron.fs | 5 ++++ tests/Chiron.Tests/Chiron.Tests.fs | 41 ++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/Chiron/Chiron.fs b/src/Chiron/Chiron.fs index 2706907..9f18c9a 100644 --- a/src/Chiron/Chiron.fs +++ b/src/Chiron/Chiron.fs @@ -898,6 +898,11 @@ module Mapping = let inline write key value = Json.setLensPartial (Json.ObjectPLens >??> mapPLens key) (toJson value) + let inline writeUnlessDefault key def value = + match value with + | v when v = def -> Json.ofResult <| Value () + | _ -> write key value + (* Serialization/Deserialization *) let inline deserialize json = diff --git a/tests/Chiron.Tests/Chiron.Tests.fs b/tests/Chiron.Tests/Chiron.Tests.fs index 7c0f2d5..413a685 100644 --- a/tests/Chiron.Tests/Chiron.Tests.fs +++ b/tests/Chiron.Tests/Chiron.Tests.fs @@ -60,9 +60,9 @@ let ``Json.map2 returns correct values`` () = data structures. *) let private lens = - idLens - <-?> Json.ObjectPIso - >??> mapPLens "bool" + idLens + <-?> Json.ObjectPIso + >??> mapPLens "bool" Json.BoolPIso [] @@ -206,13 +206,13 @@ type Test = Values = v Json = j } Json.read "string" - <*> Json.read "number" + <*> Json.readOrDefault "number" None <*> Json.read "values" <*> Json.read "json" static member ToJson (x: Test) = Json.write "string" x.String - *> Json.write "number" x.Number + *> Json.writeUnlessDefault "number" None x.Number *> Json.write "values" x.Values *> Json.write "json" x.Json @@ -233,6 +233,37 @@ let testInstance = let ``Json.deserialize with custom typed returns correct values`` () = Json.deserialize testJson =? testInstance +let testJsonWithNullOption = + Object (Map.ofList + [ "string", String "hello" + "number", Null () + "values", Array [] + "json", Object (Map [ "hello", String "world" ]) ]) + +let testInstanceWithNoneOption = + { String = "hello" + Number = None + Values = [ ] + Json = Object (Map [ "hello", String "world" ]) } + +[] +let ``Json.deserialize with null option value`` () = + Json.deserialize testJsonWithNullOption =? testInstanceWithNoneOption + +let testJsonWithMissingOption = + Object (Map.ofList + [ "string", String "hello" + "values", Array [] + "json", Object (Map [ "hello", String "world" ]) ]) + +[] +let ``Json.deserialize with missing value`` () = + Json.deserialize testJsonWithMissingOption =? testInstanceWithNoneOption + +[] +let ``Json.serialize with default value`` () = + Json.serialize testInstanceWithNoneOption =? testJsonWithMissingOption + [] let ``Json.serialize with simple types returns correct values`` () = From 4d49bf9ed572c8c6438caa5c3add1792cac7026b Mon Sep 17 00:00:00 2001 From: kolektiv Date: Tue, 6 Oct 2015 23:37:34 +0100 Subject: [PATCH 3/3] merging in an addition from marcus griep, updating dependencies to newer aether, removing chiron.schema for now, and updating lenses to newer aether standard of lens_ naming --- Chiron.sln | 24 +-- build.fsx | 5 +- paket.dependencies | 3 +- paket.lock | 20 +- src/Chiron.Schema/Chiron.Schema.fsproj | 186 ------------------ .../Chiron.Schema.fsproj.paket.references | 3 - src/Chiron.Schema/Schema.fs | 30 --- src/Chiron/Chiron.fs | 139 ++++++------- src/Chiron/Chiron.fsproj | 22 ++- tests/Chiron.Tests/Chiron.Tests.fs | 149 +++++++------- tests/Chiron.Tests/Chiron.Tests.fsproj | 63 ++++-- 11 files changed, 233 insertions(+), 411 deletions(-) delete mode 100644 src/Chiron.Schema/Chiron.Schema.fsproj delete mode 100644 src/Chiron.Schema/Chiron.Schema.fsproj.paket.references delete mode 100644 src/Chiron.Schema/Schema.fs diff --git a/Chiron.sln b/Chiron.sln index 8f35231..d678ded 100644 --- a/Chiron.sln +++ b/Chiron.sln @@ -1,17 +1,15 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio 2013 VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{10A1D756-4F8F-47DC-882E-8CFE58D5EE55}" EndProject -Project("{f2a71f9b-5d33-465a-a702-920d77279786}") = "Chiron", "src\Chiron\Chiron.fsproj", "{0C508EEE-E451-4BB3-863A-36D3DD7DA413}" -EndProject -Project("{f2a71f9b-5d33-465a-a702-920d77279786}") = "Chiron.Schema", "src\Chiron.Schema\Chiron.Schema.fsproj", "{4EE2600B-C084-4ACE-B324-AFBC86F59C2D}" +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Chiron", "src\Chiron\Chiron.fsproj", "{0C508EEE-E451-4BB3-863A-36D3DD7DA413}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{9CFCA560-5277-474D-9535-5895502DAF4E}" EndProject -Project("{f2a71f9b-5d33-465a-a702-920d77279786}") = "Chiron.Tests", "tests\Chiron.Tests\Chiron.Tests.fsproj", "{948B05DB-C8B2-42CB-A5A6-F93B8C9096DE}" +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Chiron.Tests", "tests\Chiron.Tests\Chiron.Tests.fsproj", "{948B05DB-C8B2-42CB-A5A6-F93B8C9096DE}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sln", "sln", "{5E1D0790-B7BC-46CF-8780-4E66EEC95AC7}" EndProject @@ -26,7 +24,6 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D85F3E6B-3A52-4099-953E-06B9766538A4}" ProjectSection(SolutionItems) = preProject src\Chiron\Chiron.fsproj.paket.references = src\Chiron\Chiron.fsproj.paket.references - src\Chiron.Schema\Chiron.Schema.fsproj.paket.references = src\Chiron.Schema\Chiron.Schema.fsproj.paket.references EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7BA60919-04CD-4D84-AFA7-A2F908541D95}" @@ -55,27 +52,22 @@ Global {0C508EEE-E451-4BB3-863A-36D3DD7DA413}.Debug|Any CPU.Build.0 = Debug|Any CPU {0C508EEE-E451-4BB3-863A-36D3DD7DA413}.Release|Any CPU.ActiveCfg = Release|Any CPU {0C508EEE-E451-4BB3-863A-36D3DD7DA413}.Release|Any CPU.Build.0 = Release|Any CPU - {4EE2600B-C084-4ACE-B324-AFBC86F59C2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4EE2600B-C084-4ACE-B324-AFBC86F59C2D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4EE2600B-C084-4ACE-B324-AFBC86F59C2D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4EE2600B-C084-4ACE-B324-AFBC86F59C2D}.Release|Any CPU.Build.0 = Release|Any CPU {948B05DB-C8B2-42CB-A5A6-F93B8C9096DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {948B05DB-C8B2-42CB-A5A6-F93B8C9096DE}.Debug|Any CPU.Build.0 = Debug|Any CPU {948B05DB-C8B2-42CB-A5A6-F93B8C9096DE}.Release|Any CPU.ActiveCfg = Release|Any CPU {948B05DB-C8B2-42CB-A5A6-F93B8C9096DE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection GlobalSection(NestedProjects) = preSolution {0C508EEE-E451-4BB3-863A-36D3DD7DA413} = {10A1D756-4F8F-47DC-882E-8CFE58D5EE55} - {4EE2600B-C084-4ACE-B324-AFBC86F59C2D} = {10A1D756-4F8F-47DC-882E-8CFE58D5EE55} {948B05DB-C8B2-42CB-A5A6-F93B8C9096DE} = {9CFCA560-5277-474D-9535-5895502DAF4E} {2096F0EA-E379-4C9A-8546-680617B7CC1E} = {5E1D0790-B7BC-46CF-8780-4E66EEC95AC7} - {F87BBE06-BC6A-4C39-AB27-C906CE8F761F} = {5E1D0790-B7BC-46CF-8780-4E66EEC95AC7} - {21B241CF-5EC0-40D9-80E3-3F6016F9B31F} = {5E1D0790-B7BC-46CF-8780-4E66EEC95AC7} {A9BA802C-64D5-4706-8465-657F8AF7180F} = {2096F0EA-E379-4C9A-8546-680617B7CC1E} {D85F3E6B-3A52-4099-953E-06B9766538A4} = {A9BA802C-64D5-4706-8465-657F8AF7180F} {7BA60919-04CD-4D84-AFA7-A2F908541D95} = {A9BA802C-64D5-4706-8465-657F8AF7180F} - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE + {F87BBE06-BC6A-4C39-AB27-C906CE8F761F} = {5E1D0790-B7BC-46CF-8780-4E66EEC95AC7} + {21B241CF-5EC0-40D9-80E3-3F6016F9B31F} = {5E1D0790-B7BC-46CF-8780-4E66EEC95AC7} EndGlobalSection EndGlobal diff --git a/build.fsx b/build.fsx index 1dbf7f2..dc4d81d 100644 --- a/build.fsx +++ b/build.fsx @@ -31,9 +31,10 @@ Target "Publish" (fun _ -> Authors = [ "Andrew Cherry" "Michael Newton" - "Henrik Feldt" ] + "Henrik Feldt" + "Marcus Griep" ] Project = "Chiron" - Version = "4.1.0" + Version = "5.0.0" OutputPath = "bin" AccessKey = getBuildParamOrDefault "nuget_key" "" Publish = hasBuildParam "nuget_key" diff --git a/paket.dependencies b/paket.dependencies index cf609ae..c6788e4 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -1,9 +1,8 @@ source http://nuget.org/api/v2 nuget Aether -nuget Freya.Types.Uri 0.9.0-alpha-46 nuget FParsec -nuget FSharp.Core +nuget FSharp.Core 3.1.2.1 nuget Fake nuget FsCheck nuget Nuget.CommandLine diff --git a/paket.lock b/paket.lock index ffb1242..b131473 100644 --- a/paket.lock +++ b/paket.lock @@ -1,19 +1,13 @@ NUGET remote: http://nuget.org/api/v2 specs: - Aether (6.0) - FAKE (3.17.0) - FParsec (1.0.1) - Freya.Types (0.9.0-alpha-46) - FParsec (>= 1.0.1) - FSharp.Core (>= 3.1.2) - Freya.Types.Uri (0.9.0-alpha-46) - FParsec (>= 1.0.1) - FSharp.Core (>= 3.1.2) - Freya.Types (>= 0.9.0-alpha-46) - FsCheck (1.0.4) + Aether (7.0) + FAKE (4.4.6) + FParsec (1.0.2) + FsCheck (2.0.4) + FSharp.Core (>= 3.1.2.1) FSharp.Core (3.1.2.1) - NuGet.CommandLine (2.8.3) + NuGet.CommandLine (2.8.6) NUnit (2.6.4) NUnit.Runners (2.6.4) - Unquote (2.2.2) + Unquote (3.0.0) diff --git a/src/Chiron.Schema/Chiron.Schema.fsproj b/src/Chiron.Schema/Chiron.Schema.fsproj deleted file mode 100644 index 4d2066d..0000000 --- a/src/Chiron.Schema/Chiron.Schema.fsproj +++ /dev/null @@ -1,186 +0,0 @@ - - - - - Debug - AnyCPU - {4EE2600B-C084-4ACE-B324-AFBC86F59C2D} - Library - Chiron.Schema - Chiron.Schema - v4.5 - 4.3.1.0 - Chiron.Schema - - - true - full - false - false - bin\Debug\ - DEBUG;TRACE - 3 - bin\Debug\Chiron.Schema.XML - - - pdbonly - true - true - bin\Release\ - TRACE - 3 - bin\Release\Chiron.Schema.XML - - - - - - - - - - Chiron - {0C508EEE-E451-4BB3-863A-36D3DD7DA413} - - - - - - - 11 - - - - - $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets - - - - - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets - - - - - - - - - - ..\..\packages\Aether\lib\net40\Aether.dll - True - True - - - - - - - - - ..\..\packages\FParsec\lib\net40-client\FParsec.dll - True - True - - - ..\..\packages\FParsec\lib\net40-client\FParsecCS.dll - True - True - - - - - - - - - ..\..\packages\Freya.Types\lib\net40\Freya.Types.dll - True - True - - - - - - - - - ..\..\packages\Freya.Types.Uri\lib\net40\Freya.Types.Uri.dll - True - True - - - - - - - - - ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll - True - True - - - - - - - ..\..\packages\FSharp.Core\lib\MonoAndroid\FSharp.Core.dll - True - True - - - - - - - ..\..\packages\FSharp.Core\lib\MonoTouch\FSharp.Core.dll - True - True - - - - - - - ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+MonoAndroid1+MonoTouch1\FSharp.Core.dll - True - True - - - - - - - ..\..\packages\FSharp.Core\lib\portable-net45+sl5+netcore45+MonoAndroid1+MonoTouch1\FSharp.Core.dll - True - True - - - - - - - ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wp8+MonoAndroid1+MonoTouch1\FSharp.Core.dll - True - True - - - - - - - ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1\FSharp.Core.dll - True - True - - - - - \ No newline at end of file diff --git a/src/Chiron.Schema/Chiron.Schema.fsproj.paket.references b/src/Chiron.Schema/Chiron.Schema.fsproj.paket.references deleted file mode 100644 index 1d4c8bb..0000000 --- a/src/Chiron.Schema/Chiron.Schema.fsproj.paket.references +++ /dev/null @@ -1,3 +0,0 @@ -Aether -Freya.Types.Uri -FSharp.Core diff --git a/src/Chiron.Schema/Schema.fs b/src/Chiron.Schema/Schema.fs deleted file mode 100644 index 9db8432..0000000 --- a/src/Chiron.Schema/Schema.fs +++ /dev/null @@ -1,30 +0,0 @@ -module Chiron.Schema - -open Chiron -open Chiron.Operators -open Freya.Types.Uri - -[] -module Json = - - let inline tryReadMap key f = - function | Some x -> - match f x with - | Some x -> Json.init (Some x) - | _ -> Json.error "" - | _ -> - Json.init None - <=< Json.tryRead key - -(* Types *) - -type Schema = - { Title: string option - Schema: AbsoluteUri option } - - static member FromJson (_: Schema) = - fun t s -> - { Title = t - Schema = s } - Json.tryRead "title" - <*> Json.tryReadMap "$schema" AbsoluteUri.TryParse \ No newline at end of file diff --git a/src/Chiron/Chiron.fs b/src/Chiron/Chiron.fs index e453c89..3f89a58 100644 --- a/src/Chiron/Chiron.fs +++ b/src/Chiron/Chiron.fs @@ -30,46 +30,49 @@ type Json = (* Isomorphisms *) - static member Array_ : PIso = + static member internal Array__ = (function | Array x -> Some x | _ -> None), Array - static member Bool_ : PIso = + static member internal Bool__ = (function | Bool x -> Some x | _ -> None), Bool - static member Null_ : PIso = + static member internal Null__ = (function | Null () -> Some () | _ -> None), Null - static member Number_ : PIso = + static member internal Number__ = (function | Number x -> Some x | _ -> None), Number - static member Object_ : PIso> = + static member internal Object__ = (function | Object x -> Some x | _ -> None), Object - static member String_ : PIso = + static member internal String__ = (function | String x -> Some x | _ -> None), String -(* Lenses *) + (* Lenses *) -let private array_ = - idLens <-?> Json.Array_ + static member Array_ = + id_ <-?> Json.Array__ -let private bool_ = - idLens <-?> Json.Bool_ + static member Bool_ = + id_ <-?> Json.Bool__ -let private number_ = - idLens <-?> Json.Number_ + static member Null_ = + id_ <-?> Json.Null__ -let private object_ = - idLens <-?> Json.Object_ + static member Number_ = + id_ <-?> Json.Number__ -let private string_ = - idLens <-?> Json.String_ + static member Object_ = + id_ <-?> Json.Object__ + + static member String_ = + id_ <-?> Json.String__ (* Functional @@ -621,37 +624,37 @@ module Mapping = (* Basic Types *) static member inline FromJson (_: bool) = - Json.getLensPartial bool_ + Json.getLensPartial Json.Bool_ static member inline FromJson (_: decimal) = - id Json.getLensPartial number_ + id Json.getLensPartial Json.Number_ static member inline FromJson (_: float) = - float Json.getLensPartial number_ + float Json.getLensPartial Json.Number_ static member inline FromJson (_: int) = - int Json.getLensPartial number_ + int Json.getLensPartial Json.Number_ static member inline FromJson (_: int16) = - int16 Json.getLensPartial number_ + int16 Json.getLensPartial Json.Number_ static member inline FromJson (_: int64) = - int64 Json.getLensPartial number_ + int64 Json.getLensPartial Json.Number_ static member inline FromJson (_: single) = - single Json.getLensPartial number_ + single Json.getLensPartial Json.Number_ static member inline FromJson (_: string) = - Json.getLensPartial string_ + Json.getLensPartial Json.String_ static member inline FromJson (_: uint16) = - uint16 Json.getLensPartial number_ + uint16 Json.getLensPartial Json.Number_ static member inline FromJson (_: uint32) = - uint32 Json.getLensPartial number_ + uint32 Json.getLensPartial Json.Number_ static member inline FromJson (_: uint64) = - uint64 Json.getLensPartial number_ + uint64 Json.getLensPartial Json.Number_ (* Common Types *) @@ -660,26 +663,26 @@ module Mapping = match DateTime.TryParseExact (x, [| "s"; "r"; "o" |], null, DateTimeStyles.AdjustToUniversal) with | true, x -> Json.init x | _ -> Json.error "datetime" - =<< Json.getLensPartial string_ + =<< Json.getLensPartial Json.String_ static member inline FromJson (_: DateTimeOffset) = fun x -> match DateTimeOffset.TryParseExact (x, [|"yyyy-MM-dd'T'HH:mm:ss.FFFK" |], null, DateTimeStyles.None) with | true, x -> Json.init x | _ -> Json.error "datetimeoffset" - =<< Json.getLensPartial string_ + =<< Json.getLensPartial Json.String_ static member inline FromJson (_: Guid) = fun x -> match Guid.TryParse x with | true, x -> Json.init x | _ -> Json.error "guid" - =<< Json.getLensPartial string_ + =<< Json.getLensPartial Json.String_ (* Json Type *) static member inline FromJson (_: Json) = - Json.getLens idLens + Json.getLens id_ (* Mapping Functions @@ -711,13 +714,13 @@ module Mapping = static member inline FromJson (_: 'a array) : Json<'a array> = fromJsonFold Array.empty (fun x xs -> Array.append [| x |] xs) >> Json.ofResult - =<< Json.getLensPartial array_ + =<< Json.getLensPartial Json.Array_ (* Lists *) static member inline FromJson (_: 'a list) : Json<'a list> = fromJsonFold List.empty (fun x xs -> x :: xs) >> Json.ofResult - =<< Json.getLensPartial array_ + =<< Json.getLensPartial Json.Array_ (* Maps *) @@ -725,20 +728,20 @@ module Mapping = fun x -> let k, v = (Map.toList >> List.unzip) x List.zip k >> Map.ofList Json.ofResult (fromJsonFold [] (fun x xs -> x :: xs) v) - =<< Json.getLensPartial object_ + =<< Json.getLensPartial Json.Object_ (* Sets *) static member inline FromJson (_: Set<'a>) : Json> = fromJsonFold Set.empty Set.add >> Json.ofResult - =<< Json.getLensPartial array_ + =<< Json.getLensPartial Json.Array_ (* Options *) static member inline FromJson (_: 'a option) : Json<'a option> = function | Null _ -> Json.init None | x -> Some Json.ofResult (fromJson x) - =<< Json.getLens idLens + =<< Json.getLens id_ (* Tuples *) @@ -749,7 +752,7 @@ module Mapping = <*> Json.ofResult (fromJson b) | _ -> Json.error "tuple2" - =<< Json.getLensPartial array_ + =<< Json.getLensPartial Json.Array_ static member inline FromJson (_: 'a * 'b * 'c) : Json<'a * 'b * 'c> = function | a :: b :: c :: [] -> @@ -759,7 +762,7 @@ module Mapping = <*> Json.ofResult (fromJson c) | _ -> Json.error "tuple3" - =<< Json.getLensPartial array_ + =<< Json.getLensPartial Json.Array_ (* To @@ -772,56 +775,56 @@ module Mapping = (* Basic Types *) static member inline ToJson (x: bool) = - Json.setLensPartial bool_ x + Json.setLensPartial Json.Bool_ x static member inline ToJson (x: decimal) = - Json.setLensPartial number_ x + Json.setLensPartial Json.Number_ x static member inline ToJson (x: float) = match x with | x when Double.IsInfinity x -> failwith "Serialization of Infinite Numbers Invalid." | x when Double.IsNaN x -> failwith "Serialization of NaN Invalid." - | x -> Json.setLensPartial number_ (decimal x) + | x -> Json.setLensPartial Json.Number_ (decimal x) static member inline ToJson (x: int) = - Json.setLensPartial number_ (decimal x) + Json.setLensPartial Json.Number_ (decimal x) static member inline ToJson (x: int16) = - Json.setLensPartial number_ (decimal x) + Json.setLensPartial Json.Number_ (decimal x) static member inline ToJson (x: int64) = - Json.setLensPartial number_ (decimal x) + Json.setLensPartial Json.Number_ (decimal x) static member inline ToJson (x: single) = - Json.setLensPartial number_ (decimal x) + Json.setLensPartial Json.Number_ (decimal x) static member inline ToJson (x: string) = - Json.setLensPartial string_ x + Json.setLensPartial Json.String_ x static member inline ToJson (x: uint16) = - Json.setLensPartial number_ (decimal x) + Json.setLensPartial Json.Number_ (decimal x) static member inline ToJson (x: uint32) = - Json.setLensPartial number_ (decimal x) + Json.setLensPartial Json.Number_ (decimal x) static member inline ToJson (x: uint64) = - Json.setLensPartial number_ (decimal x) + Json.setLensPartial Json.Number_ (decimal x) (* Common Types *) static member inline ToJson (x: DateTime) = - Json.setLensPartial string_ (x.ToUniversalTime().ToString("o")) + Json.setLensPartial Json.String_ (x.ToUniversalTime().ToString("o")) static member inline ToJson (x: DateTimeOffset) = - Json.setLensPartial string_ (x.ToString("o")) + Json.setLensPartial Json.String_ (x.ToString("o")) static member inline ToJson (x: Guid) = - Json.setLensPartial string_ (string x) + Json.setLensPartial Json.String_ (string x) (* Json Type *) static member inline ToJson (x: Json) = - Json.setLens idLens x + Json.setLens id_ x (* Mapping Functions @@ -841,36 +844,36 @@ module Mapping = (* Arrays *) static member inline ToJson (x: 'a array) = - Json.setLens idLens (Array ((Array.toList >> List.map toJson) x)) + Json.setLens id_ (Array ((Array.toList >> List.map toJson) x)) (* Lists *) static member inline ToJson (x: 'a list) = - Json.setLens idLens (Array (List.map toJson x)) + Json.setLens id_ (Array (List.map toJson x)) (* Maps *) static member inline ToJson (x: Map) = - Json.setLens idLens (Object (Map.map (fun _ a -> toJson a) x)) + Json.setLens id_ (Object (Map.map (fun _ a -> toJson a) x)) (* Options *) static member inline ToJson (x: 'a option) = - Json.setLens idLens ((function | Some a -> toJson a - | _ -> Null ()) x) + Json.setLens id_ ((function | Some a -> toJson a + | _ -> Null ()) x) (* Sets *) static member inline ToJson (x: Set<'a>) = - Json.setLens idLens (Array ((Set.toList >> List.map toJson) x)) + Json.setLens id_ (Array ((Set.toList >> List.map toJson) x)) (* Tuples *) static member inline ToJson ((a, b)) = - Json.setLens idLens (Array [ toJson a; toJson b ]) + Json.setLens id_ (Array [ toJson a; toJson b ]) static member inline ToJson ((a, b, c)) = - Json.setLens idLens (Array [ toJson a; toJson b; toJson c ]) + Json.setLens id_ (Array [ toJson a; toJson b; toJson c ]) (* Functions @@ -883,23 +886,23 @@ module Mapping = let inline read key = fromJson >> Json.ofResult - =<< Json.getLensPartial (object_ >??> mapPLens key) + =<< Json.getLensPartial (Json.Object_ >??> key_ key) let inline readOrDefault key def = function | Some json -> Json.ofResult (fromJson json) | _ -> Json.init def - =<< Json.tryGetLensPartial (object_ >??> mapPLens key) + =<< Json.tryGetLensPartial (Json.Object_ >??> key_ key) let inline tryRead key = function | Some json -> Some Json.ofResult (fromJson json) | _ -> Json.init None - =<< Json.tryGetLensPartial (object_ >??> mapPLens key) + =<< Json.tryGetLensPartial (Json.Object_ >??> key_ key) let inline write key value = - Json.setLensPartial (object_ >??> mapPLens key) (toJson value) + Json.setLensPartial (Json.Object_ >??> key_ key) (toJson value) let inline writeNone key = - Json.setLensPartial (object_ >??> mapPLens key) (Json.Null ()) + Json.setLensPartial (Json.Object_ >??> key_ key) (Json.Null ()) let inline writeUnlessDefault key def value = match value with @@ -932,6 +935,6 @@ module Patterns = /// Parse a Property from a Json Object token, and try to deserialize it to the /// inferred type. let inline (|Property|_|) key = - Lens.getPartial (object_ >??> mapPLens key) + Lens.getPartial (Json.Object_ >??> key_ key) >> Option.bind (Json.tryDeserialize >> function | Choice1Of2 json -> Some json | _ -> None) \ No newline at end of file diff --git a/src/Chiron/Chiron.fsproj b/src/Chiron/Chiron.fsproj index fe1009d..4c50bae 100644 --- a/src/Chiron/Chiron.fsproj +++ b/src/Chiron/Chiron.fsproj @@ -64,10 +64,10 @@ --> - + - ..\..\packages\Aether\lib\net40\Aether.dll + ..\..\packages\Aether\lib\net35\Aether.dll True True @@ -75,7 +75,7 @@ - + ..\..\packages\FParsec\lib\net40-client\FParsec.dll @@ -89,6 +89,20 @@ + + + + ..\..\packages\FParsec\lib\portable-net45+netcore45+wpa81+wp8\FParsec.dll + True + True + + + ..\..\packages\FParsec\lib\portable-net45+netcore45+wpa81+wp8\FParsecCS.dll + True + True + + + @@ -118,7 +132,7 @@ - + ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+MonoAndroid1+MonoTouch1\FSharp.Core.dll diff --git a/tests/Chiron.Tests/Chiron.Tests.fs b/tests/Chiron.Tests/Chiron.Tests.fs index 413a685..7de69a2 100644 --- a/tests/Chiron.Tests/Chiron.Tests.fs +++ b/tests/Chiron.Tests/Chiron.Tests.fs @@ -27,99 +27,98 @@ let private t2 = [] let ``Json.init returns correct values`` () = - Json.init 1 t1 =? (Value 1, t1) + Json.init 1 t1 =! (Value 1, t1) [] let ``Json.error returns correct values`` () = - Json.error "e" t1 =? (Error "e", t1) + Json.error "e" t1 =! (Error "e", t1) [] let ``Json.bind returns correct values`` () = - Json.bind (Json.init 2) (fun x -> Json.init (x * 3)) t1 =? (Value 6, t1) - Json.bind (Json.error "e") (fun x -> Json.init (x * 3)) t1 =? (Error "e", t1) + Json.bind (Json.init 2) (fun x -> Json.init (x * 3)) t1 =! (Value 6, t1) + Json.bind (Json.error "e") (fun x -> Json.init (x * 3)) t1 =! (Error "e", t1) [] let ``Json.apply returns correct values`` () = - Json.apply (Json.init (fun x -> x * 3)) (Json.init 2) t1 =? (Value 6, t1) - Json.apply (Json.init (fun x -> x * 3)) (Json.error "e") t1 =? (Error "e", t1) + Json.apply (Json.init (fun x -> x * 3)) (Json.init 2) t1 =! (Value 6, t1) + Json.apply (Json.init (fun x -> x * 3)) (Json.error "e") t1 =! (Error "e", t1) [] let ``Json.map returns correct values`` () = - Json.map (fun x -> x * 3) (Json.init 2) t1 =? (Value 6, t1) - Json.map (fun x -> x * 3) (Json.error "e") t1 =? (Error "e", t1) + Json.map (fun x -> x * 3) (Json.init 2) t1 =! (Value 6, t1) + Json.map (fun x -> x * 3) (Json.error "e") t1 =! (Error "e", t1) [] let ``Json.map2 returns correct values`` () = - Json.map2 (*) (Json.init 2) (Json.init 3) t1 =? (Value 6, t1) - Json.map2 (*) (Json.error "e") (Json.init 3) t1 =? (Error "e", t1) - Json.map2 (*) (Json.init 2) (Json.error "e") t1 =? (Error "e", t1) + Json.map2 (*) (Json.init 2) (Json.init 3) t1 =! (Value 6, t1) + Json.map2 (*) (Json.error "e") (Json.init 3) t1 =! (Error "e", t1) + Json.map2 (*) (Json.init 2) (Json.error "e") t1 =! (Error "e", t1) (* Lens Tests to exercise the functional lens based access to Json data structures. *) -let private lens = - idLens - <-?> Json.ObjectPIso - >??> mapPLens "bool" - Json.BoolPIso +let private lens_ = + Json.Object_ + >??> key_ "bool" + >??> Json.Bool_ [] let ``Json.getLens returns correct values`` () = - Json.getLens idLens t1 =? (Value t1, t1) + Json.getLens id_ t1 =! (Value t1, t1) [] let ``Json.getLensPartial returns correct values`` () = - Json.getLensPartial lens t1 =? (Value true, t1) + Json.getLensPartial lens_ t1 =! (Value true, t1) [] let ``Json.tryGetLensPartial returns correct values`` () = - Json.tryGetLensPartial (idLens <-?> Json.NumberPIso) t1 =? (Value None, t1) + Json.tryGetLensPartial Json.Number_ t1 =! (Value None, t1) [] let ``Json.setLens returns correct values`` () = - Json.setLens idLens (Bool false) t1 =? (Value (), Bool false) + Json.setLens id_ (Bool false) t1 =! (Value (), Bool false) [] let ``Json.setLensPartial returns correct values`` () = - Json.setLensPartial lens false t1 =? (Value (), t2) + Json.setLensPartial lens_ false t1 =! (Value (), t2) [] let ``Json.mapLens returns correct values`` () = - Json.mapLens idLens (fun _ -> Null ()) t1 =? (Value (), Null ()) + Json.mapLens id_ (fun _ -> Null ()) t1 =! (Value (), Null ()) [] let ``Json.mapLensPartial returns correct values`` () = - Json.mapLensPartial lens not t1 =? (Value (), t2) + Json.mapLensPartial lens_ not t1 =! (Value (), t2) (* Parsing *) [] let ``Json.parse returns correct values`` () = - Json.parse "\"hello\"" =? String "hello" - Json.parse "\"\"" =? String "" - Json.parse "\"\\n\"" =? String "\n" - Json.parse "\"\\u005c\"" =? String "\\" - Json.parse "\"푟\"" =? String "푟" + Json.parse "\"hello\"" =! String "hello" + Json.parse "\"\"" =! String "" + Json.parse "\"\\n\"" =! String "\n" + Json.parse "\"\\u005c\"" =! String "\\" + Json.parse "\"푟\"" =! String "푟" (* Formatting *) [] let ``Json.format returns correct values`` () = (* String *) - Json.format <| String "hello" =? "\"hello\"" + Json.format <| String "hello" =! "\"hello\"" (* Awkward string *) - Json.format <| String "he\nllo" =? "\"he\\nllo\"" + Json.format <| String "he\nllo" =! "\"he\\nllo\"" (* Complex type *) - Json.format t1 =? """{"bool":true,"number":2}""" + Json.format t1 =! """{"bool":true,"number":2}""" - Json.format (String "hello") =? "\"hello\"" - Json.format (String "") =? "\"\"" - Json.format (String "푟") =? "\"푟\"" - Json.format (String "\t") =? "\"\\t\"" + Json.format (String "hello") =! "\"hello\"" + Json.format (String "") =! "\"\"" + Json.format (String "푟") =! "\"푟\"" + Json.format (String "\t") =! "\"\\t\"" (* Mapping @@ -131,31 +130,31 @@ let ``Json.deserialize simple types returns correct values`` () = (* Boolean *) - Json.deserialize (Bool true) =? true + Json.deserialize (Bool true) =! true (* Numeric *) - Json.deserialize (Number 42M) =? decimal 42 - Json.deserialize (Number 42M) =? float 42 - Json.deserialize (Number 42M) =? int 42 - Json.deserialize (Number 42M) =? int16 42 - Json.deserialize (Number 42M) =? int64 42 - Json.deserialize (Number 42M) =? single 42 - Json.deserialize (Number 42M) =? uint16 42 - Json.deserialize (Number 42M) =? uint32 42 - Json.deserialize (Number 42M) =? uint64 42 + Json.deserialize (Number 42M) =! decimal 42 + Json.deserialize (Number 42M) =! float 42 + Json.deserialize (Number 42M) =! int 42 + Json.deserialize (Number 42M) =! int16 42 + Json.deserialize (Number 42M) =! int64 42 + Json.deserialize (Number 42M) =! single 42 + Json.deserialize (Number 42M) =! uint16 42 + Json.deserialize (Number 42M) =! uint32 42 + Json.deserialize (Number 42M) =! uint64 42 (* String *) - Json.deserialize (String "hello") =? "hello" + Json.deserialize (String "hello") =! "hello" (* DateTime *) - Json.deserialize (String "Fri, 20 Feb 2015 14:36:21 GMT") =? DateTime (2015, 2, 20, 14, 36, 21, DateTimeKind.Utc) + Json.deserialize (String "Fri, 20 Feb 2015 14:36:21 GMT") =! DateTime (2015, 2, 20, 14, 36, 21, DateTimeKind.Utc) (* DateTimeOffset *) - Json.deserialize (String "2015-04-15T13:45:55Z") =? DateTimeOffset (2015, 4, 15, 13, 45, 55, TimeSpan.Zero) + Json.deserialize (String "2015-04-15T13:45:55Z") =! DateTimeOffset (2015, 4, 15, 13, 45, 55, TimeSpan.Zero) [] let ``Json.deserialize complex types returns correct values`` () = @@ -163,12 +162,12 @@ let ``Json.deserialize complex types returns correct values`` () = (* Arrays *) Json.deserialize (Array [ String "hello"; String "world"]) - =? [| "hello"; "world" |] + =! [| "hello"; "world" |] (* Lists *) Json.deserialize (Array [ String "hello"; String "world"]) - =? [ "hello"; "world" ] + =! [ "hello"; "world" ] (* Maps *) @@ -176,22 +175,22 @@ let ``Json.deserialize complex types returns correct values`` () = Object (Map.ofList [ "one", Number 1M "two", Number 2M ])) - =? Map.ofList [ "one", 1; "two", 2 ] + =! Map.ofList [ "one", 1; "two", 2 ] (* Sets *) Json.deserialize (Array [ String "one"; String "two" ]) - =? set [ "one"; "two" ] + =! set [ "one"; "two" ] (* Options *) Json.deserialize (String "hello") - =? Some "hello" + =! Some "hello" (* Tuples *) Json.deserialize (Array [ String "hello"; Number 42M ]) - =? ("hello", 42) + =! ("hello", 42) type Test = { String: string @@ -231,7 +230,7 @@ let testInstance = [] let ``Json.deserialize with custom typed returns correct values`` () = - Json.deserialize testJson =? testInstance + Json.deserialize testJson =! testInstance let testJsonWithNullOption = Object (Map.ofList @@ -248,7 +247,7 @@ let testInstanceWithNoneOption = [] let ``Json.deserialize with null option value`` () = - Json.deserialize testJsonWithNullOption =? testInstanceWithNoneOption + Json.deserialize testJsonWithNullOption =! testInstanceWithNoneOption let testJsonWithMissingOption = Object (Map.ofList @@ -258,46 +257,46 @@ let testJsonWithMissingOption = [] let ``Json.deserialize with missing value`` () = - Json.deserialize testJsonWithMissingOption =? testInstanceWithNoneOption + Json.deserialize testJsonWithMissingOption =! testInstanceWithNoneOption [] let ``Json.serialize with default value`` () = - Json.serialize testInstanceWithNoneOption =? testJsonWithMissingOption + Json.serialize testInstanceWithNoneOption =! testJsonWithMissingOption [] let ``Json.serialize with simple types returns correct values`` () = (* Bool *) - Json.serialize true =? Bool true + Json.serialize true =! Bool true (* Numeric *) - Json.serialize (decimal 42) =? Number 42M - Json.serialize (float 42) =? Number 42M - Json.serialize (int 42) =? Number 42M - Json.serialize (int16 42) =? Number 42M - Json.serialize (int64 42) =? Number 42M - Json.serialize (single 42) =? Number 42M - Json.serialize (uint16 42) =? Number 42M - Json.serialize (uint32 42) =? Number 42M - Json.serialize (uint64 42) =? Number 42M + Json.serialize (decimal 42) =! Number 42M + Json.serialize (float 42) =! Number 42M + Json.serialize (int 42) =! Number 42M + Json.serialize (int16 42) =! Number 42M + Json.serialize (int64 42) =! Number 42M + Json.serialize (single 42) =! Number 42M + Json.serialize (uint16 42) =! Number 42M + Json.serialize (uint32 42) =! Number 42M + Json.serialize (uint64 42) =! Number 42M (* DateTime *) - Json.serialize (DateTime (2015, 2, 20, 14, 36, 21, DateTimeKind.Utc)) =? String "2015-02-20T14:36:21.0000000Z" + Json.serialize (DateTime (2015, 2, 20, 14, 36, 21, DateTimeKind.Utc)) =! String "2015-02-20T14:36:21.0000000Z" (* DateTimeOffset *) - Json.serialize (DateTimeOffset (2015, 2, 20, 14, 36, 21, TimeSpan.Zero)) =? String "2015-02-20T14:36:21.0000000+00:00" + Json.serialize (DateTimeOffset (2015, 2, 20, 14, 36, 21, TimeSpan.Zero)) =! String "2015-02-20T14:36:21.0000000+00:00" (* String *) - Json.serialize "hello" =? String "hello" + Json.serialize "hello" =! String "hello" [] let ``Json.serialize with custom types returns correct values`` () = - Json.serialize testInstance =? testJson + Json.serialize testInstance =! testJson type TestUnion = | One of string @@ -323,11 +322,11 @@ let testUnionJson = [] let ``Json.serialize with union types remains tractable`` () = - Json.serialize testUnion =? testUnionJson + Json.serialize testUnion =! testUnionJson [] let ``Json.deserialize with union types remains tractable`` () = - Json.deserialize testUnionJson =? testUnion + Json.deserialize testUnionJson =! testUnion [] let ``Json.format escapes object keys correctly`` () = @@ -335,4 +334,4 @@ let ``Json.format escapes object keys correctly`` () = let serialized = Json.serialize data let formatted = Json.format serialized - formatted =? """{"\u001F":"abc"}""" + formatted =! """{"\u001F":"abc"}""" diff --git a/tests/Chiron.Tests/Chiron.Tests.fsproj b/tests/Chiron.Tests/Chiron.Tests.fsproj index 71c1501..c1b374d 100644 --- a/tests/Chiron.Tests/Chiron.Tests.fsproj +++ b/tests/Chiron.Tests/Chiron.Tests.fsproj @@ -64,16 +64,12 @@ - - Chiron - {0C508EEE-E451-4BB3-863A-36D3DD7DA413} - - + - ..\..\packages\Aether\lib\net40\Aether.dll + ..\..\packages\Aether\lib\net35\Aether.dll True True @@ -81,7 +77,7 @@ - + ..\..\packages\FsCheck\lib\net45\FsCheck.dll @@ -90,6 +86,33 @@ + + + + ..\..\packages\FsCheck\lib\portable-net45+netcore45\FsCheck.dll + True + True + + + + + + + ..\..\packages\FsCheck\lib\portable-net45+netcore45+wp8\FsCheck.dll + True + True + + + + + + + ..\..\packages\FsCheck\lib\portable-net45+netcore45+wpa81+wp8\FsCheck.dll + True + True + + + @@ -119,7 +142,7 @@ - + ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+MonoAndroid1+MonoTouch1\FSharp.Core.dll @@ -163,20 +186,36 @@ True + + + Chiron + {0c508eee-e451-4bb3-863a-36d3dd7da413} + True + + - + - ..\..\packages\Unquote\lib\sl4\Unquote.dll + ..\..\packages\Unquote\lib\net40\Unquote.dll True True - + - ..\..\packages\Unquote\lib\net40\Unquote.dll + ..\..\packages\Unquote\lib\net45\Unquote.dll + True + True + + + + + + + ..\..\packages\Unquote\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1\Unquote.dll True True