<commit_before>module Tests

open System
open System.Net
open System.Net.Mail

open Expecto
open FSONParser

type SimpleRecord = {Name : string}
type OptionRecord = {Name : string option}

type Region = 
    | BC | Alberta | Canada
let regionsData = "
  - BC
  - Alberta   "

type Address = 
    {Street: string;
    City: string; 
    Region: Region; 
    Postal: string option;
    Country: string;}
let addr = {
  Street = "245 West Howe";
  City = "Vancouver";
  Region = BC;
  Postal = Some("V68 5R3");
  Country = "Canada"}
let addrData = " 
  Street: 245 West Howe 
  City: Vancouver 
  Region: BC 
  Postal: V68 5R3
  Country: Canada 
 "

  



[<Tests>]
let tests =
  testList "All" [
    testList "Primatives" [
      testCase "int16" <| fun _ -> Expect.equal ((parseFSON typeof<int16> "12") :?> int16)  12s ""
      testCase "int32" <| fun _ -> Expect.equal ((parseFSON typeof<int32> "12") :?> int32)  12l ""
      testCase "int64" <| fun _ -> Expect.equal ((parseFSON typeof<int64> "12") :?> int64)  12L ""
      testCase "uint16" <| fun _ -> Expect.equal ((parseFSON typeof<uint16> "12") :?> uint16)  12us ""
      testCase "uint32" <| fun _ -> Expect.equal ((parseFSON typeof<uint32> "12") :?> uint32)  12ul ""
      testCase "uint64" <| fun _ -> Expect.equal ((parseFSON typeof<uint64> "12") :?> uint64)  12UL ""

      testCase "single" <| fun _ -> Expect.equal ((parseFSON typeof<Single> "1.2") :?> Single)  1.2f ""
      testCase "double" <| fun _ -> Expect.equal ((parseFSON typeof<Double> "1.2") :?> Double)  1.2 ""
      testCase "double" <| fun _ -> Expect.equal ((parseFSON typeof<Double> "1.2e10") :?> Double)  1.2e10 ""
      testCase "decimal" <| fun _ -> Expect.equal ((parseFSON typeof<Decimal> "1.2") :?> Decimal)  1.2m ""
      testCase "boolean" <| fun _ -> Expect.equal ((parseFSON typeof<Boolean> "true") :?> Boolean)  true ""

      testCase "byte" <| fun _ -> Expect.equal ((parseFSON typeof<byte> "12") :?> byte)  12uy ""
      testCase "sbyte" <| fun _ -> Expect.equal ((parseFSON typeof<sbyte> "12") :?> sbyte)  12y ""

      testCase "char" <| fun _ -> Expect.equal ((parseFSON typeof<char> "a") :?> char)  'a' ""
      testCase "string" <| fun _ -> Expect.equal ((parseFSON typeof<string> "foo") :?> string)  "foo" ""
      testCase "string empty" <| fun _ -> Expect.equal ((parseFSON typeof<string> "") :?> string)  "" ""
      testCase "string only whitespace" <| fun _ -> Expect.equal ((parseFSON typeof<string> "  ") :?> string)  "" ""

      testCase "DateTime" <| fun _ -> Expect.equal ((parseFSON typeof<DateTime> " feb 1, 2016 ") :?> DateTime)  (DateTime.Parse "Feb 1, 2016") ""
      testCase "Guid" <| fun _ -> Expect.equal ((parseFSON typeof<Guid> " 872ccb13-2e12-4eec-a2f5-ab64b3652b1c ") :?> Guid)  (Guid.Parse "872ccb13-2e12-4eec-a2f5-ab64b3652b1c") ""
      testCase "Uri" <| fun _ -> Expect.equal ((parseFSON typeof<Uri> " http://something.com ") :?> Uri)  (Uri.Parse "http://something.com") ""
      testCase "IP Address" <| fun _ -> Expect.equal ((parseFSON typeof<IPAddress> " 127.0.0.1 ") :?> IPAddress)  (IPAddress.Parse "127.0.0.1")  ""
      testCase "MailAddress" <| fun _ -> Expect.equal ((parseFSON typeof<MailAddress> " <EMAIL> ") :?> MailAddress)  (MailAddress.Parse "<EMAIL>") ""
    ]

    testList "Records" [
      testCase "simple record" <| fun _ ->
        let record = (parseFSON typeof<SimpleRecord> "Name: Joe") :?> SimpleRecord
        Expect.isTrue (record = {Name = "Joe"}) ""

      testCase "option record" <| fun _ ->
        let record = (parseFSON typeof<OptionRecord> "Name: Joe") :?> OptionRecord
        Expect.isTrue (record = {Name = Some("Joe")}) ""

      testCase "parse address" <| fun _ ->
        let address = (parseFSON typeof<Address> addrData) :?> Address
        Expect.isTrue (address = addr) ""
    ]

    testList "Unions" [
      testCase "zero field DU" <| fun _ -> Expect.equal ((parseFSON typeof<Region> " BC ") :?> Region)  Region.BC ""
    ]

    testList "Collections" [
      testCase "DU List" <| fun _ -> 
        Expect.equal ((parseFSON typeof<Region list> regionsData) :?> Region list) [BC; Alberta] ""

      testCase "String List" <| fun _ -> 
        Expect.equal ((parseFSON typeof<string list> regionsData) :?> string list) ["BC"; "Alberta"] ""

      testCase "DU Array" <| fun _ -> 
        Expect.equal ((parseFSON typeof<Region array> regionsData) :?> Region array) [|BC; Alberta|] ""
    ]

    testList "Special Cases" [
      testCase "non sep DU List" <| fun _ -> 
        Expect.equal ((parseFSON typeof<Region list> "BC Alberta") :?> Region list) [BC; Alberta] ""
    ]
  ]


  
