Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix template optional field parsing #666

Merged
merged 2 commits into from
Feb 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/Paket.Core/TemplateFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 225,9 @@ module internal TemplateFile =
|> fun x -> defaultArg x []

let private getOptionalInfo (map : Map<string, string>) =
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
Expand All @@ -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

Expand Down
51 changes: 49 additions & 2 deletions tests/Paket.Tests/TemplateFileParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 114,7 @@ description A short description
"""

[<Literal>]
let DescriptionTest = """type project
let RealTest = """type project
owners
Thomas Petricek, David Thomas, Ryan Riley, Steffen Forkmann
authors
Expand All @@ -138,12 138,59 @@ description

"""

[<Literal>]
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"""

[<TestCase(ValidWithoutVersion)>]
[<TestCase(DescriptionTest)>]
[<TestCase(RealTest)>]
[<TestCase(FullTest)>]
let ``Valid file input recognised as valid`` (fileContent : string) =
fileContent |> strToStream |> TemplateFile.Parse |> (function | Failure _ -> false | Success _ -> true)
|> shouldEqual true

[<TestCase(FullTest)>]
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")

[<Literal>]
let Dependency1 = """type file
id My.Thing
Expand Down