diff --git a/tests/Paket.Tests/DependenciesFile/PropertyTests.fs b/tests/Paket.Tests/DependenciesFile/PropertyTests.fs index a48240b259..f7129d3275 100644 --- a/tests/Paket.Tests/DependenciesFile/PropertyTests.fs +++ b/tests/Paket.Tests/DependenciesFile/PropertyTests.fs @@ -4,6 +4,10 @@ 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" @@ -15,19 +19,53 @@ 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] +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() with - override x.Generator = Gen.arrayOf depLine - override x.Shrinker t = Seq.empty } + {new Arbitrary() with + override x.Generator = generator + override x.Shrinker t = shrinker t } let _ = PropertyAttribute(Verbose = true) [|], Verbose = true)>] -let ``round trip`` (lines : string[]) = +let ``round trip`` (contents : string) = + let lines = toLines contents let df = DependenciesFile(DependenciesFileParser.parseDependenciesFile "dummy" lines) df.ToString() = String.concat Environment.NewLine lines \ No newline at end of file