<commit_msg>tests<commit_after>module Tests

open System
open System.Net
open System.Net.Mail

open Expecto
open FSONParser

type SimpleRecord = {Name : string}
type OptionRecord = {Name : string option}

type Region = 
    | BC | Alberta | Canada
let regionsData = "
  - BC
  - Alberta   "

type Address = 
    {Street: string;
    City: string; 
    Region: Region; 
    Postal: string option;
    Country: string;}
let addr = {
  Street = "245 West Howe";
  City = "Vancouver";
  Region = BC;
  Postal = Some("V68 5R3");
  Country = "Canada"}
let addrData = " 
  Street: 245 West Howe 
  City: Vancouver 
  Region: BC 
  Postal: V68 5R3
  Country: Canada 
 "

  



[<Tests>]
let tests =
  testList "All" [
    testList "Primatives" [
      testCase "int16" <| fun _ -> Expect.equal ((parseFSON typeof<int16> "12") :?> int16)  12s ""
      testCase "int32" <| fun _ -> Expect.equal ((parseFSON typeof<int32> "12") :?> int32)  12l ""
      testCase "int64" <| fun _ -> Expect.equal ((parseFSON typeof<int64> "12") :?> int64)  12L ""
      testCase "uint16" <| fun _ -> Expect.equal ((parseFSON typeof<uint16> "12") :?> uint16)  12us ""
      testCase "uint32" <| fun _ -> Expect.equal ((parseFSON typeof<uint32> "12") :?> uint32)  12ul ""
      testCase "uint64" <| fun _ -> Expect.equal ((parseFSON typeof<uint64> "12") :?> uint64)  12UL ""

      testCase "single" <| fun _ -> Expect.equal ((parseFSON typeof<Single> "1.2") :?> Single)  1.2f ""
      testCase "double" <| fun _ -> Expect.equal ((parseFSON typeof<Double> "1.2") :?> Double)  1.2 ""
      testCase "double" <| fun _ -> Expect.equal ((parseFSON typeof<Double> "1.2e10") :?> Double)  1.2e10 ""
      testCase "decimal" <| fun _ -> Expect.equal ((parseFSON typeof<Decimal> "1.2") :?> Decimal)  1.2m ""
      testCase "boolean" <| fun _ -> Expect.equal ((parseFSON typeof<Boolean> "true") :?> Boolean)  true ""

      testCase "byte" <| fun _ -> Expect.equal ((parseFSON typeof<byte> "12") :?> byte)  12uy ""
      testCase "sbyte" <| fun _ -> Expect.equal ((parseFSON typeof<sbyte> "12") :?> sbyte)  12y ""

      testCase "char" <| fun _ -> Expect.equal ((parseFSON typeof<char> "a") :?> char)  'a' ""
      testCase "string" <| fun _ -> Expect.equal ((parseFSON typeof<string> "foo") :?> string)  "foo" ""
      testCase "string empty" <| fun _ -> Expect.equal ((parseFSON typeof<string> "") :?> string)  "" ""
      testCase "string only whitespace" <| fun _ -> Expect.equal ((parseFSON typeof<string> "  ") :?> string)  "" ""

      testCase "DateTime" <| fun _ -> Expect.equal ((parseFSON typeof<DateTime> " feb 1, 2016 ") :?> DateTime)  (DateTime.Parse "Feb 1, 2016") ""
      testCase "Guid" <| fun _ -> Expect.equal ((parseFSON typeof<Guid> " 872ccb13-2e12-4eec-a2f5-ab64b3652b1c ") :?> Guid)  (Guid.Parse "872ccb13-2e12-4eec-a2f5-ab64b3652b1c") ""
      testCase "Uri" <| fun _ -> Expect.equal ((parseFSON typeof<Uri> " http://something.com ") :?> Uri)  (Uri.Parse "http://something.com") ""
      testCase "IP Address" <| fun _ -> Expect.equal ((parseFSON typeof<IPAddress> " 127.0.0.1 ") :?> IPAddress)  (IPAddress.Parse "127.0.0.1")  ""
      testCase "MailAddress" <| fun _ -> Expect.equal ((parseFSON typeof<MailAddress> " <EMAIL> ") :?> MailAddress)  (MailAddress.Parse "<EMAIL>") ""
    ]

    testList "Records" [
      testCase "simple record" <| fun _ ->
        let record = (parseFSON typeof<SimpleRecord> "Name: Joe") :?> SimpleRecord
        Expect.isTrue (record = {Name = "Joe"}) ""

      testCase "option record" <| fun _ ->
        let record = (parseFSON typeof<OptionRecord> "Name: Joe") :?> OptionRecord
        Expect.isTrue (record = {Name = Some("Joe")}) ""

      testCase "parse address" <| fun _ ->
        let address = (parseFSON typeof<Address> addrData) :?> Address
        Expect.isTrue (address = addr) ""
    ]

    testList "Unions" [
      testCase "zero field DU" <| fun _ -> Expect.equal ((parseFSON typeof<Region> " BC ") :?> Region)  Region.BC ""
    ]

    testList "Collections" [
      testCase "DU List" <| fun _ -> 
        Expect.equal ((parseFSON typeof<Region list> regionsData) :?> Region list) [BC; Alberta] ""

      testCase "String List" <| fun _ -> 
        Expect.equal ((parseFSON typeof<string list> regionsData) :?> string list) ["BC"; "Alberta"] ""

      testCase "DU Array" <| fun _ -> 
        Expect.equal ((parseFSON typeof<Region array> regionsData) :?> Region array) [|BC; Alberta|] ""
    ]

    testList "Special Cases" [
      ptestCase "non sep DU List" <| fun _ -> 
        Expect.equal ((parseFSON typeof<Region list> "BC Alberta") :?> Region list) [BC; Alberta] ""
    ]
  ]


  

{'fraction_non_alphanumeric': 0.17205930094145655, 'fraction_numerical': 0.034628286981928366, 'mean_word_length': 3.058849363197189, 'pattern_counts': {'":': 0, '<': 129, '<?xml version=': 0, '>': 189, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1054355', 'n_tokens_mistral': 3374, 'n_tokens_neox': 3127, 'n_words': 810}