diff --git a/src/Paket.Core/TemplateFile.fs b/src/Paket.Core/TemplateFile.fs index 18d686d7d5..bb0b1ae4d3 100644 --- a/src/Paket.Core/TemplateFile.fs +++ b/src/Paket.Core/TemplateFile.fs @@ -225,7 +225,9 @@ module internal TemplateFile = |> fun x -> defaultArg x [] let private getOptionalInfo (map : Map) = - let title = Map.tryFind "title" map + let get (n : string) = Map.tryFind (n.ToLowerInvariant()) map + + let title = get "title" let owners = Map.tryFind "owners" map @@ -235,28 +237,28 @@ module internal TemplateFile = |> Array.toList) |> fun x -> defaultArg x [] - let releaseNotes = Map.tryFind "releaseNotes" map - let summary = Map.tryFind "summary" map - let language = Map.tryFind "language" map - let projectUrl = Map.tryFind "projectUrl" map - let iconUrl = Map.tryFind "iconUrl" map - let licenseUrl = Map.tryFind "licenseUrl" map - let copyright = Map.tryFind "copyright" map + let releaseNotes = get "releaseNotes" + let summary = get "summary" + let language = get "language" + let projectUrl = get "projectUrl" + let iconUrl = get "iconUrl" + let licenseUrl = get "licenseUrl" + let copyright = get "copyright" let requireLicenseAcceptance = - match Map.tryFind "requireLicenseAcceptance" map with + match get "requireLicenseAcceptance" with | Some x when x.ToLower() = "true" -> true | _ -> false let tags = - Map.tryFind "tags" map + get "tags" |> Option.map (fun t -> t.Split ' ' - |> Array.map (fun t -> t.Trim()) + |> Array.map (fun t -> t.Trim().Trim(',')) |> Array.toList) |> fun x -> defaultArg x [] let developmentDependency = - match Map.tryFind "developmentDependency" map with + match get "developmentDependency" with | Some x when x.ToLower() = "true" -> true | _ -> false diff --git a/tests/Paket.Tests/TemplateFileParsing.fs b/tests/Paket.Tests/TemplateFileParsing.fs index 523e9107b5..af6868c773 100644 --- a/tests/Paket.Tests/TemplateFileParsing.fs +++ b/tests/Paket.Tests/TemplateFileParsing.fs @@ -114,7 +114,7 @@ description A short description """ [] -let DescriptionTest = """type project +let RealTest = """type project owners Thomas Petricek, David Thomas, Ryan Riley, Steffen Forkmann authors @@ -138,12 +138,59 @@ description """ +[] +let FullTest = """type project +title Chessie.Rop +owners + Steffen Forkmann, Max Malook, Tomasz Heimowski +authors + Steffen Forkmann, Max Malook, Tomasz Heimowski +projectUrl + http://github.com/fsprojects/Chessie +iconUrl + https://raw.githubusercontent.com/fsprojects/Chessie/master/docs/files/img/logo.png +licenseUrl + http://github.com/fsprojects/Chessie/blob/master/LICENSE.txt +requireLicenseAcceptance + false +copyright + Copyright 2015 +LANGUAGE + en-gb +tags + rop, fsharp F# +summary + Railway-oriented programming for .NET +description + Railway-oriented programming for .NET""" + [] -[] +[] +[] let ``Valid file input recognised as valid`` (fileContent : string) = fileContent |> strToStream |> TemplateFile.Parse |> (function | Failure _ -> false | Success _ -> true) |> shouldEqual true +[] +let ``Optional fields are read`` (fileContent : string) = + let sut = + fileContent |> strToStream |> TemplateFile.Parse + |> returnOrFail + |> function + | CompleteInfo (_, opt) + | ProjectInfo (_, opt) -> opt + sut.Title |> shouldEqual (Some "Chessie.Rop") + sut.Copyright |> shouldEqual (Some "Copyright 2015") + sut.Summary |> shouldEqual (Some "Railway-oriented programming for .NET") + sut.IconUrl |> shouldEqual (Some "https://raw.githubusercontent.com/fsprojects/Chessie/master/docs/files/img/logo.png") + sut.LicenseUrl |> shouldEqual (Some "http://github.com/fsprojects/Chessie/blob/master/LICENSE.txt") + sut.ProjectUrl |> shouldEqual (Some "http://github.com/fsprojects/Chessie") + sut.Tags |> shouldEqual ["rop";"fsharp";"F#"] + sut.Owners |> shouldEqual ["Steffen Forkmann";"Max Malook";"Tomasz Heimowski"] + sut.RequireLicenseAcceptance |> shouldEqual false + sut.DevelopmentDependency |> shouldEqual false + sut.Language |> shouldEqual (Some "en-gb") + [] let Dependency1 = """type file id My.Thing