Skip to content

Commit 53e462f

Browse files
authored
Fix alt dir separator issue on mac (#1292)
1 parent f9ccc29 commit 53e462f

8 files changed

+78
-50
lines changed

docs/serializer-settings.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public Task ScopedSerializerFluent()
347347
.AddExtraSettings(_ => _.TypeNameHandling = TypeNameHandling.All);
348348
}
349349
```
350-
<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>
350+
<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>
351351
<!-- endSnippet -->
352352

353353
Result:
@@ -475,7 +475,7 @@ public Task IgnoreTypeFluent()
475475
.IgnoreMembersWithType<ToIgnoreStruct>();
476476
}
477477
```
478-
<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>
478+
<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>
479479
<!-- endSnippet -->
480480

481481
Or globally:
@@ -485,7 +485,7 @@ Or globally:
485485
```cs
486486
VerifierSettings.IgnoreMembersWithType<ToIgnore>();
487487
```
488-
<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>
488+
<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>
489489
<!-- endSnippet -->
490490

491491
Result:
@@ -622,7 +622,7 @@ public Task ScrubTypeFluent()
622622
.ScrubMembersWithType<ToIgnoreStruct>();
623623
}
624624
```
625-
<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>
625+
<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>
626626
<!-- endSnippet -->
627627

628628
Or globally:
@@ -632,7 +632,7 @@ Or globally:
632632
```cs
633633
VerifierSettings.ScrubMembersWithType<ToIgnore>();
634634
```
635-
<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>
635+
<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>
636636
<!-- endSnippet -->
637637

638638
Result:
@@ -711,7 +711,7 @@ public Task AddIgnoreInstanceFluent()
711711
.IgnoreInstance<Instance>(_ => _.Property == "Ignore");
712712
}
713713
```
714-
<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>
714+
<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>
715715
<!-- endSnippet -->
716716

717717
Or globally:
@@ -721,7 +721,7 @@ Or globally:
721721
```cs
722722
VerifierSettings.IgnoreInstance<Instance>(_ => _.Property == "Ignore");
723723
```
724-
<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>
724+
<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>
725725
<!-- endSnippet -->
726726

727727
Result:
@@ -783,7 +783,7 @@ public Task AddScrubInstanceFluent()
783783
.ScrubInstance<Instance>(_ => _.Property == "Ignore");
784784
}
785785
```
786-
<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>
786+
<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>
787787
<!-- endSnippet -->
788788

789789
Or globally:
@@ -793,7 +793,7 @@ Or globally:
793793
```cs
794794
VerifierSettings.ScrubInstance<Instance>(_ => _.Property == "Ignore");
795795
```
796-
<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>
796+
<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>
797797
<!-- endSnippet -->
798798

799799
Result:
@@ -838,7 +838,7 @@ public Task WithObsoleteProp()
838838
return Verify(target);
839839
}
840840
```
841-
<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>
841+
<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>
842842
<!-- endSnippet -->
843843

844844
Result:
@@ -886,7 +886,7 @@ public Task WithObsoletePropIncludedFluent()
886886
.IncludeObsoletes();
887887
}
888888
```
889-
<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>
889+
<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>
890890
<!-- endSnippet -->
891891

892892
Or globally:
@@ -896,7 +896,7 @@ Or globally:
896896
```cs
897897
VerifierSettings.IncludeObsoletes();
898898
```
899-
<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>
899+
<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>
900900
<!-- endSnippet -->
901901

902902
Result:
@@ -957,7 +957,7 @@ public Task IgnoreMemberByExpressionFluent()
957957
_ => _.PropertyThatThrows);
958958
}
959959
```
960-
<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>
960+
<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>
961961
<!-- endSnippet -->
962962

