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

Allow comments in the references file. #2477

Merged
merged 1 commit into from
Jul 1, 2017
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
9 changes: 9 additions & 0 deletions src/Paket.Core/Common/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,15 @@ let removeFile (fileName : string) =
let normalizeLineEndings (text : string) =
text.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", Environment.NewLine)

let removeComment (text:string) =
let stripComment pos =
if pos = 0 || text.[pos-1] = ' ' then text.Substring(0,pos).Trim()
else text
match text.IndexOf "//", text.IndexOf "#" with
| -1 , -1 -> text
| -1, p | p , -1 -> stripComment p
| p1, p2 -> stripComment (min p1 p2)

// adapted from MiniRx
// http://minirx.codeplex.com/
[<AutoOpen>]
Expand Down
9 changes: 0 additions & 9 deletions src/Paket.Core/Dependencies/DependenciesFileParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,6 @@ module DependenciesFileParser =
| PackageSource of PackageSource
| Cache of Cache

let private removeComment (text:string) =
let stripComment pos =
let ln = text.Substring(0,pos).Trim() in printfn "%s" ln; ln
match text.IndexOf "//", text.IndexOf "#" with
| -1 , -1 -> text
| -1, p | p , -1 -> stripComment p
| p1, p2 -> stripComment (min p1 p2)


let private (|Remote|_|) (line:string) =
match line.Trim() with
| String.RemovePrefix "source" _ as trimmed ->
Expand Down
3 changes: 2 additions & 1 deletion src/Paket.Core/PaketConfigFiles/ReferencesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type ReferencesFile =
static member FromLines(lines : string[]) =
let groupedLines =
lines
|> Array.fold (fun state line ->
|> Seq.map removeComment
|> Seq.fold (fun state line ->
match state with
| [] -> failwithf "error while parsing %A" lines
| ((name,lines) as currentGroup)::otherGroups ->
Expand Down
35 changes: 34 additions & 1 deletion tests/Paket.Tests/ReferencesFile/ReferencesFileSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,37 @@ File:countdown.js Scripts link: false"""
[<Test>]
let ``should parse and serialize reffiles with aliases``() =
let refFile = ReferencesFile.FromLines(toLines refFileWithAliases).ToString()
normalizeLineEndings refFile |> shouldEqual (normalizeLineEndings refFileWithAliases)
normalizeLineEndings refFile |> shouldEqual (normalizeLineEndings refFileWithAliases)


let refFileWithComments = """
# separate-line comment with hash
Castle.Windsor # same-line comment with hash
// separate-line comment with slashes
Newtonsoft.Json // same-line comment with slashes

// multiline
// comment
// here
// throw in some leading spaces
# and a hash
FSharp.Core //

File: Some//File#With#Hashes.dot #and a comment after
File: AnotherFile.txt //pluscomment

// Some empty comments:
#
//
# and another comment at the very end
"""

[<Test>]
let ``should parse and serialize reffiles with comments``() =
let refFile = ReferencesFile.FromLines(toLines refFileWithComments).Groups.[Constants.MainDependencyGroup]

[for p in refFile.NugetPackages -> p.Name.Name]
|> shouldEqual ["Castle.Windsor"; "Newtonsoft.Json"; "FSharp.Core"]

[for f in refFile.RemoteFiles -> f.Name]
|> shouldEqual ["Some//File#With#Hashes.dot"; "AnotherFile.txt"]