Skip to content

Commit

Permalink
Merge branch 'sln-items-with-spaces' into main
Browse files Browse the repository at this point in the history
Fixes #13
  • Loading branch information
timabell committed Nov 19, 2024
2 parents bc297b6 + fa26e7d commit 8f3887c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
8 changes: 5 additions & 3 deletions SlnEditor/Parsers/SolutionFolderDefinitionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@ internal class SolutionFolderDefinitionParser
/// </summary>
public static string? ParseFile(string line, int lineNumber, bool bestEffort)
{
var match = Regex.Match(line, @"(?<key>[\S]+)\s*=\s*(?<value>[\S]+)");
var match = Regex.Match(line, @"(?<key>[\S ]+)\s*=\s*(?<value>[\S ]+)");
if (!match.Success)
{
return null;
}

if (!bestEffort && match.Groups["key"].Value != match.Groups["value"].Value)
var key = match.Groups["key"].Value.Trim();
var value = match.Groups["value"].Value.Trim();
if (!bestEffort && key != value)
{
throw new UnexpectedSolutionStructureException(
$"Unexpected solution file format. Expected 'path/to/file.txt = path/to/file.txt'. Line {lineNumber}.");
}

return match.Groups["key"].Value;
return key;
}
}
}
15 changes: 10 additions & 5 deletions Tests/ParseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class ParseTests
something\something.txt = something\something.txt
test123.txt = test123.txt
test456.txt = test456.txt
test 789.txt = test 789.txt
EndProjectSection
EndProject
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""NestedSolutionFolder"", ""NestedSolutionFolder"", ""{DA01EB1C-A2F7-4851-AD58-D1319B29EE3D}""
Expand Down Expand Up @@ -526,9 +527,13 @@ public void Should_Be_Able_To_Parse_TestSln_Solution_Correctly()
firstSolutionFolder
.Files
.Should()
.Contain(file => file == "something.txt" ||
file == "test123.txt" ||
file == "test456.txt");
.BeEquivalentTo(new List<string>
{
"something\\something.txt",
"test123.txt",
"test456.txt",
"test 789.txt",
});

var nestedSolutionFolder = solution
.FlatProjectList()
Expand All @@ -542,8 +547,8 @@ public void Should_Be_Able_To_Parse_TestSln_Solution_Correctly()
.Should()
.Contain(file => file == "testNested1.txt");

solution.GlobalSection<NestedProjectsSection>().SourceLine.Should().Be(115);
solution.GlobalSection<SolutionPropertiesSection>().SourceLine.Should().Be(121);
solution.GlobalSection<NestedProjectsSection>().SourceLine.Should().Be(116);
solution.GlobalSection<SolutionPropertiesSection>().SourceLine.Should().Be(122);
}

[Fact]
Expand Down
20 changes: 20 additions & 0 deletions Tests/RoundTripTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,25 @@ public class RoundTripTests
EndGlobalSection
EndGlobal";

private const string SlnContentsFilesWithSpaces = @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""Solution Items"", ""Solution Items"", ""{34448D97-83B4-4E18-A461-149287204509}""
EndProject
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""some folder"", ""some folder"", ""{F928870D-CBD1-4FD0-9A10-2784B9F8EDE8}""
ProjectSection(SolutionItems) = preProject
some folder\some file.txt = some folder\some file.txt
EndProjectSection
EndProject
Global
GlobalSection(NestedProjects) = preSolution
{F928870D-CBD1-4FD0-9A10-2784B9F8EDE8} = {34448D97-83B4-4E18-A461-149287204509}
EndGlobalSection
EndGlobal
";

[Theory]
[InlineData(nameof(SlnContentsSlnParser), SlnContentsSlnParser)]
[InlineData(nameof(SlnContentsTestSln), SlnContentsTestSln)]
Expand All @@ -603,6 +622,7 @@ public class RoundTripTests
[InlineData(nameof(SlnContentsNoProperties), SlnContentsNoProperties)]
[InlineData(nameof(SlnContentsSlnSync), SlnContentsSlnSync)]
[InlineData(nameof(SlnContentsHttpAbstractions), SlnContentsHttpAbstractions)]
[InlineData(nameof(SlnContentsFilesWithSpaces), SlnContentsFilesWithSpaces)]
public void Should_RoundTripFile(string name, string originalSln)
{
// Arrange
Expand Down

0 comments on commit 8f3887c

Please sign in to comment.