963963
Or globally
@@ -972,7 +972,7 @@ VerifierSettings.IgnoreMembers<IgnoreExplicitTarget>(
972972
_ => _.GetOnlyProperty,
973973
_ => _.PropertyThatThrows);
974974
```
975-
<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>
975+
<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>
976976
<!-- endSnippet -->
977977

978978
Result:
@@ -1032,7 +1032,7 @@ public Task ScrubMemberByExpressionFluent()
10321032
_ => _.PropertyThatThrows);
10331033
}
10341034
```
1035-
<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>
1035+
<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>
10361036
<!-- endSnippet -->
10371037

10381038
Or globally
@@ -1047,7 +1047,7 @@ VerifierSettings.ScrubMembers<IgnoreExplicitTarget>(
10471047
_ => _.GetOnlyProperty,
10481048
_ => _.PropertyThatThrows);
10491049
```
1050-
<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>
1050+
<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>
10511051
<!-- endSnippet -->
10521052

10531053
Result:
@@ -1126,7 +1126,7 @@ public Task IgnoreMemberByNameFluent()
11261126
.IgnoreMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
11271127
}
11281128
```
1129-
<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>
1129+
<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>
11301130
<!-- endSnippet -->
11311131

11321132
Or globally:
@@ -1146,7 +1146,7 @@ VerifierSettings.IgnoreMember<IgnoreExplicitTarget>("Field");
11461146
// For a specific type with expression
11471147
VerifierSettings.IgnoreMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
11481148
```
1149-
<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>
1149+
<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>
11501150
<!-- endSnippet -->
11511151

11521152
Result:
@@ -1221,7 +1221,7 @@ public Task ScrubMemberByNameFluent()
12211221
.ScrubMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
12221222
}
12231223
```
1224-
<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>
1224+
<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>
12251225
<!-- endSnippet -->
12261226

12271227
Or globally:
@@ -1241,7 +1241,7 @@ VerifierSettings.ScrubMember<IgnoreExplicitTarget>("Field");
12411241
// For a specific type with expression
12421242
VerifierSettings.ScrubMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
12431243
```
1244-
<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>
1244+
<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>
12451245
<!-- endSnippet -->
12461246

12471247
Result:
@@ -1292,7 +1292,7 @@ public Task CustomExceptionPropFluent()
12921292
.IgnoreMembersThatThrow<CustomException>();
12931293
}
12941294
```
1295-
<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>
1295+
<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>
12961296
<!-- endSnippet -->
12971297

12981298
Or globally:
@@ -1302,7 +1302,7 @@ Or globally:
13021302
```cs
13031303
VerifierSettings.IgnoreMembersThatThrow<CustomException>();
13041304
```
1305-
<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>
1305+
<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>
13061306
<!-- endSnippet -->
13071307

13081308
Result:
@@ -1339,7 +1339,7 @@ public Task ExceptionMessagePropFluent()
13391339
.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore");
13401340
}
13411341
```
1342-
<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>
1342+
<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>
13431343
<!-- endSnippet -->
13441344

13451345
Or globally:
@@ -1349,7 +1349,7 @@ Or globally:
13491349
```cs
13501350
VerifierSettings.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore");
13511351
```
1352-
<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>
1352+
<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>
13531353
<!-- endSnippet -->
13541354

13551355
Result:
@@ -1507,7 +1507,7 @@ public Task MemberConverterByExpression()
15071507
return Verify(input);
15081508
}
15091509
```
1510-
<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>
1510+
<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>
15111511
<!-- endSnippet -->
15121512

