Skip to content

Commit

Permalink
Fix alt dir separator issue on mac (#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Sep 13, 2024
1 parent f9ccc29 commit 53e462f
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 50 deletions.
50 changes: 25 additions & 25 deletions docs/serializer-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public Task ScopedSerializerFluent()
.AddExtraSettings(_ => _.TypeNameHandling = TypeNameHandling.All);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3669-L3696' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScopedSerializer' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3675-L3702' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScopedSerializer' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -475,7 +475,7 @@ public Task IgnoreTypeFluent()
.IgnoreMembersWithType<ToIgnoreStruct>();
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2695-L2800' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddIgnoreType' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2701-L2806' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddIgnoreType' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand All @@ -485,7 +485,7 @@ Or globally:
```cs
VerifierSettings.IgnoreMembersWithType<ToIgnore>();
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2682-L2686' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddIgnoreTypeGlobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2688-L2692' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddIgnoreTypeGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -622,7 +622,7 @@ public Task ScrubTypeFluent()
.ScrubMembersWithType<ToIgnoreStruct>();
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2803-L2908' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddScrubType' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2809-L2914' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddScrubType' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand All @@ -632,7 +632,7 @@ Or globally:
```cs
VerifierSettings.ScrubMembersWithType<ToIgnore>();
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2688-L2692' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddScrubTypeGlobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2694-L2698' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddScrubTypeGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -711,7 +711,7 @@ public Task AddIgnoreInstanceFluent()
.IgnoreInstance<Instance>(_ => _.Property == "Ignore");
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2568-L2607' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddIgnoreInstance' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2574-L2613' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddIgnoreInstance' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand All @@ -721,7 +721,7 @@ Or globally:
```cs
VerifierSettings.IgnoreInstance<Instance>(_ => _.Property == "Ignore");
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2555-L2559' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddIgnoreInstanceGlobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2561-L2565' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddIgnoreInstanceGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -783,7 +783,7 @@ public Task AddScrubInstanceFluent()
.ScrubInstance<Instance>(_ => _.Property == "Ignore");
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2609-L2648' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddScrubInstance' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2615-L2654' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddScrubInstance' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand All @@ -793,7 +793,7 @@ Or globally:
```cs
VerifierSettings.ScrubInstance<Instance>(_ => _.Property == "Ignore");
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2561-L2565' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddScrubInstanceGlobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2567-L2571' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddScrubInstanceGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -838,7 +838,7 @@ public Task WithObsoleteProp()
return Verify(target);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3634-L3655' title='Snippet source file'>snippet source</a> | <a href='#snippet-WithObsoleteProp' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3640-L3661' title='Snippet source file'>snippet source</a> | <a href='#snippet-WithObsoleteProp' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -886,7 +886,7 @@ public Task WithObsoletePropIncludedFluent()
.IncludeObsoletes();
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3605-L3632' title='Snippet source file'>snippet source</a> | <a href='#snippet-WithObsoletePropIncluded' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3611-L3638' title='Snippet source file'>snippet source</a> | <a href='#snippet-WithObsoletePropIncluded' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand All @@ -896,7 +896,7 @@ Or globally:
```cs
VerifierSettings.IncludeObsoletes();
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3601-L3603' title='Snippet source file'>snippet source</a> | <a href='#snippet-WithObsoletePropIncludedGlobally' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3607-L3609' title='Snippet source file'>snippet source</a> | <a href='#snippet-WithObsoletePropIncludedGlobally' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -957,7 +957,7 @@ public Task IgnoreMemberByExpressionFluent()
_ => _.PropertyThatThrows);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3124-L3163' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMemberByExpression' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3130-L3169' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMemberByExpression' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally
Expand All @@ -972,7 +972,7 @@ VerifierSettings.IgnoreMembers<IgnoreExplicitTarget>(
_ => _.GetOnlyProperty,
_ => _.PropertyThatThrows);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3101-L3110' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMemberByExpressionGlobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3107-L3116' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMemberByExpressionGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -1032,7 +1032,7 @@ public Task ScrubMemberByExpressionFluent()
_ => _.PropertyThatThrows);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3165-L3204' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubMemberByExpression' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3171-L3210' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubMemberByExpression' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally
Expand All @@ -1047,7 +1047,7 @@ VerifierSettings.ScrubMembers<IgnoreExplicitTarget>(
_ => _.GetOnlyProperty,
_ => _.PropertyThatThrows);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3112-L3121' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubMemberByExpressionGlobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3118-L3127' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubMemberByExpressionGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -1126,7 +1126,7 @@ public Task IgnoreMemberByNameFluent()
.IgnoreMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3278-L3331' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMemberByName' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3284-L3337' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMemberByName' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand All @@ -1146,7 +1146,7 @@ VerifierSettings.IgnoreMember<IgnoreExplicitTarget>("Field");
// For a specific type with expression
VerifierSettings.IgnoreMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3245-L3259' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMemberByNameGlobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3251-L3265' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMemberByNameGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -1221,7 +1221,7 @@ public Task ScrubMemberByNameFluent()
.ScrubMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3333-L3386' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubMemberByName' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3339-L3392' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubMemberByName' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand All @@ -1241,7 +1241,7 @@ VerifierSettings.ScrubMember<IgnoreExplicitTarget>("Field");
// For a specific type with expression
VerifierSettings.ScrubMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3261-L3275' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubMemberByNameGlobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3267-L3281' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubMemberByNameGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -1292,7 +1292,7 @@ public Task CustomExceptionPropFluent()
.IgnoreMembersThatThrow<CustomException>();
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3490-L3509' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrow' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3496-L3515' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrow' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand All @@ -1302,7 +1302,7 @@ Or globally:
```cs
VerifierSettings.IgnoreMembersThatThrow<CustomException>();
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3486-L3488' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrowGlobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3492-L3494' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrowGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -1339,7 +1339,7 @@ public Task ExceptionMessagePropFluent()
.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore");
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2312-L2333' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrowExpression' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2318-L2339' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrowExpression' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand All @@ -1349,7 +1349,7 @@ Or globally:
```cs
VerifierSettings.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore");
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2307-L2309' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrowExpressionGlobal' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2313-L2315' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrowExpressionGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -1507,7 +1507,7 @@ public Task MemberConverterByExpression()
return Verify(input);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3206-L3234' title='Snippet source file'>snippet source</a> | <a href='#snippet-MemberConverter' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3212-L3240' title='Snippet source file'>snippet source</a> | <a href='#snippet-MemberConverter' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"path": "{ProjectDirectory}Foo",
"trimmed": "{ProjectDirectory}Foo",
"altPath": "{ProjectDirectory}Foo",
"altPathTrimmed": "{ProjectDirectory}Foo"
"altPath1": "{ProjectDirectory}Foo",
"altPath1Trimmed": "{ProjectDirectory}Foo",
"altPath2": "{ProjectDirectory}Foo",
"altPath2Trimmed": "{ProjectDirectory}Foo"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"path": "{SolutionDirectory}Foo",
"trimmed": "{SolutionDirectory}Foo",
"altPath": "{SolutionDirectory}Foo",
"altPathTrimmed": "{SolutionDirectory}Foo"
"altPath1": "{SolutionDirectory}Foo",
"altPath1Trimmed": "{SolutionDirectory}Foo",
"altPath2": "{SolutionDirectory}Foo",
"altPath2Trimmed": "{SolutionDirectory}Foo"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
path: {ProjectDirectory}Foo,
trimmed: {ProjectDirectory}Foo,
altPath: {ProjectDirectory}Foo,
altPathTrimmed: {ProjectDirectory}Foo
altPath1: {ProjectDirectory}Foo,
altPath1Trimmed: {ProjectDirectory}Foo,
altPath2: {ProjectDirectory}Foo,
altPath2Trimmed: {ProjectDirectory}Foo
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
path: {SolutionDirectory}Foo,
trimmed: {SolutionDirectory}Foo,
altPath: {SolutionDirectory}Foo,
altPathTrimmed: {SolutionDirectory}Foo
altPath1: {SolutionDirectory}Foo,
altPath1Trimmed: {SolutionDirectory}Foo,
altPath2: {SolutionDirectory}Foo,
altPath2Trimmed: {SolutionDirectory}Foo
}
18 changes: 12 additions & 6 deletions src/Verify.Tests/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2018,14 +2018,17 @@ public Task ScrubProjectDirectory()
{
var projectDirectory = AttributeReader.GetProjectDirectory();
var path = Path.GetFullPath(Path.Combine(projectDirectory, "Foo"));
var altPath = path.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
var altPath1 = path.Replace('/', '\\');
var altPath2 = path.Replace('\\', '/');
return Verify(
new
{
path,
trimmed = path.TrimEnd('/', '\\'),
altPath,
altPathTrimmed = altPath.TrimEnd('/', '\\')
altPath1,
altPath1Trimmed = altPath1.TrimEnd('/', '\\'),
altPath2,
altPath2Trimmed = altPath2.TrimEnd('/', '\\')
});
}

Expand All @@ -2034,14 +2037,17 @@ public Task ScrubSolutionDirectory()
{
var solutionDirectory = AttributeReader.GetSolutionDirectory();
var path = Path.GetFullPath(Path.Combine(solutionDirectory, "Foo"));
var altPath = path.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
var altPath1 = path.Replace('/', '\\');
var altPath2 = path.Replace('\\', '/');
return Verify(
new
{
path,
trimmed = path.TrimEnd('/', '\\'),
altPath,
altPathTrimmed = altPath.TrimEnd('/', '\\')
altPath1,
altPath1Trimmed = altPath1.TrimEnd('/', '\\'),
altPath2,
altPath2Trimmed = altPath2.TrimEnd('/', '\\')
});
}

Expand Down
16 changes: 16 additions & 0 deletions src/Verify/IoHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
static class IoHelpers
{
static IoHelpers()
{
DirectorySeparator = Path.DirectorySeparatorChar;
if (DirectorySeparator == '/')
{
AltDirectorySeparator = '\\';
}
else
{
AltDirectorySeparator = '/';
}
}

public static char DirectorySeparator { get; }
public static char AltDirectorySeparator { get; }

static readonly char[] Separators =
[
'\\',
Expand Down
Loading

0 comments on commit 53e462f

Please sign in to comment.