<commit_before>﻿module Paket.TestHelpers

open Paket
open System

let DictionaryDiscovery(graph : seq<string * string * (string * VersionRange) list>) = 
    { new IDiscovery with
          
          member __.GetPackageDetails(true, sourceType, source, package, version) = 
              async { 
                  let dependencies =
                    graph
                         |> Seq.filter (fun (p, v, _) -> p = package && v = version)
                         |> Seq.map (fun (_, _, d) -> d)
                         |> Seq.head
                         |> List.map (fun (p, v) -> 
                                { Name = p
                                  VersionRange = v
                                  SourceType = sourceType
                                  Source = source })
                  return "",dependencies
              }
          
          member __.GetVersions(sourceType, source, package) = 
              async { 
                  return graph
                         |> Seq.filter (fun (p, _, _) -> p = package)
                         |> Seq.map (fun (_, v, _) -> v)
              } }

let resolve graph (dependencies: (string * VersionRange) seq) =
    let packages = dependencies |> Seq.map (fun (n,v) -> { Name = n; VersionRange = v; SourceType = ""; Source = "" })
    Resolver.Resolve(true, DictionaryDiscovery graph, packages)

let getVersion resolved =
    match resolved with
    | ResolvedDependency.Resolved x ->
        match x.Referenced.VersionRange with
        | Specific v -> v.ToString()

let getDefiningPackage resolved =
    match resolved with
    | ResolvedDependency.Resolved (FromPackage x) -> x.Defining.Name

let getDefiningVersion resolved =
    match resolved with
    | ResolvedDependency.Resolved (FromPackage x) -> 
        match x.Defining.VersionRange with
        | Specific v -> v.ToString()

let getSourceType resolved =
    match resolved with
    | ResolvedDependency.Resolved x -> x.Referenced.SourceType

let getSource resolved =
    match resolved with
    | ResolvedDependency.Resolved x -> x.Referenced.Source


let normalizeLineEndings (text:string) = text.Replace("\r\n","\n").Replace("\r","\n").Replace("\n",Environment.NewLine)

let toLines (text:string) = text.Replace("\r\n","\n").Replace("\r","\n").Split('\n')<commit_msg>Implement NuGet caching - closes #39<commit_after>﻿module Paket.TestHelpers

open Paket
open System

let DictionaryDiscovery(graph : seq<string * string * (string * VersionRange) list>) = 
    { new IDiscovery with
          
          member __.GetPackageDetails(force, sourceType, source, package, version) = 
              async { 
                  let dependencies =
                    graph
                         |> Seq.filter (fun (p, v, _) -> p = package && v = version)
                         |> Seq.map (fun (_, _, d) -> d)
                         |> Seq.head
                         |> List.map (fun (p, v) -> 
                                { Name = p
                                  VersionRange = v
                                  SourceType = sourceType
                                  Source = source })
                  return "",dependencies
              }
          
          member __.GetVersions(sourceType, source, package) = 
              async { 
                  return graph
                         |> Seq.filter (fun (p, _, _) -> p = package)
                         |> Seq.map (fun (_, v, _) -> v)
              } }

let resolve graph (dependencies: (string * VersionRange) seq) =
    let packages = dependencies |> Seq.map (fun (n,v) -> { Name = n; VersionRange = v; SourceType = ""; Source = "" })
    Resolver.Resolve(true, DictionaryDiscovery graph, packages)

let getVersion resolved =
    match resolved with
    | ResolvedDependency.Resolved x ->
        match x.Referenced.VersionRange with
        | Specific v -> v.ToString()

let getDefiningPackage resolved =
    match resolved with
    | ResolvedDependency.Resolved (FromPackage x) -> x.Defining.Name

let getDefiningVersion resolved =
    match resolved with
    | ResolvedDependency.Resolved (FromPackage x) -> 
        match x.Defining.VersionRange with
        | Specific v -> v.ToString()

let getSourceType resolved =
    match resolved with
    | ResolvedDependency.Resolved x -> x.Referenced.SourceType

let getSource resolved =
    match resolved with
    | ResolvedDependency.Resolved x -> x.Referenced.Source


let normalizeLineEndings (text:string) = text.Replace("\r\n","\n").Replace("\r","\n").Replace("\n",Environment.NewLine)

let toLines (text:string) = text.Replace("\r\n","\n").Replace("\r","\n").Split('\n')
{'fraction_non_alphanumeric': 0.11168384879725086, 'fraction_numerical': 0.000429553264604811, 'mean_word_length': 1.7281780902167545, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2993209', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1208, 'n_words': 317}