Last active
February 14, 2020 12:08
-
-
Save Horusiath/d3ddb341778ff599b122e5d2b95c3b9f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| open System | |
| open System.Text.Json | |
| open FsCheck.Xunit | |
| open Newtonsoft.Json | |
| open Swensen.Unquote | |
| [<Property>] | |
| let ``Parsing strings: System.Text.Json`` (i: char[]) = | |
| let sb = System.Text.StringBuilder() | |
| for c in i do | |
| match c with | |
| | '\\' -> sb.Append('\\').Append('\\') |> ignore | |
| | '"' -> sb.Append('\\').Append('"') |> ignore | |
| | c -> sb.Append(c) |> ignore | |
| let expected = sb.ToString() | |
| let actual = JsonDocument.Parse (sprintf "\"%s\"" expected) | |
| Assertions.test <@ actual.RootElement.GetString() = (String i) @> | |
| [<Property>] | |
| let ``Parsing strings: Newtonsoft.Json`` (i: char[]) = | |
| let sb = System.Text.StringBuilder() | |
| for c in i do | |
| match c with | |
| | '\\' -> sb.Append('\\').Append('\\') |> ignore | |
| | '"' -> sb.Append('\\').Append('"') |> ignore | |
| | c -> sb.Append(c) |> ignore | |
| let expected = sb.ToString() | |
| let actual = JsonConvert.DeserializeObject<string> (sprintf "\"%s\"" expected) | |
| Assertions.test <@ actual = (String i) @> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I suppose you're refering to this failure:
I think what's happening here is that Newtonsoft is more tolerant of improperly escaped json strings. Note that if I slightly change your tests to the following:
Then it always passes without issue. I'll file an issue regardless.