<commit_before>module Pfarah.Tests

open Pfarah
open Pfarah.Operators
open Pfarah.Functional
open Utils
open NUnit.Framework
open System
open System.IO
open System.Text
open System.Collections.Generic
open System.Diagnostics

let shouldEqual (x : 'a) (y : 'a) = Assert.AreEqual(x, y, sprintf "Expected: %A\nActual: %A" x y)

let parse str =
  match (ParaValue.Parse str) with
  | ParaValue.Record properties -> properties
  | _ -> failwith "Expected a record"

[<Test>]
let ``parse basic object`` () =
  parse "foo=bar"
  |> shouldEqual [| ("foo", ParaValue.String "bar")|]

[<Test>]
let ``parse quoted string`` () =
  parse "foo=\"bar\""
  |> shouldEqual [| ("foo", ParaValue.String "bar")|]

[<Test>]
let ``parse number`` () =
  parse "foo=-2.314"
  |> shouldEqual [| ("foo", ParaValue.Number -2.314)|]

[<Test>]
let ``parse yes`` () =
  parse "foo=yes"
  |> shouldEqual [| ("foo", ParaValue.Bool true)|]

[<Test>]
let ``parse colon`` () =
  parse "foo=bar:qux"
  |> shouldEqual [| ("foo", ParaValue.String "bar:qux")|]

[<Test>]
let ``parse quoted key`` () =
  parse "\"foo\"=\"11\""
  |> shouldEqual [| ("foo", ParaValue.String "11")|]

[<Test>]
let ``parse double equal key`` () =
  parse "flags={bar=a ==b}"
  |> shouldEqual [| ("flags",
                      ParaValue.Record ([|("bar", ParaValue.String "a")
                                          ("=", ParaValue.String("b")) |]))|]

[<Test>]
let ``parse date`` () =
  parse "foo=1492.3.2"
  |> shouldEqual [| ("foo", ParaValue.Date (new DateTime(1492,3,2)))|]

[<Test>]
let ``parse invalid date is none`` () =
  parse "foo=1.a.2"
  |> shouldEqual [| ("foo", ParaValue.String "1.a.2")|]

[<Test>]
let ``parse no`` () =
  parse "foo=no"
  |> shouldEqual [| ("foo", ParaValue.Bool false)|]

[<Test>]
let ``parse list of one`` () =
  parse "foo={bar}"<commit_msg>Test to ensure we can parse variables<commit_after>module Pfarah.Tests

open Pfarah
open Pfarah.Operators
open Pfarah.Functional
open Utils
open NUnit.Framework
open System
open System.IO
open System.Text
open System.Collections.Generic
open System.Diagnostics

let shouldEqual (x : 'a) (y : 'a) = Assert.AreEqual(x, y, sprintf "Expected: %A\nActual: %A" x y)

let parse str =
  match (ParaValue.Parse str) with
  | ParaValue.Record properties -> properties
  | _ -> failwith "Expected a record"

[<Test>]
let ``parse basic object`` () =
  parse "foo=bar"
  |> shouldEqual [| ("foo", ParaValue.String "bar")|]

[<Test>]
let ``parse quoted string`` () =
  parse "foo=\"bar\""
  |> shouldEqual [| ("foo", ParaValue.String "bar")|]

[<Test>]
let ``parse number`` () =
  parse "foo=-2.314"
  |> shouldEqual [| ("foo", ParaValue.Number -2.314)|]

[<Test>]
let ``parse yes`` () =
  parse "foo=yes"
  |> shouldEqual [| ("foo", ParaValue.Bool true)|]

[<Test>]
let ``parse colon`` () =
  parse "foo=bar:qux"
  |> shouldEqual [| ("foo", ParaValue.String "bar:qux")|]

[<Test>]
let ``parse quoted key`` () =
  parse "\"foo\"=\"11\""
  |> shouldEqual [| ("foo", ParaValue.String "11")|]

[<Test>]
let ``parse double equal key`` () =
  parse "flags={bar=a ==b}"
  |> shouldEqual [| ("flags",
                      ParaValue.Record ([|("bar", ParaValue.String "a")
                                          ("=", ParaValue.String("b")) |]))|]

[<Test>]
let ``parse date`` () =
  parse "foo=1492.3.2"
  |> shouldEqual [| ("foo", ParaValue.Date (new DateTime(1492,3,2)))|]

[<Test>]
let ``parse variable`` () =
  parse "@foo = 2"
  |> shouldEqual [| ("@foo", ParaValue.Number 2.0 )|]

[<Test>]
let ``parse invalid date is none`` () =
  parse "foo=1.a.2"
  |> shouldEqual [| ("foo", ParaValue.String "1.a.2")|]

[<Test>]
let ``parse no`` () =
  parse "foo=no"
  |> shouldEqual [| ("foo", ParaValue.Bool false)|]

[<Test>]
let ``parse list of one`` () =
  parse "foo={bar}"
{'fraction_non_alphanumeric': 0.21525019857029387, 'fraction_numerical': 0.015620863118877415, 'mean_word_length': 3.6355828220858895, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '331784', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1361, 'n_words': 358}