Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Sep 12, 2023
1 parent 71c36ff commit 371ea36
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 39 deletions.
4 changes: 2 additions & 2 deletions docs/verify-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Verifies the contents of a file.
public Task VerifyFilePath() =>
VerifyFile("sample.txt");
```
<sup><a href='/src/Verify.Tests/StreamTests.cs#L179-L185' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyfile' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/StreamTests.cs#L175-L181' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyfile' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -33,7 +33,7 @@ public Task VerifyFileWithInfo() =>
"sample.txt",
info: "the info");
```
<sup><a href='/src/Verify.Tests/StreamTests.cs#L198-L206' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyfilewithinfo' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/StreamTests.cs#L194-L202' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyfilewithinfo' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
2 changes: 1 addition & 1 deletion docs/verify-xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Verifies Xml:
public Task VerifyFilePath() =>
VerifyFile("sample.txt");
```
<sup><a href='/src/Verify.Tests/StreamTests.cs#L179-L185' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyfile' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/StreamTests.cs#L175-L181' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyfile' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
1 change: 1 addition & 0 deletions src/Shared.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PatternIsAlwaysTrueOrFalse/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantStringInterpolation/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RawStringCanBeSimplified/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantTypeDeclarationBody/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantUsingDirective_002EGlobal/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SeparateLocalFunctionsWithJumpStatement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralAsInterpolationArgument/@EntryIndexedValue">ERROR</s:String>
Expand Down
8 changes: 2 additions & 6 deletions src/Verify.Tests/StreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,9 @@ public Task StreamNotAtStartAsText()
[Fact]
public Task UnboundedStream()
{
var stream = new MemoryStream(new byte[]
{
1
});
var unboundedStream = new UnboundedStream(stream);
var stream = new UnboundedStream();

return ThrowsTask(() => Verify(unboundedStream))
return ThrowsTask(() => Verify(stream))
.DisableRequireUniquePrefix()
.IgnoreStackTrace();
}
Expand Down
27 changes: 2 additions & 25 deletions src/Verify.Tests/UnboundedStream.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
class UnboundedStream(Stream inner) : Stream
class UnboundedStream :
MemoryStream
{
public override void Flush() =>
inner.Flush();

public override long Seek(long offset, SeekOrigin origin) =>
throw new NotImplementedException();

public override void SetLength(long value) =>
throw new NotImplementedException();

public override int Read(byte[] buffer, int offset, int count) =>
inner.Read(buffer, offset, count);

public override void Write(byte[] buffer, int offset, int count) =>
throw new NotImplementedException();

public override bool CanRead => inner.CanRead;
public override bool CanSeek => false;
public override bool CanWrite => false;
public override long Length => throw new NotImplementedException();

public override long Position
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}
}
16 changes: 11 additions & 5 deletions src/Verify/Verifier/InnerVerifier_Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,22 @@ public async Task<VerifyResult> VerifyStream(Stream? stream, string extension, o

using (stream)
{
try
long GetLength()
{
if (stream.Length == 0)
try
{
throw new("Empty data is not allowed.");
return stream.Length;
}
catch (NotImplementedException)
{
throw new("Could not read Length property of target stream. Verify does not support unbounded streams.");
}
}
catch (NotImplementedException)

var length = GetLength();
if (length == 0)
{
throw new ArgumentException("Could not read Length property of target stream. Verify does not support unbounded streams.");
throw new("Empty data is not allowed.");
}

if (VerifierSettings.HasExtensionConverter(extension))
Expand Down

0 comments on commit 371ea36

Please sign in to comment.