@@ -4,6 +4,10 @@ open System
44open FsCheck
55open FsCheck.NUnit
66open Paket
7+ open TestHelpers
8+
9+ let nl = Environment.NewLine
10+ let linesToString s = String.concat nl s
711
812let source = Gen.constant " source https://nuget.org/api/v2"
913
@@ -15,19 +19,53 @@ let gist = Gen.constant "gist Thorium/1972349 timestamp.fs"
1519
1620let http = Gen.constant " http http://www.fssnip.net/1n decrypt.fs"
1721
18- let depLine = Gen.oneof [ source; nuget; github; gist; http]
22+ let empty = Gen.constant " "
23+
24+ let line = Gen.oneof [ source; nuget; github; gist; http; empty]
25+
26+ let slashComment = Gen.constant " //comment"
27+ let lineWComment =
28+ let line = Gen.oneof [ source; nuget; empty]
29+ ( line, slashComment)
30+ ||> Gen.map2 ( fun l c -> l + " " + c)
31+
32+ let hashComment = Gen.constant " #comment"
33+ let comment = Gen.oneof [ slashComment; hashComment]
34+
35+ let depLine = Gen.frequency [ 80 , line; 10 , lineWComment; 10 , comment]
36+
37+ let globalOpts =
38+ Gen.elements
39+ [ " references: strict" ; " framework: net35, net40" ; " content: none" ; " import_targets: false" ; " copy_local: false" ]
40+ |> Gen.arrayOf
41+ |> Gen.map ( Seq.distinct >> Array.ofSeq)
42+
43+ let generator =
44+ ( Gen.arrayOf depLine, globalOpts)
45+ ||> Gen.map2 ( fun lines globalOpts -> Array.append globalOpts lines)
46+ |> Gen.map linesToString
47+
48+ let shrinker s =
49+ let lines = s |> toLines
50+ seq {
51+ for i in [ 0 .. lines.Length - 1 ] do
52+ yield seq {
53+ for j in [ 0 .. lines.Length - 1 ] do
54+ if i <> j then yield lines.[ j] }
55+ |> linesToString}
1956
2057type DFFileGenerator =
2158 static member StringArray () =
22- { new Arbitrary< string[] >() with
23- override x.Generator = Gen.arrayOf depLine
24- override x.Shrinker t = Seq.empty }
59+ { new Arbitrary< string>() with
60+ override x.Generator = generator
61+ override x.Shrinker t = shrinker t }
2562
2663let _ = PropertyAttribute( Verbose = true )
2764
2865[<Property(
2966 Arbitrary = [| typeof< DFFileGenerator>|],
3067 Verbose = true ) >]
31- let ``round trip`` ( lines : string []) =
68+ let ``round trip`` ( contents : string ) =
69+ let lines = toLines contents
3270 let df = DependenciesFile( DependenciesFileParser.parseDependenciesFile " dummy" lines)
3371 df.ToString() = String.concat Environment.NewLine lines
0 commit comments