<commit_before>﻿module Paket.DependenciesFile.PropertyTests

open System
open FsCheck
open FsCheck.NUnit
open Paket

let source = Gen.constant "source https://nuget.org/api/v2"

let nuget = Gen.constant "nuget FsCheck"

let github = Gen.constant "github forki/FsUnit FsUnit.fs"

let gist = Gen.constant "gist Thorium/1972349 timestamp.fs"

let http = Gen.constant "http http://www.fssnip.net/1n decrypt.fs"

let depLine = Gen.oneof [source; nuget; github; gist; http]

type DFFileGenerator =
    static member StringArray() = 
        {new Arbitrary<string[]>() with
            override x.Generator = Gen.arrayOf depLine
            override x.Shrinker t = Seq.empty }

let _ = PropertyAttribute(Verbose = true)

[<Property(
    Arbitrary = [|typeof<DFFileGenerator>|],
    Verbose = true)>]
let ``round trip`` (lines : string[]) =
    let df = DependenciesFile(DependenciesFileParser.parseDependenciesFile "dummy" lines)
    df.ToString() = String.concat Environment.NewLine lines <commit_msg>comment not allowed after http, github or gist dependency<commit_after>﻿module Paket.DependenciesFile.PropertyTests

open System
open FsCheck
open FsCheck.NUnit
open Paket
open TestHelpers

let nl = Environment.NewLine
let linesToString s = String.concat nl s

let source = Gen.constant "source https://nuget.org/api/v2"

let nuget = Gen.constant "nuget FsCheck"

let github = Gen.constant "github forki/FsUnit FsUnit.fs"

let gist = Gen.constant "gist Thorium/1972349 timestamp.fs"

let http = Gen.constant "http http://www.fssnip.net/1n decrypt.fs"

let empty = Gen.constant ""

let line = Gen.oneof [source; nuget; github; gist; http; empty]

let slashComment = Gen.constant "//comment"
let lineWComment = 
    let line = Gen.oneof [source; nuget; empty]
    (line, slashComment)
    ||> Gen.map2 (fun l c -> l + " " + c)

let hashComment = Gen.constant "#comment"
let comment = Gen.oneof [slashComment; hashComment]

let depLine = Gen.frequency [80, line; 10, lineWComment; 10, comment]

let globalOpts = 
    Gen.elements 
        [ "references: strict"; "framework: net35, net40"; "content: none"; "import_targets: false"; "copy_local: false" ]
    |> Gen.arrayOf
    |> Gen.map (Seq.distinct >> Array.ofSeq)

let generator = 
    (Gen.arrayOf depLine, globalOpts)
    ||> Gen.map2 (fun lines globalOpts -> Array.append globalOpts lines)
    |> Gen.map linesToString

let shrinker s =
    let lines = s |> toLines
    seq { 
        for i in [0 .. lines.Length - 1] do
            yield seq { 
                for j in [0 .. lines.Length - 1] do
                    if i <> j then yield lines.[j] }
                |> linesToString}

type DFFileGenerator =
    static member StringArray() = 
        {new Arbitrary<string>() with
            override x.Generator = generator
            override x.Shrinker t = shrinker t }

let _ = PropertyAttribute(Verbose = true)

[<Property(
    Arbitrary = [|typeof<DFFileGenerator>|],
    Verbose = true)>]
let ``round trip`` (contents : string) =
    let lines = toLines contents
    let df = DependenciesFile(DependenciesFileParser.parseDependenciesFile "dummy" lines)
    df.ToString() = String.concat Environment.NewLine lines 
{'fraction_non_alphanumeric': 0.1116015132408575, 'fraction_numerical': 0.010718789407313998, 'mean_word_length': 3.305291723202171, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, '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': '2885867', 'n_tokens_mistral': 1052, 'n_tokens_neox': 1001, 'n_words': 296}