15131513

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"path": "{ProjectDirectory}Foo",
33
"trimmed": "{ProjectDirectory}Foo",
4-
"altPath": "{ProjectDirectory}Foo",
5-
"altPathTrimmed": "{ProjectDirectory}Foo"
4+
"altPath1": "{ProjectDirectory}Foo",
5+
"altPath1Trimmed": "{ProjectDirectory}Foo",
6+
"altPath2": "{ProjectDirectory}Foo",
7+
"altPath2Trimmed": "{ProjectDirectory}Foo"
68
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"path": "{SolutionDirectory}Foo",
33
"trimmed": "{SolutionDirectory}Foo",
4-
"altPath": "{SolutionDirectory}Foo",
5-
"altPathTrimmed": "{SolutionDirectory}Foo"
4+
"altPath1": "{SolutionDirectory}Foo",
5+
"altPath1Trimmed": "{SolutionDirectory}Foo",
6+
"altPath2": "{SolutionDirectory}Foo",
7+
"altPath2Trimmed": "{SolutionDirectory}Foo"
68
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
path: {ProjectDirectory}Foo,
33
trimmed: {ProjectDirectory}Foo,
4-
altPath: {ProjectDirectory}Foo,
5-
altPathTrimmed: {ProjectDirectory}Foo
4+
altPath1: {ProjectDirectory}Foo,
5+
altPath1Trimmed: {ProjectDirectory}Foo,
6+
altPath2: {ProjectDirectory}Foo,
7+
altPath2Trimmed: {ProjectDirectory}Foo
68
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
path: {SolutionDirectory}Foo,
33
trimmed: {SolutionDirectory}Foo,
4-
altPath: {SolutionDirectory}Foo,
5-
altPathTrimmed: {SolutionDirectory}Foo
4+
altPath1: {SolutionDirectory}Foo,
5+
altPath1Trimmed: {SolutionDirectory}Foo,
6+
altPath2: {SolutionDirectory}Foo,
7+
altPath2Trimmed: {SolutionDirectory}Foo
68
}

src/Verify.Tests/Serialization/SerializationTests.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,14 +2018,17 @@ public Task ScrubProjectDirectory()
20182018
{
20192019
var projectDirectory = AttributeReader.GetProjectDirectory();
20202020
var path = Path.GetFullPath(Path.Combine(projectDirectory, "Foo"));
2021-
var altPath = path.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
2021+
var altPath1 = path.Replace('/', '\\');
2022+
var altPath2 = path.Replace('\\', '/');
20222023
return Verify(
20232024
new
20242025
{
20252026
path,
20262027
trimmed = path.TrimEnd('/', '\\'),
2027-
altPath,
2028-
altPathTrimmed = altPath.TrimEnd('/', '\\')
2028+
altPath1,
2029+
altPath1Trimmed = altPath1.TrimEnd('/', '\\'),
2030+
altPath2,
2031+
altPath2Trimmed = altPath2.TrimEnd('/', '\\')
20292032
});
20302033
}
20312034

@@ -2034,14 +2037,17 @@ public Task ScrubSolutionDirectory()
20342037
{
20352038
var solutionDirectory = AttributeReader.GetSolutionDirectory();
20362039
var path = Path.GetFullPath(Path.Combine(solutionDirectory, "Foo"));
2037-
var altPath = path.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
2040+
var altPath1 = path.Replace('/', '\\');
2041+
var altPath2 = path.Replace('\\', '/');
20382042
return Verify(
20392043
new
20402044
{
20412045
path,
20422046
trimmed = path.TrimEnd('/', '\\'),
2043-
altPath,
2044-
altPathTrimmed = altPath.TrimEnd('/', '\\')
2047+
altPath1,
2048+
altPath1Trimmed = altPath1.TrimEnd('/', '\\'),
2049+
altPath2,
2050+
altPath2Trimmed = altPath2.TrimEnd('/', '\\')
20452051
});
20462052
}
20472053

src/Verify/IoHelpers.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
static class IoHelpers
22
{
3+
static IoHelpers()
4+
{
5+
DirectorySeparator = Path.DirectorySeparatorChar;
6+
if (DirectorySeparator == '/')
7+
{
8+
AltDirectorySeparator = '\\';
9+
}
10+
else
11+
{
12+
AltDirectorySeparator = '/';
13+
}
14+
}
15+
16+
public static char DirectorySeparator { get; }
17+
public static char AltDirectorySeparator { get; }
18+
319
static readonly char[] Separators =
420
[
521
'\\',

0 commit comments

Comments
 (0)